2 This file is part of GNUnet
3 (C) 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file include/gnunet_arm_service.h
23 * @brief API to access gnunet-arm
24 * @author Christian Grothoff
27 #ifndef GNUNET_ARM_SERVICE_H
28 #define GNUNET_ARM_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_configuration_lib.h"
39 #include "gnunet_scheduler_lib.h"
40 #include "gnunet_os_lib.h"
41 #include "gnunet_time_lib.h"
44 * Version of the arm API.
46 #define GNUNET_ARM_VERSION 0x00000002
50 * Statuses of the requests that client can send to ARM.
52 enum GNUNET_ARM_RequestStatus
55 * Message was sent successfully.
57 GNUNET_ARM_REQUEST_SENT_OK = 0,
60 * Misconfiguration (can't connect to the ARM service).
62 GNUNET_ARM_REQUEST_CONFIGURATION_ERROR = 1,
65 * We disconnected from ARM, and request was not sent.
67 GNUNET_ARM_REQUEST_DISCONNECTED = 2,
70 * ARM API is busy (probably trying to connect to ARM),
71 * and request was not sent. Try again later.
73 GNUNET_ARM_REQUEST_BUSY = 3,
76 * It was discovered that the request would be too long to fit in a message,
77 * and thus it was not sent.
79 GNUNET_ARM_REQUEST_TOO_LONG = 4,
82 * Request time ran out before we had a chance to send it.
84 GNUNET_ARM_REQUEST_TIMEOUT = 5
90 * Statuses of services.
92 enum GNUNET_ARM_ServiceStatus
97 GNUNET_ARM_SERVICE_MONITORING_STARTED = 0,
100 * Service was stopped.
102 GNUNET_ARM_SERVICE_STOPPED = 1,
105 * Service starting was initiated
107 GNUNET_ARM_SERVICE_STARTING = 2,
110 * Service stopping was initiated
112 GNUNET_ARM_SERVICE_STOPPING = 3
116 * Replies to ARM requests
118 enum GNUNET_ARM_Result
121 * Service was stopped (never sent for ARM itself).
123 GNUNET_ARM_RESULT_STOPPED = 0,
126 * ARM stopping was initiated (there's no "stopped" for ARM itself).
128 GNUNET_ARM_RESULT_STOPPING = 1,
131 * Service starting was initiated
133 GNUNET_ARM_RESULT_STARTING = 2,
136 * Asked to start it, but it's already starting.
138 GNUNET_ARM_RESULT_IS_STARTING_ALREADY = 3,
141 * Asked to stop it, but it's already stopping.
143 GNUNET_ARM_RESULT_IS_STOPPING_ALREADY = 4,
146 * Asked to start it, but it's already started.
148 GNUNET_ARM_RESULT_IS_STARTED_ALREADY = 5,
151 * Asked to stop it, but it's already stopped.
153 GNUNET_ARM_RESULT_IS_STOPPED_ALREADY = 6,
156 * Asked to start or stop a service, but it's not known.
158 GNUNET_ARM_RESULT_IS_NOT_KNOWN = 7,
161 * Tried to start a service, but that failed for some reason.
163 GNUNET_ARM_RESULT_START_FAILED = 8,
166 * Asked to start something, but ARM is shutting down and can't comply.
168 GNUNET_ARM_RESULT_IN_SHUTDOWN = 9
173 * Handle for interacting with ARM.
175 struct GNUNET_ARM_Handle;
179 * Function called whenever we connect to or disconnect from ARM.
182 * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected
183 * @param error GNUNET_YES if we encountered a permanent error, and there
184 * will be no re-connection.
186 typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls, struct GNUNET_ARM_Handle *arm, unsigned char connected, unsigned char error);
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.
196 * @param arm handle to the arm connection
197 * @param rs status of the request
198 * @param service service name
199 * @param result result of the operation
201 typedef void (*GNUNET_ARM_ResultCallback) (void *cls, struct GNUNET_ARM_Handle *arm, enum GNUNET_ARM_RequestStatus rs, const char *service, enum GNUNET_ARM_Result result);
205 * Callback function invoked when list operation is complete.
206 * Will be called when request was not sent successfully,
207 * or when a reply comes. If the request was not sent successfully,
208 * 'rs' will indicate that, and 'count' and 'list' will be undefined.
211 * @param arm handle to the arm connection
212 * @param rs status of the request
213 * @param count number of strings in the list
214 * @param list list of running services
216 typedef void (*GNUNET_ARM_ServiceListCallback) (void *cls, struct GNUNET_ARM_Handle *arm, enum GNUNET_ARM_RequestStatus rs, unsigned int count, const char *const*list);
220 * Setup a context for communicating with ARM. Note that this
221 * can be done even if the ARM service is not yet running.
224 * @param cfg configuration to use (needed to contact ARM;
225 * the ARM service may internally use a different
226 * configuration to determine how to start the service).
227 * @return context to use for further ARM operations
229 struct GNUNET_ARM_Handle *
230 GNUNET_ARM_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg);
233 * Start connecting to the ARM service using the context.
234 * @param conn_status called when we (dis)connect from/to ARM.
235 * It's also called on connection errors.
236 * @param cls closure for conn_status
238 * @param h ARM handle
241 GNUNET_ARM_connect (struct GNUNET_ARM_Handle *h,
242 GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls);
246 * Disconnect from the ARM service and destroy the handle.
247 * Don't call this from inside an ARM callback!
249 * @param h the handle that was being used
252 GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h);
256 * Request a list of running services.
258 * @param h handle to ARM
259 * @param timeout how long to wait before failing for good
260 * @param cont callback to invoke after request is sent or is not sent
261 * @param cont_cls closure for callback
264 GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
265 struct GNUNET_TIME_Relative timeout,
266 GNUNET_ARM_ServiceListCallback cont, void *cont_cls);
270 * Request a service to be stopped.
271 * Stopping arm itself will not invalidate its handle, and
272 * ARM API will try to restore connection to the ARM service,
273 * even if ARM connection was lost because you asked for ARM to be stopped.
274 * Call GNUNET_ARM_disconnect_and_free () to free the handle and prevent
275 * further connection attempts.
277 * @param h handle to ARM
278 * @param service_name name of the service
279 * @param timeout how long to wait before failing for good
280 * @param cont callback to invoke after request is sent or is not sent
281 * @param cont_cls closure for callback
284 GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
285 const char *service_name, struct GNUNET_TIME_Relative timeout,
286 GNUNET_ARM_ResultCallback cont, void *cont_cls);
290 * Request for a service to be started.
292 * @param h handle to ARM
293 * @param service_name name of the service
294 * @param std_inheritance inheritance of std streams
295 * @param timeout how long to wait before failing for good
296 * @param cont callback to invoke after request is sent or not sent
297 * @param cont_cls closure for callback
300 GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
301 const char *service_name, enum GNUNET_OS_InheritStdioFlags std_inheritance,
302 struct GNUNET_TIME_Relative timeout, GNUNET_ARM_ResultCallback cont,
307 * Handle for monitoring ARM.
309 struct GNUNET_ARM_MonitorHandle;
313 * Function called in when a status update arrives.
316 * @param arm handle to the arm connection
317 * @param service service name
318 * @param status status of the service
320 typedef void (*GNUNET_ARM_ServiceStatusCallback) (void *cls, struct GNUNET_ARM_MonitorHandle *arm, const char *service, enum GNUNET_ARM_ServiceStatus status);
324 * Setup a context for monitoring ARM. Note that this
325 * can be done even if the ARM service is not yet running.
328 * @param cfg configuration to use (needed to contact ARM;
329 * the ARM service may internally use a different
330 * configuration to determine how to start the service).
331 * @return context to use for further ARM monitor operations
333 struct GNUNET_ARM_MonitorHandle *
334 GNUNET_ARM_monitor_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg);
337 * Start connecting to the ARM service for monitoring using the context.
339 * @param h ARM monitor handle
340 * @param cont callback to invoke on status updates
341 * @param cont_cls closure
344 GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h,
345 GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls);
349 * Disconnect from the ARM service and destroy the handle.
350 * Don't call this from inside an ARM callback!
352 * @param h the handle that was being used
355 GNUNET_ARM_monitor_disconnect (struct GNUNET_ARM_MonitorHandle *h);
358 #if 0 /* keep Emacsens' auto-indent happy */