-fixes
[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 0x00000001
47
48
49 /**
50  * Values characterizing GNUnet process states.
51  */
52 enum GNUNET_ARM_ProcessStatus
53 {
54   /**
55    * Service name is unknown to ARM.
56    */
57   GNUNET_ARM_PROCESS_UNKNOWN = -1,
58
59   /**
60    * Service is now down (due to client request).
61    */
62   GNUNET_ARM_PROCESS_DOWN = 0,
63
64   /**
65    * Service is already running.
66    */
67   GNUNET_ARM_PROCESS_ALREADY_RUNNING = 1,
68
69   /**
70    * Service is currently being started (due to client request).
71    */
72   GNUNET_ARM_PROCESS_STARTING = 2,
73   
74   /**
75    * Service is already being stopped by some other client.
76    */
77   GNUNET_ARM_PROCESS_ALREADY_STOPPING = 3,
78
79   /**
80    * Service is already down (no action taken)
81    */
82   GNUNET_ARM_PROCESS_ALREADY_DOWN = 4,
83
84   /**
85    * ARM is currently being shut down (no more process starts)
86    */
87   GNUNET_ARM_PROCESS_SHUTDOWN = 5,
88
89   /**
90    * Error in communication with ARM
91    */
92   GNUNET_ARM_PROCESS_COMMUNICATION_ERROR = 6,
93
94   /**
95    * Timeout in communication with ARM
96    */
97   GNUNET_ARM_PROCESS_COMMUNICATION_TIMEOUT = 7,
98
99   /**
100    * Failure to perform operation
101    */
102   GNUNET_ARM_PROCESS_FAILURE = 8
103 };
104
105
106 /**
107  * Callback function invoked when operation is complete.
108  *
109  * @param cls closure
110  * @param result outcome of the operation
111  */
112 typedef void (*GNUNET_ARM_Callback) (void *cls, 
113                                      enum GNUNET_ARM_ProcessStatus result);
114
115 /**
116  * Callback function invoked when list operation is complete.
117  *
118  * @param cls closure
119  * @param result outcome of the operation (GNUNET_YES if successful)
120  * @param count number of strings in the list
121  * @param list list of running services
122  */
123 typedef void (*GNUNET_ARM_List_Callback) (void *cls, 
124                                           int result,
125                                           unsigned int count,
126                                           const char *const *list);
127
128
129 /**
130  * Handle for interacting with ARM.
131  */
132 struct GNUNET_ARM_Handle;
133
134
135 /**
136  * Setup a context for communicating with ARM.  Note that this
137  * can be done even if the ARM service is not yet running.
138  *
139  * @param cfg configuration to use (needed to contact ARM;
140  *        the ARM service may internally use a different
141  *        configuration to determine how to start the service).
142  * @param service service that *this* process is implementing/providing, can be NULL
143  * @return context to use for further ARM operations, NULL on error
144  */
145 struct GNUNET_ARM_Handle *
146 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
147                     const char *service);
148
149
150 /**
151  * Disconnect from the ARM service.
152  *
153  * @param h the handle that was being used
154  */
155 void
156 GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h);
157
158
159 /**
160  * Start a service.  Note that this function merely asks ARM to start
161  * the service and that ARM merely confirms that it forked the
162  * respective process.  The specified callback may thus return before
163  * the service has started to listen on the server socket and it may
164  * also be that the service has crashed in the meantime.  Clients
165  * should repeatedly try to connect to the service at the respective
166  * port (with some delays in between) before assuming that the service
167  * actually failed to start.  Note that if an error is returned to the
168  * callback, clients obviously should not bother with trying to
169  * contact the service.
170  *
171  * @param h handle to ARM
172  * @param service_name name of the service
173  * @param std_inheritance flags controlling std descriptors inheritance
174  * @param timeout how long to wait before failing for good
175  * @param cb callback to invoke when service is ready
176  * @param cb_cls closure for callback
177  */
178 void
179 GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, const char *service_name,
180                           enum GNUNET_OS_InheritStdioFlags std_inheritance,
181                           struct GNUNET_TIME_Relative timeout,
182                           GNUNET_ARM_Callback cb, void *cb_cls);
183
184
185 /**
186  * Stop a service.  Note that the callback is invoked as soon
187  * as ARM confirms that it will ask the service to terminate.
188  * The actual termination may still take some time.
189  *
190  * @param h handle to ARM
191  * @param service_name name of the service
192  * @param timeout how long to wait before failing for good
193  * @param cb callback to invoke when service is ready
194  * @param cb_cls closure for callback
195  */
196 void
197 GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, const char *service_name,
198                          struct GNUNET_TIME_Relative timeout,
199                          GNUNET_ARM_Callback cb, void *cb_cls);
200
201
202 /**
203  * List all running services.
204  * 
205  * @param h handle to ARM
206  * @param timeout how long to wait before failing for good
207  * @param cb callback to invoke when service is ready
208  * @param cb_cls closure for callback
209  */
210 void
211 GNUNET_ARM_list_running_services (struct GNUNET_ARM_Handle *h,
212                                   struct GNUNET_TIME_Relative timeout,
213                                   GNUNET_ARM_List_Callback cb, void *cb_cls);
214
215 #if 0                           /* keep Emacsens' auto-indent happy */
216 {
217 #endif
218 #ifdef __cplusplus
219 }
220 #endif
221
222 #endif