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 Affero 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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Christian Grothoff
23 * API to access gnunet-arm
25 * @defgroup arm ARM service
26 * Automatic Restart Manager
28 * @see [Documentation](https://gnunet.org/arm)
33 #ifndef GNUNET_ARM_SERVICE_H
34 #define GNUNET_ARM_SERVICE_H
39 #if 0 /* keep Emacsens' auto-indent happy */
44 #include "gnunet_util_lib.h"
47 * Version of the arm API.
49 #define GNUNET_ARM_VERSION 0x00000003
53 * Statuses of the requests that client can send to ARM.
55 enum GNUNET_ARM_RequestStatus
58 * Message was sent successfully.
60 GNUNET_ARM_REQUEST_SENT_OK = 0,
63 * We disconnected from ARM, and request was not sent.
65 GNUNET_ARM_REQUEST_DISCONNECTED = 2
71 * Statuses of services.
73 enum GNUNET_ARM_ServiceStatus
78 GNUNET_ARM_SERVICE_MONITORING_STARTED = 0,
81 * Service was stopped.
83 GNUNET_ARM_SERVICE_STOPPED = 1,
86 * Service starting was initiated
88 GNUNET_ARM_SERVICE_STARTING = 2,
91 * Service stopping was initiated
93 GNUNET_ARM_SERVICE_STOPPING = 3
98 * Replies to ARM requests
100 enum GNUNET_ARM_Result
103 * Service was stopped (never sent for ARM itself).
105 GNUNET_ARM_RESULT_STOPPED = 0,
108 * ARM stopping was initiated (there's no "stopped" for ARM itself).
110 GNUNET_ARM_RESULT_STOPPING = 1,
113 * Service starting was initiated
115 GNUNET_ARM_RESULT_STARTING = 2,
118 * Asked to start it, but it's already starting.
120 GNUNET_ARM_RESULT_IS_STARTING_ALREADY = 3,
123 * Asked to stop it, but it's already stopping.
125 GNUNET_ARM_RESULT_IS_STOPPING_ALREADY = 4,
128 * Asked to start it, but it's already started.
130 GNUNET_ARM_RESULT_IS_STARTED_ALREADY = 5,
133 * Asked to stop it, but it's already stopped.
135 GNUNET_ARM_RESULT_IS_STOPPED_ALREADY = 6,
138 * Asked to start or stop a service, but it's not known.
140 GNUNET_ARM_RESULT_IS_NOT_KNOWN = 7,
143 * Tried to start a service, but that failed for some reason.
145 GNUNET_ARM_RESULT_START_FAILED = 8,
148 * Asked to start something, but ARM is shutting down and can't comply.
150 GNUNET_ARM_RESULT_IN_SHUTDOWN = 9
155 * Handle for interacting with ARM.
157 struct GNUNET_ARM_Handle;
160 * Handle for an ARM operation.
162 struct GNUNET_ARM_Operation;
166 * Function called whenever we connect to or disconnect from ARM.
169 * @param connected #GNUNET_YES if connected, #GNUNET_NO if disconnected,
170 * #GNUNET_SYSERR if there was an error.
173 (*GNUNET_ARM_ConnectionStatusCallback) (void *cls,
178 * Function called in response to a start/stop request.
179 * Will be called when request was not sent successfully,
180 * or when a reply comes. If the request was not sent successfully,
181 * @a rs will indicate that, and @a result will be undefined.
184 * @param rs status of the request
185 * @param result result of the operation
188 (*GNUNET_ARM_ResultCallback) (void *cls,
189 enum GNUNET_ARM_RequestStatus rs,
190 enum GNUNET_ARM_Result result);
194 * Callback function invoked when list operation is complete.
195 * Will be called when request was not sent successfully,
196 * or when a reply comes. If the request was not sent successfully,
197 * @a rs will indicate that, and @a count and @a list will be undefined.
200 * @param rs status of the request
201 * @param count number of strings in the list
202 * @param list list of running services
205 (*GNUNET_ARM_ServiceListCallback) (void *cls,
206 enum GNUNET_ARM_RequestStatus rs,
208 const char *const*list);
212 * Set up a context for communicating with ARM, then
213 * start connecting to the ARM service using that context.
215 * @param cfg configuration to use (needed to contact ARM;
216 * the ARM service may internally use a different
217 * configuration to determine how to start the service).
218 * @param conn_status will be called when connecting/disconnecting
219 * @param conn_status_cls closure for @a conn_status
220 * @return context to use for further ARM operations, NULL on error.
222 struct GNUNET_ARM_Handle *
223 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
224 GNUNET_ARM_ConnectionStatusCallback conn_status,
225 void *conn_status_cls);
229 * Disconnect from the ARM service and destroy the handle.
231 * @param h the handle that was being used
234 GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h);
238 * Abort an operation. Only prevents the callback from being
239 * called, the operation may still complete.
241 * @param op operation to cancel
244 GNUNET_ARM_operation_cancel (struct GNUNET_ARM_Operation *op);
248 * Request a list of running services.
250 * @param h handle to ARM
251 * @param cont callback to invoke after request is sent or is not sent
252 * @param cont_cls closure for @a cont
253 * @return handle for the operation, NULL on error
255 struct GNUNET_ARM_Operation *
256 GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
257 GNUNET_ARM_ServiceListCallback cont,
262 * Request a service to be stopped.
263 * Stopping arm itself will not invalidate its handle, and
264 * ARM API will try to restore connection to the ARM service,
265 * even if ARM connection was lost because you asked for ARM to be stopped.
266 * Call #GNUNET_ARM_disconnect() to free the handle and prevent
267 * further connection attempts.
269 * @param h handle to ARM
270 * @param service_name name of the service
271 * @param cont callback to invoke after request is sent or is not sent
272 * @param cont_cls closure for @a cont
273 * @return handle for the operation, NULL on error
275 struct GNUNET_ARM_Operation *
276 GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
277 const char *service_name,
278 GNUNET_ARM_ResultCallback cont,
283 * Request for a service to be started.
285 * @param h handle to ARM
286 * @param service_name name of the service
287 * @param std_inheritance inheritance of std streams
288 * @param cont callback to invoke after request is sent or not sent
289 * @param cont_cls closure for @a cont
290 * @return handle for the operation, NULL on error
292 struct GNUNET_ARM_Operation *
293 GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
294 const char *service_name,
295 enum GNUNET_OS_InheritStdioFlags std_inheritance,
296 GNUNET_ARM_ResultCallback cont,
301 * Handle for monitoring ARM.
303 struct GNUNET_ARM_MonitorHandle;
307 * Function called in when a status update arrives.
310 * @param service service name
311 * @param status status of the service
314 (*GNUNET_ARM_ServiceStatusCallback) (void *cls,
316 enum GNUNET_ARM_ServiceStatus status);
320 * Setup a context for monitoring ARM, then
321 * start connecting to the ARM service for monitoring using that context.
323 * @param cfg configuration to use (needed to contact ARM;
324 * the ARM service may internally use a different
325 * configuration to determine how to start the service).
326 * @param cont callback to invoke on status updates
327 * @param cont_cls closure for @a cont
328 * @return context to use for further ARM monitor operations, NULL on error.
330 struct GNUNET_ARM_MonitorHandle *
331 GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
332 GNUNET_ARM_ServiceStatusCallback cont,
337 * Disconnect from the ARM service and destroy the handle.
339 * @param h the handle that was being used
342 GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h);
344 #if 0 /* keep Emacsens' auto-indent happy */
353 /** @} */ /* end of group */