gnunet_arm_service.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2009 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Christian Grothoff
  19. *
  20. * @file
  21. * API to access gnunet-arm
  22. *
  23. * @defgroup arm ARM service
  24. * Automatic Restart Manager
  25. * @{
  26. */
  27. #ifndef GNUNET_ARM_SERVICE_H
  28. #define GNUNET_ARM_SERVICE_H
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #if 0 /* keep Emacsens' auto-indent happy */
  33. }
  34. #endif
  35. #endif
  36. #include "gnunet_util_lib.h"
  37. /**
  38. * Version of the arm API.
  39. */
  40. #define GNUNET_ARM_VERSION 0x00000002
  41. /**
  42. * Statuses of the requests that client can send to ARM.
  43. */
  44. enum GNUNET_ARM_RequestStatus
  45. {
  46. /**
  47. * Message was sent successfully.
  48. */
  49. GNUNET_ARM_REQUEST_SENT_OK = 0,
  50. /**
  51. * Misconfiguration (can't connect to the ARM service).
  52. */
  53. GNUNET_ARM_REQUEST_CONFIGURATION_ERROR = 1,
  54. /**
  55. * We disconnected from ARM, and request was not sent.
  56. */
  57. GNUNET_ARM_REQUEST_DISCONNECTED = 2,
  58. /**
  59. * ARM API is busy (probably trying to connect to ARM),
  60. * and request was not sent. Try again later.
  61. */
  62. GNUNET_ARM_REQUEST_BUSY = 3,
  63. /**
  64. * It was discovered that the request would be too long to fit in a message,
  65. * and thus it was not sent.
  66. */
  67. GNUNET_ARM_REQUEST_TOO_LONG = 4,
  68. /**
  69. * Request time ran out before we had a chance to send it.
  70. */
  71. GNUNET_ARM_REQUEST_TIMEOUT = 5
  72. };
  73. /**
  74. * Statuses of services.
  75. */
  76. enum GNUNET_ARM_ServiceStatus
  77. {
  78. /**
  79. * Dummy message.
  80. */
  81. GNUNET_ARM_SERVICE_MONITORING_STARTED = 0,
  82. /**
  83. * Service was stopped.
  84. */
  85. GNUNET_ARM_SERVICE_STOPPED = 1,
  86. /**
  87. * Service starting was initiated
  88. */
  89. GNUNET_ARM_SERVICE_STARTING = 2,
  90. /**
  91. * Service stopping was initiated
  92. */
  93. GNUNET_ARM_SERVICE_STOPPING = 3
  94. };
  95. /**
  96. * Replies to ARM requests
  97. */
  98. enum GNUNET_ARM_Result
  99. {
  100. /**
  101. * Service was stopped (never sent for ARM itself).
  102. */
  103. GNUNET_ARM_RESULT_STOPPED = 0,
  104. /**
  105. * ARM stopping was initiated (there's no "stopped" for ARM itself).
  106. */
  107. GNUNET_ARM_RESULT_STOPPING = 1,
  108. /**
  109. * Service starting was initiated
  110. */
  111. GNUNET_ARM_RESULT_STARTING = 2,
  112. /**
  113. * Asked to start it, but it's already starting.
  114. */
  115. GNUNET_ARM_RESULT_IS_STARTING_ALREADY = 3,
  116. /**
  117. * Asked to stop it, but it's already stopping.
  118. */
  119. GNUNET_ARM_RESULT_IS_STOPPING_ALREADY = 4,
  120. /**
  121. * Asked to start it, but it's already started.
  122. */
  123. GNUNET_ARM_RESULT_IS_STARTED_ALREADY = 5,
  124. /**
  125. * Asked to stop it, but it's already stopped.
  126. */
  127. GNUNET_ARM_RESULT_IS_STOPPED_ALREADY = 6,
  128. /**
  129. * Asked to start or stop a service, but it's not known.
  130. */
  131. GNUNET_ARM_RESULT_IS_NOT_KNOWN = 7,
  132. /**
  133. * Tried to start a service, but that failed for some reason.
  134. */
  135. GNUNET_ARM_RESULT_START_FAILED = 8,
  136. /**
  137. * Asked to start something, but ARM is shutting down and can't comply.
  138. */
  139. GNUNET_ARM_RESULT_IN_SHUTDOWN = 9
  140. };
  141. /**
  142. * Handle for interacting with ARM.
  143. */
  144. struct GNUNET_ARM_Handle;
  145. /**
  146. * Function called whenever we connect to or disconnect from ARM.
  147. *
  148. * @param cls closure
  149. * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
  150. * GNUNET_SYSERR if there was an error.
  151. */
  152. typedef void (*GNUNET_ARM_ConnectionStatusCallback) (void *cls,
  153. int connected);
  154. /**
  155. * Function called in response to a start/stop request.
  156. * Will be called when request was not sent successfully,
  157. * or when a reply comes. If the request was not sent successfully,
  158. * 'rs' will indicate that, and 'service' and 'result' will be undefined.
  159. *
  160. * @param cls closure
  161. * @param rs status of the request
  162. * @param service service name
  163. * @param result result of the operation
  164. */
  165. typedef void (*GNUNET_ARM_ResultCallback) (void *cls,
  166. enum GNUNET_ARM_RequestStatus rs,
  167. const char *service,
  168. enum GNUNET_ARM_Result result);
  169. /**
  170. * Callback function invoked when list operation is complete.
  171. * Will be called when request was not sent successfully,
  172. * or when a reply comes. If the request was not sent successfully,
  173. * 'rs' will indicate that, and 'count' and 'list' will be undefined.
  174. *
  175. * @param cls closure
  176. * @param rs status of the request
  177. * @param count number of strings in the list
  178. * @param list list of running services
  179. */
  180. typedef void (*GNUNET_ARM_ServiceListCallback) (void *cls,
  181. enum GNUNET_ARM_RequestStatus rs,
  182. unsigned int count,
  183. const char *const*list);
  184. /**
  185. * Set up a context for communicating with ARM, then
  186. * start connecting to the ARM service using that context.
  187. *
  188. * @param cfg configuration to use (needed to contact ARM;
  189. * the ARM service may internally use a different
  190. * configuration to determine how to start the service).
  191. * @param conn_status will be called when connecting/disconnecting
  192. * @param cls closure for conn_status
  193. * @return context to use for further ARM operations, NULL on error.
  194. */
  195. struct GNUNET_ARM_Handle *
  196. GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  197. GNUNET_ARM_ConnectionStatusCallback conn_status,
  198. void *cls);
  199. /**
  200. * Disconnect from the ARM service and destroy the handle.
  201. *
  202. * @param h the handle that was being used
  203. */
  204. void
  205. GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h);
  206. /**
  207. * Request a list of running services.
  208. *
  209. * @param h handle to ARM
  210. * @param timeout how long to wait before failing for good
  211. * @param cont callback to invoke after request is sent or is not sent
  212. * @param cont_cls closure for callback
  213. */
  214. void
  215. GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
  216. struct GNUNET_TIME_Relative timeout,
  217. GNUNET_ARM_ServiceListCallback cont, void *cont_cls);
  218. /**
  219. * Request a service to be stopped.
  220. * Stopping arm itself will not invalidate its handle, and
  221. * ARM API will try to restore connection to the ARM service,
  222. * even if ARM connection was lost because you asked for ARM to be stopped.
  223. * Call GNUNET_ARM_disconnect_and_free () to free the handle and prevent
  224. * further connection attempts.
  225. *
  226. * @param h handle to ARM
  227. * @param service_name name of the service
  228. * @param timeout how long to wait before failing for good
  229. * @param cont callback to invoke after request is sent or is not sent
  230. * @param cont_cls closure for callback
  231. */
  232. void
  233. GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
  234. const char *service_name,
  235. struct GNUNET_TIME_Relative timeout,
  236. GNUNET_ARM_ResultCallback cont, void *cont_cls);
  237. /**
  238. * Request for a service to be started.
  239. *
  240. * @param h handle to ARM
  241. * @param service_name name of the service
  242. * @param std_inheritance inheritance of std streams
  243. * @param timeout how long to wait before failing for good
  244. * @param cont callback to invoke after request is sent or not sent
  245. * @param cont_cls closure for callback
  246. */
  247. void
  248. GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
  249. const char *service_name,
  250. enum GNUNET_OS_InheritStdioFlags std_inheritance,
  251. struct GNUNET_TIME_Relative timeout,
  252. GNUNET_ARM_ResultCallback cont,
  253. void *cont_cls);
  254. /**
  255. * Handle for monitoring ARM.
  256. */
  257. struct GNUNET_ARM_MonitorHandle;
  258. /**
  259. * Function called in when a status update arrives.
  260. *
  261. * @param cls closure
  262. * @param arm handle to the arm connection
  263. * @param service service name
  264. * @param status status of the service
  265. */
  266. typedef void (*GNUNET_ARM_ServiceStatusCallback) (void *cls,
  267. const char *service,
  268. enum GNUNET_ARM_ServiceStatus status);
  269. /**
  270. * Setup a context for monitoring ARM, then
  271. * start connecting to the ARM service for monitoring using that context.
  272. *
  273. * @param cfg configuration to use (needed to contact ARM;
  274. * the ARM service may internally use a different
  275. * configuration to determine how to start the service).
  276. * @param cont callback to invoke on status updates
  277. * @param cont_cls closure
  278. * @return context to use for further ARM monitor operations, NULL on error.
  279. */
  280. struct GNUNET_ARM_MonitorHandle *
  281. GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
  282. GNUNET_ARM_ServiceStatusCallback cont,
  283. void *cont_cls);
  284. /**
  285. * Disconnect from the ARM service and destroy the handle.
  286. *
  287. * @param h the handle that was being used
  288. */
  289. void
  290. GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *h);
  291. #if 0 /* keep Emacsens' auto-indent happy */
  292. {
  293. #endif
  294. #ifdef __cplusplus
  295. }
  296. #endif
  297. #endif
  298. /** @} */ /* end of group */