- distribute peers equally among island nodes on SuperMUC
[oweals/gnunet.git] / src / include / gnunet_arm_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2009 Christian Grothoff (and other contributing authors)
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_arm_service.h
23  * @brief API to access gnunet-arm
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_ARM_SERVICE_H
28 #define GNUNET_ARM_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_configuration_lib.h"
39 #include "gnunet_scheduler_lib.h"
40 #include "gnunet_os_lib.h"
41 #include "gnunet_time_lib.h"
42
43 /**
44  * Version of the arm API.
45  */
46 #define GNUNET_ARM_VERSION 0x00000002
47
48
49 /**
50  * Statuses of the requests that client can send to ARM.
51  */
52 enum GNUNET_ARM_RequestStatus
53 {
54   /**
55    * Message was sent successfully.
56    */
57   GNUNET_ARM_REQUEST_SENT_OK = 0,
58
59   /**
60    * Misconfiguration (can't connect to the ARM service).
61    */
62   GNUNET_ARM_REQUEST_CONFIGURATION_ERROR = 1,
63
64   /**
65    * We disconnected from ARM, and request was not sent.
66    */
67   GNUNET_ARM_REQUEST_DISCONNECTED = 2,
68
69   /**
70    * ARM API is busy (probably trying to connect to ARM),
71    * and request was not sent. Try again later.
72    */
73   GNUNET_ARM_REQUEST_BUSY = 3,
74
75   /**
76    * It was discovered that the request would be too long to fit in a message,
77    * and thus it was not sent.
78    */
79   GNUNET_ARM_REQUEST_TOO_LONG = 4,
80
81   /**
82    * Request time ran out before we had a chance to send it.
83    */
84   GNUNET_ARM_REQUEST_TIMEOUT = 5
85
86 };
87
88
89 /**
90  * Statuses of services.
91  */
92 enum GNUNET_ARM_ServiceStatus
93 {
94   /**
95    * Dummy message.
96    */
97   GNUNET_ARM_SERVICE_MONITORING_STARTED = 0,
98
99   /**
100    * Service was stopped.
101    */
102   GNUNET_ARM_SERVICE_STOPPED = 1,
103
104   /**
105    * Service starting was initiated
106    */
107   GNUNET_ARM_SERVICE_STARTING = 2,
108
109   /**
110    * Service stopping was initiated
111    */
112   GNUNET_ARM_SERVICE_STOPPING = 3
113 };
114
115 /**
116  * Replies to ARM requests
117  */
118 enum GNUNET_ARM_Result
119 {
120   /**
121    * Service was stopped (never sent for ARM itself).
122    */
123   GNUNET_ARM_RESULT_STOPPED = 0,
124
125   /**
126    * ARM stopping was initiated (there's no "stopped" for ARM itself).
127    */
128   GNUNET_ARM_RESULT_STOPPING = 1,
129
130   /**
131    * Service starting was initiated
132    */
133   GNUNET_ARM_RESULT_STARTING = 2,
134
135   /**
136    * Asked to start it, but it's already starting.
137    */
138   GNUNET_ARM_RESULT_IS_STARTING_ALREADY = 3,
139
140   /**
141    * Asked to stop it, but it's already stopping.
142    */
143   GNUNET_ARM_RESULT_IS_STOPPING_ALREADY = 4,
144
145   /**
146    * Asked to start it, but it's already started.
147    */
148   GNUNET_ARM_RESULT_IS_STARTED_ALREADY = 5,
149
150   /**
151    * Asked to stop it, but it's already stopped.
152    */
153   GNUNET_ARM_RESULT_IS_STOPPED_ALREADY = 6,
154
155   /**
156    * Asked to start or stop a service, but it's not known.
157    */
158   GNUNET_ARM_RESULT_IS_NOT_KNOWN = 7,
159
160   /**
161    * Tried to start a service, but that failed for some reason.
162    */
163   GNUNET_ARM_RESULT_START_FAILED = 8,
164
165   /**
166    * Asked to start something, but ARM is shutting down and can't comply.
167    */
168   GNUNET_ARM_RESULT_IN_SHUTDOWN = 9
169 };
170
171
172 /**
173  * Handle for interacting with ARM.
174  */
175 struct GNUNET_ARM_Handle;
176
177
178 /**
179  * Function called whenever we connect to or disconnect from ARM.
180  *
181  * @param cls closure
182  * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
183  *                  GNUNET_SYSERR if there was an error.
184  */
185 typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls, 
186                                                      int connected);
187
188
189 /**
190  * Function called in response to a start/stop request.
191  * Will be called when request was not sent successfully,
192  * or when a reply comes. If the request was not sent successfully,
193  * 'rs' will indicate that, and 'service' and 'result' will be undefined.
194  *
195  * @param cls closure
196  * @param rs status of the request
197  * @param service service name
198  * @param result result of the operation
199  */
200 typedef void (*GNUNET_ARM_ResultCallback) (void *cls, 
201                                            enum GNUNET_ARM_RequestStatus rs, 
202                                            const char *service, 
203                                            enum GNUNET_ARM_Result result);
204
205
206 /**
207  * Callback function invoked when list operation is complete.
208  * Will be called when request was not sent successfully,
209  * or when a reply comes. If the request was not sent successfully,
210  * 'rs' will indicate that, and 'count' and 'list' will be undefined.
211  *
212  * @param cls closure
213  * @param rs status of the request
214  * @param count number of strings in the list
215  * @param list list of running services
216  */
217 typedef void (*GNUNET_ARM_ServiceListCallback) (void *cls, 
218                                                 enum GNUNET_ARM_RequestStatus rs, 
219                                                 unsigned int count, 
220                                                 const char *const*list);
221
222
223 /**
224  * Set up a context for communicating with ARM, then
225  * start connecting to the ARM service using that context.
226  *
227  * @param cfg configuration to use (needed to contact ARM;
228  *        the ARM service may internally use a different
229  *        configuration to determine how to start the service).
230  * @param conn_status will be called when connecting/disconnecting
231  * @param cls closure for conn_status
232  * @return context to use for further ARM operations, NULL on error.
233  */
234 struct GNUNET_ARM_Handle *
235 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
236                     GNUNET_ARM_ConnectionStatusCallback conn_status, 
237                     void *cls);
238
239
240 /**
241  * Disconnect from the ARM service and destroy the handle.
242  *
243  * @param h the handle that was being used
244  */
245 void
246 GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h);
247
248
249 /**
250  * Request a list of running services.
251  *
252  * @param h handle to ARM
253  * @param timeout how long to wait before failing for good
254  * @param cont callback to invoke after request is sent or is not sent
255  * @param cont_cls closure for callback
256  */
257 void
258 GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
259                                  struct GNUNET_TIME_Relative timeout,
260                                  GNUNET_ARM_ServiceListCallback cont, void *cont_cls);
261
262
263 /**
264  * Request a service to be stopped.
265  * Stopping arm itself will not invalidate its handle, and
266  * ARM API will try to restore connection to the ARM service,
267  * even if ARM connection was lost because you asked for ARM to be stopped.
268  * Call GNUNET_ARM_disconnect_and_free () to free the handle and prevent
269  * further connection attempts.
270  *
271  * @param h handle to ARM
272  * @param service_name name of the service
273  * @param timeout how long to wait before failing for good
274  * @param cont callback to invoke after request is sent or is not sent
275  * @param cont_cls closure for callback
276  */
277 void
278 GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
279                                  const char *service_name, 
280                                  struct GNUNET_TIME_Relative timeout,
281                                  GNUNET_ARM_ResultCallback cont, void *cont_cls);
282
283
284 /**
285  * Request for a service to be started.
286  *
287  * @param h handle to ARM
288  * @param service_name name of the service
289  * @param std_inheritance inheritance of std streams
290  * @param timeout how long to wait before failing for good
291  * @param cont callback to invoke after request is sent or not sent
292  * @param cont_cls closure for callback
293  */
294 void
295 GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
296     const char *service_name, enum GNUNET_OS_InheritStdioFlags std_inheritance,
297     struct GNUNET_TIME_Relative timeout, GNUNET_ARM_ResultCallback cont,
298     void *cont_cls);
299
300
301 /**
302  * Handle for monitoring ARM.
303  */
304 struct GNUNET_ARM_MonitorHandle;
305
306
307 /**
308  * Function called in when a status update arrives.
309  *
310  * @param cls closure
311  * @param arm handle to the arm connection
312  * @param service service name
313  * @param status status of the service
314  */
315 typedef void (*GNUNET_ARM_ServiceStatusCallback) (void *cls, 
316                                                   const char *service, 
317                                                   enum GNUNET_ARM_ServiceStatus status);
318
319
320 /**
321  * Setup a context for monitoring ARM, then
322  * start connecting to the ARM service for monitoring using that context.
323  *
324  * @param cfg configuration to use (needed to contact ARM;
325  *        the ARM service may internally use a different
326  *        configuration to determine how to start the service).
327  * @param cont callback to invoke on status updates
328  * @param cont_cls closure
329  * @return context to use for further ARM monitor operations, NULL on error.
330  */
331 struct GNUNET_ARM_MonitorHandle *
332 GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
333                     GNUNET_ARM_ServiceStatusCallback cont, 
334                     void *cont_cls);
335
336
337 /**
338  * Disconnect from the ARM service and destroy the handle.
339  *
340  * @param h the handle that was being used
341  */
342 void
343 GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *h);
344
345
346 #if 0                           /* keep Emacsens' auto-indent happy */
347 {
348 #endif
349 #ifdef __cplusplus
350 }
351 #endif
352
353 #endif