2 This file is part of GNUnet
3 Copyright (C) 2009, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @author Christian Grothoff
20 * API to access gnunet-arm
22 * @defgroup arm ARM service
23 * Automatic Restart Manager
25 * @see [Documentation](https://gnunet.org/arm)
30 #ifndef GNUNET_ARM_SERVICE_H
31 #define GNUNET_ARM_SERVICE_H
36 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
44 * Version of the arm API.
46 #define GNUNET_ARM_VERSION 0x00000003
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 * We disconnected from ARM, and request was not sent.
62 GNUNET_ARM_REQUEST_DISCONNECTED = 2
68 * Statuses of services.
70 enum GNUNET_ARM_ServiceStatus
75 GNUNET_ARM_SERVICE_MONITORING_STARTED = 0,
78 * Service was stopped.
80 GNUNET_ARM_SERVICE_STOPPED = 1,
83 * Service starting was initiated
85 GNUNET_ARM_SERVICE_STARTING = 2,
88 * Service stopping was initiated
90 GNUNET_ARM_SERVICE_STOPPING = 3
95 * Replies to ARM requests
97 enum GNUNET_ARM_Result
100 * Service was stopped (never sent for ARM itself).
102 GNUNET_ARM_RESULT_STOPPED = 0,
105 * ARM stopping was initiated (there's no "stopped" for ARM itself).
107 GNUNET_ARM_RESULT_STOPPING = 1,
110 * Service starting was initiated
112 GNUNET_ARM_RESULT_STARTING = 2,
115 * Asked to start it, but it's already starting.
117 GNUNET_ARM_RESULT_IS_STARTING_ALREADY = 3,
120 * Asked to stop it, but it's already stopping.
122 GNUNET_ARM_RESULT_IS_STOPPING_ALREADY = 4,
125 * Asked to start it, but it's already started.
127 GNUNET_ARM_RESULT_IS_STARTED_ALREADY = 5,
130 * Asked to stop it, but it's already stopped.
132 GNUNET_ARM_RESULT_IS_STOPPED_ALREADY = 6,
135 * Asked to start or stop a service, but it's not known.
137 GNUNET_ARM_RESULT_IS_NOT_KNOWN = 7,
140 * Tried to start a service, but that failed for some reason.
142 GNUNET_ARM_RESULT_START_FAILED = 8,
145 * Asked to start something, but ARM is shutting down and can't comply.
147 GNUNET_ARM_RESULT_IN_SHUTDOWN = 9
152 * Handle for interacting with ARM.
154 struct GNUNET_ARM_Handle;
157 * Handle for an ARM operation.
159 struct GNUNET_ARM_Operation;
163 * Function called whenever we connect to or disconnect from ARM.
166 * @param connected #GNUNET_YES if connected, #GNUNET_NO if disconnected,
167 * #GNUNET_SYSERR if there was an error.
170 (*GNUNET_ARM_ConnectionStatusCallback) (void *cls,
175 * Function called in response to a start/stop request.
176 * Will be called when request was not sent successfully,
177 * or when a reply comes. If the request was not sent successfully,
178 * @a rs will indicate that, and @a result will be undefined.
181 * @param rs status of the request
182 * @param result result of the operation
185 (*GNUNET_ARM_ResultCallback) (void *cls,
186 enum GNUNET_ARM_RequestStatus rs,
187 enum GNUNET_ARM_Result result);
191 * Callback function invoked when list operation is complete.
192 * Will be called when request was not sent successfully,
193 * or when a reply comes. If the request was not sent successfully,
194 * @a rs will indicate that, and @a count and @a list will be undefined.
197 * @param rs status of the request
198 * @param count number of strings in the list
199 * @param list list of running services
202 (*GNUNET_ARM_ServiceListCallback) (void *cls,
203 enum GNUNET_ARM_RequestStatus rs,
205 const char *const*list);
209 * Set up a context for communicating with ARM, then
210 * start connecting to the ARM service using that context.
212 * @param cfg configuration to use (needed to contact ARM;
213 * the ARM service may internally use a different
214 * configuration to determine how to start the service).
215 * @param conn_status will be called when connecting/disconnecting
216 * @param conn_status_cls closure for @a conn_status
217 * @return context to use for further ARM operations, NULL on error.
219 struct GNUNET_ARM_Handle *
220 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
221 GNUNET_ARM_ConnectionStatusCallback conn_status,
222 void *conn_status_cls);
226 * Disconnect from the ARM service and destroy the handle.
228 * @param h the handle that was being used
231 GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h);
235 * Abort an operation. Only prevents the callback from being
236 * called, the operation may still complete.
238 * @param op operation to cancel
241 GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op);
245 * Request a list of running services.
247 * @param h handle to ARM
248 * @param cont callback to invoke after request is sent or is not sent
249 * @param cont_cls closure for @a cont
250 * @return handle for the operation, NULL on error
252 struct GNUNET_ARM_Operation *
253 GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
254 GNUNET_ARM_ServiceListCallback cont,
259 * Request a service to be stopped.
260 * Stopping arm itself will not invalidate its handle, and
261 * ARM API will try to restore connection to the ARM service,
262 * even if ARM connection was lost because you asked for ARM to be stopped.
263 * Call #GNUNET_ARM_disconnect() to free the handle and prevent
264 * further connection attempts.
266 * @param h handle to ARM
267 * @param service_name name of the service
268 * @param cont callback to invoke after request is sent or is not sent
269 * @param cont_cls closure for @a cont
270 * @return handle for the operation, NULL on error
272 struct GNUNET_ARM_Operation *
273 GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
274 const char *service_name,
275 GNUNET_ARM_ResultCallback cont,
280 * Request for a service to be started.
282 * @param h handle to ARM
283 * @param service_name name of the service
284 * @param std_inheritance inheritance of std streams
285 * @param cont callback to invoke after request is sent or not sent
286 * @param cont_cls closure for @a cont
287 * @return handle for the operation, NULL on error
289 struct GNUNET_ARM_Operation *
290 GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
291 const char *service_name,
292 enum GNUNET_OS_InheritStdioFlags std_inheritance,
293 GNUNET_ARM_ResultCallback cont,
298 * Handle for monitoring ARM.
300 struct GNUNET_ARM_MonitorHandle;
304 * Function called in when a status update arrives.
307 * @param service service name
308 * @param status status of the service
311 (*GNUNET_ARM_ServiceStatusCallback) (void *cls,
313 enum GNUNET_ARM_ServiceStatus status);
317 * Setup a context for monitoring ARM, then
318 * start connecting to the ARM service for monitoring using that context.
320 * @param cfg configuration to use (needed to contact ARM;
321 * the ARM service may internally use a different
322 * configuration to determine how to start the service).
323 * @param cont callback to invoke on status updates
324 * @param cont_cls closure for @a cont
325 * @return context to use for further ARM monitor operations, NULL on error.
327 struct GNUNET_ARM_MonitorHandle *
328 GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
329 GNUNET_ARM_ServiceStatusCallback cont,
334 * Disconnect from the ARM service and destroy the handle.
336 * @param h the handle that was being used
339 GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h);
341 #if 0 /* keep Emacsens' auto-indent happy */
350 /** @} */ /* end of group */