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