N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/Vaike/linux/system-addons/system/soap/sensor++.h

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 #ifndef _SENSORPP_H_
00036 #define _SENSORPP_H_
00037 
00038 
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include <strings.h>
00042 #include <stdlib.h>
00043 #include <stdarg.h>
00044 #include <limits.h>
00045 #include <minisoap.h>
00046 #include <sensor.h>
00047 
00048 
00049 #define MAX_APPS  1024
00050 #define MAX_DATA  1024
00051 
00052 extern int ipc_data_port, ipc_cmd_port;
00053 extern const char *my_app;
00054 
00055 static int registered[MAX_APPS];
00056 static int count = 0;
00057 
00058 
00059 template <class T>
00060 int consume(const char *appname, <T> data[], unsigned int size)
00061 {
00062         int i;
00063         SoapEvent evt;
00064         char *msg, *app = NULL, *addr = NULL;
00065         char format[20] = "";
00066 
00067         if (appname == NULL || data == NULL || bytes == NULL)
00068                 return -EINVAL;
00069 
00070         sscanf(appname, "%s : %s", app, addr);
00071 
00072         if (!registered[count]) {
00073                 SoapEvent req;
00074                 sprintf(req.msg, "register %s", appname);
00075                 // FIXME: fill in remainder of event
00076                 ipc_cmd_send(&req);
00077                 registered[count]++;  // FIXME: app_t list?
00078         }
00079         ipc_data_recv(&evt);
00080         msg = evt.msg;
00081 
00082         if (data[0].typeid != evt.data_type)
00083                 return -EINVAL;  // FIXME: more appropriate errno?
00084 
00085         for (i = 0; i < size; i ++) {
00086                 // FIXME: de-serialize msg into data[i]
00087         }
00088         return 0;
00089 }
00090 
00091 
00092 template <class T>
00093 int produce(<T> data[], unsigned int size)
00094 {
00095         int i;
00096         SoapEvent evt;
00097         int msg_size = sizeof(EVENT_DATA_LEN) - 1;
00098 
00099         if (data == NULL)
00100                 return;
00101 
00102         memset(evt.msg, '\0', EVENT_DATA_LEN);
00103         memset(evt.to, '\0', NET_ADDR_LEN);
00104         memset(evt.to_app, '\0', PATH_MAX);
00105         evt.data_type = type;
00106         strncpy(evt.from_app, my_app, PATH_MAX);
00107         gettimeofday(&evt.time, NULL);
00108         evt.type = Event_Msg;
00109         strncpy(evt.from, my_ip_addr, NET_ADDR_LEN);
00110         strncpy(evt.data_type, data[0]->typeid.name(), MAX_TYPE_NAME);
00111 
00112         for (i = 0; i < size; i ++) {
00113                 char tmp[msg_size];
00114                 if (i)
00115                         strncat(evt.msg, ",", msg_size--);
00116                 // FIXME: serialize into tmp
00117                 strncat(evt.msg, tmp, msg_size);
00118                 msg_size = EVENT_DATA_LEN - strlen(evt.msg) - 1;
00119         }
00120         return ipc_data_send(&evt);
00121 }
00122 
00123 
00124 #endif  // _SENSORPP_H_


© 2007, Los Alamos National Security, LLC.