2 This file is part of GNUnet
3 Copyright (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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @author Christian Grothoff
25 * API to access gnunet-arm
27 * @defgroup arm ARM service
28 * Automatic Restart Manager
32 #ifndef GNUNET_ARM_SERVICE_H
33 #define GNUNET_ARM_SERVICE_H
38 #if 0 /* keep Emacsens' auto-indent happy */
43 #include "gnunet_util_lib.h"
46 * Version of the arm API.
48 #define GNUNET_ARM_VERSION 0x00000002
52 * Statuses of the requests that client can send to ARM.
54 enum GNUNET_ARM_RequestStatus
57 * Message was sent successfully.
59 GNUNET_ARM_REQUEST_SENT_OK = 0,
62 * Misconfiguration (can't connect to the ARM service).
64 GNUNET_ARM_REQUEST_CONFIGURATION_ERROR = 1,
67 * We disconnected from ARM, and request was not sent.
69 GNUNET_ARM_REQUEST_DISCONNECTED = 2,
72 * ARM API is busy (probably trying to connect to ARM),
73 * and request was not sent. Try again later.
75 GNUNET_ARM_REQUEST_BUSY = 3,
78 * It was discovered that the request would be too long to fit in a message,
79 * and thus it was not sent.
81 GNUNET_ARM_REQUEST_TOO_LONG = 4,
84 * Request time ran out before we had a chance to send it.
86 GNUNET_ARM_REQUEST_TIMEOUT = 5
92 * Statuses of services.
94 enum GNUNET_ARM_ServiceStatus
99 GNUNET_ARM_SERVICE_MONITORING_STARTED = 0,
102 * Service was stopped.
104 GNUNET_ARM_SERVICE_STOPPED = 1,
107 * Service starting was initiated
109 GNUNET_ARM_SERVICE_STARTING = 2,
112 * Service stopping was initiated
114 GNUNET_ARM_SERVICE_STOPPING = 3
119 * Replies to ARM requests
121 enum GNUNET_ARM_Result
124 * Service was stopped (never sent for ARM itself).
126 GNUNET_ARM_RESULT_STOPPED = 0,
129 * ARM stopping was initiated (there's no "stopped" for ARM itself).
131 GNUNET_ARM_RESULT_STOPPING = 1,
134 * Service starting was initiated
136 GNUNET_ARM_RESULT_STARTING = 2,
139 * Asked to start it, but it's already starting.
141 GNUNET_ARM_RESULT_IS_STARTING_ALREADY = 3,
144 * Asked to stop it, but it's already stopping.
146 GNUNET_ARM_RESULT_IS_STOPPING_ALREADY = 4,
149 * Asked to start it, but it's already started.
151 GNUNET_ARM_RESULT_IS_STARTED_ALREADY = 5,
154 * Asked to stop it, but it's already stopped.
156 GNUNET_ARM_RESULT_IS_STOPPED_ALREADY = 6,
159 * Asked to start or stop a service, but it's not known.
161 GNUNET_ARM_RESULT_IS_NOT_KNOWN = 7,
164 * Tried to start a service, but that failed for some reason.
166 GNUNET_ARM_RESULT_START_FAILED = 8,
169 * Asked to start something, but ARM is shutting down and can't comply.
171 GNUNET_ARM_RESULT_IN_SHUTDOWN = 9
176 * Handle for interacting with ARM.
178 struct GNUNET_ARM_Handle;
182 * Function called whenever we connect to or disconnect from ARM.
185 * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
186 * GNUNET_SYSERR if there was an error.
188 typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls,
193 * Function called in response to a start/stop request.
194 * Will be called when request was not sent successfully,
195 * or when a reply comes. If the request was not sent successfully,
196 * 'rs' will indicate that, and 'service' and 'result' will be undefined.
199 * @param rs status of the request
200 * @param service service name
201 * @param result result of the operation
203 typedef void (*GNUNET_ARM_ResultCallback) (void *cls,
204 enum GNUNET_ARM_RequestStatus rs,
206 enum GNUNET_ARM_Result result);
210 * Callback function invoked when list operation is complete.
211 * Will be called when request was not sent successfully,
212 * or when a reply comes. If the request was not sent successfully,
213 * 'rs' will indicate that, and 'count' and 'list' will be undefined.
216 * @param rs status of the request
217 * @param count number of strings in the list
218 * @param list list of running services
220 typedef void (*GNUNET_ARM_ServiceListCallback) (void *cls,
221 enum GNUNET_ARM_RequestStatus rs,
223 const char *const*list);
227 * Set up a context for communicating with ARM, then
228 * start connecting to the ARM service using that context.
230 * @param cfg configuration to use (needed to contact ARM;
231 * the ARM service may internally use a different
232 * configuration to determine how to start the service).
233 * @param conn_status will be called when connecting/disconnecting
234 * @param cls closure for conn_status
235 * @return context to use for further ARM operations, NULL on error.
237 struct GNUNET_ARM_Handle *
238 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
239 GNUNET_ARM_ConnectionStatusCallback conn_status,
244 * Disconnect from the ARM service and destroy the handle.
246 * @param h the handle that was being used
249 GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h);
253 * Request a list of running services.
255 * @param h handle to ARM
256 * @param timeout how long to wait before failing for good
257 * @param cont callback to invoke after request is sent or is not sent
258 * @param cont_cls closure for callback
261 GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
262 struct GNUNET_TIME_Relative timeout,
263 GNUNET_ARM_ServiceListCallback cont, void *cont_cls);
267 * Request a service to be stopped.
268 * Stopping arm itself will not invalidate its handle, and
269 * ARM API will try to restore connection to the ARM service,
270 * even if ARM connection was lost because you asked for ARM to be stopped.
271 * Call GNUNET_ARM_disconnect_and_free () to free the handle and prevent
272 * further connection attempts.
274 * @param h handle to ARM
275 * @param service_name name of the service
276 * @param timeout how long to wait before failing for good
277 * @param cont callback to invoke after request is sent or is not sent
278 * @param cont_cls closure for callback
281 GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
282 const char *service_name,
283 struct GNUNET_TIME_Relative timeout,
284 GNUNET_ARM_ResultCallback cont, void *cont_cls);
288 * Request for a service to be started.
290 * @param h handle to ARM
291 * @param service_name name of the service
292 * @param std_inheritance inheritance of std streams
293 * @param timeout how long to wait before failing for good
294 * @param cont callback to invoke after request is sent or not sent
295 * @param cont_cls closure for callback
298 GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
299 const char *service_name,
300 enum GNUNET_OS_InheritStdioFlags std_inheritance,
301 struct GNUNET_TIME_Relative timeout,
302 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,
322 enum GNUNET_ARM_ServiceStatus status);
326 * Setup a context for monitoring ARM, then
327 * start connecting to the ARM service for monitoring using that context.
329 * @param cfg configuration to use (needed to contact ARM;
330 * the ARM service may internally use a different
331 * configuration to determine how to start the service).
332 * @param cont callback to invoke on status updates
333 * @param cont_cls closure
334 * @return context to use for further ARM monitor operations, NULL on error.
336 struct GNUNET_ARM_MonitorHandle *
337 GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
338 GNUNET_ARM_ServiceStatusCallback cont,
343 * Disconnect from the ARM service and destroy the handle.
345 * @param h the handle that was being used
348 GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *h);
350 #if 0 /* keep Emacsens' auto-indent happy */
359 /** @} */ /* end of group */