moved common sensor functionality to a util lib
[oweals/gnunet.git] / src / include / gnunet_sensor_service.h
1 /*
2       This file is part of GNUnet
3       (C) 
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file include/gnunet_sensor_service.h
23  * @brief API to the sensor service
24  * @author Omar Tarabai
25  */
26 #ifndef GNUNET_SENSOR_SERVICE_H
27 #define GNUNET_SENSOR_SERVICE_H
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /**
42  * Handle to the sensor service.
43  */
44 struct GNUNET_SENSOR_Handle;
45
46 /**
47  * Structure containing brief info about sensor
48  */
49 struct SensorInfoShort
50 {
51
52   /*
53    * Sensor name
54    */
55   char *name;
56
57   /*
58    * First part of version number
59    */
60   uint16_t version_major;
61
62   /*
63    * Second part of version number
64    */
65   uint16_t version_minor;
66
67   /*
68    * Sensor description
69    */
70   char *description;
71
72 };
73
74 GNUNET_NETWORK_STRUCT_BEGIN
75
76 /**
77  * Used to communicate sensor readings to
78  * collection points (SENSORDASHBAORD service)
79  */
80 struct GNUNET_SENSOR_Reading
81 {
82
83   /**
84    * GNUNET general message header
85    */
86   struct GNUNET_MessageHeader *header;
87
88   /**
89    * Size of the sensor name value, allocated
90    * at position 0 after this struct
91    */
92   size_t sensorname_size;
93
94   /**
95    * First part of sensor version number
96    */
97   uint16_t sensorversion_major;
98
99   /**
100    * Second part of sensor version number
101    */
102   uint16_t sensorversion_minor;
103
104   /**
105    * Timestamp of recorded reading
106    */
107   uint64_t timestamp;
108
109   /**
110    * Size of reading value, allocation
111    * at poistion 1 after this struct
112    */
113   size_t value_size;
114
115 };
116 GNUNET_NETWORK_STRUCT_END
117
118 /**
119  * Type of an iterator over sensor definitions.
120  *
121  * @param cls closure
122  * @param hello hello message for the peer (can be NULL)
123  * @param error message
124  */
125 typedef void (*GNUNET_SENSOR_SensorIteratorCB) (void *cls,
126                                              const struct SensorInfoShort *sensor,
127                                              const char *err_msg);
128
129 /**
130  * Continuation called with a status result.
131  *
132  * @param cls closure
133  * @param emsg error message, NULL on success
134  */
135 typedef void (*GNUNET_SENSOR_Continuation)(void *cls,
136                const char *emsg);
137
138 /**
139  * Connect to the sensor service.
140  *
141  * @return NULL on error
142  */
143 struct GNUNET_SENSOR_Handle *
144 GNUNET_SENSOR_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
145
146 /**
147  * Disconnect from the sensor service
148  *
149  * @param h handle to disconnect
150  */
151 void
152 GNUNET_SENSOR_disconnect(struct GNUNET_SENSOR_Handle *h);
153
154 /**
155  * Client asking to iterate all available sensors
156  *
157  * @param h Handle to SENSOR service
158  * @param timeout how long to wait until timing out
159  * @param sensorname information on one sensor only, can be NULL to get all
160  * @param sensorname_len length of the sensorname parameter
161  * @param callback the method to call for each sensor
162  * @param callback_cls closure for callback
163  * @return iterator context
164  */
165 struct GNUNET_SENSOR_SensorIteratorContext *
166 GNUNET_SENSOR_iterate_sensors (struct GNUNET_SENSOR_Handle *h,
167     struct GNUNET_TIME_Relative timeout,
168     const char* sensorname, size_t sensorname_len,
169     GNUNET_SENSOR_SensorIteratorCB callback, void *callback_cls);
170
171 #if 0                           /* keep Emacsens' auto-indent happy */
172 {
173 #endif
174 #ifdef __cplusplus
175 }
176 #endif
177
178 #endif