diff options
author | LRN <lrn1986@gmail.com> | 2013-03-20 18:50:18 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-03-20 18:50:18 +0000 |
commit | 346748a3a55e197fe206e87b0520cef85ab9fda3 (patch) | |
tree | 37bc351cba1af84ee12e8d5dcd6d596f0456da3f /src/arm/arm_monitor_api.c | |
parent | 41646c7ce6e3d1711beb4b95da08afbd5b79d097 (diff) | |
download | gnunet-346748a3a55e197fe206e87b0520cef85ab9fda3.tar.gz gnunet-346748a3a55e197fe206e87b0520cef85ab9fda3.zip |
Simplify ARM alloc/connect
Diffstat (limited to 'src/arm/arm_monitor_api.c')
-rw-r--r-- | src/arm/arm_monitor_api.c | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index dc690b904..fa9e0faab 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c | |||
@@ -88,7 +88,7 @@ struct GNUNET_ARM_MonitorHandle | |||
88 | static void | 88 | static void |
89 | monitor_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg); | 89 | monitor_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg); |
90 | 90 | ||
91 | static void | 91 | static int |
92 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); | 92 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); |
93 | 93 | ||
94 | /** | 94 | /** |
@@ -211,7 +211,7 @@ transmit_monitoring_init_message (void *cls, size_t size, void *buf) | |||
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | static void | 214 | static int |
215 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | 215 | reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) |
216 | { | 216 | { |
217 | GNUNET_assert (NULL == h->monitor); | 217 | GNUNET_assert (NULL == h->monitor); |
@@ -220,56 +220,49 @@ reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) | |||
220 | { | 220 | { |
221 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 221 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
222 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); | 222 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); |
223 | GNUNET_CLIENT_disconnect (h->monitor); | 223 | if (NULL != h->service_status) |
224 | h->monitor = NULL; | 224 | h->service_status (h->cls, h, NULL, GNUNET_ARM_SERVICE_STOPPED); |
225 | return; | 225 | return GNUNET_SYSERR; |
226 | } | 226 | } |
227 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 227 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
228 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); | 228 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); |
229 | h->cth = GNUNET_CLIENT_notify_transmit_ready (h->monitor, | 229 | h->cth = GNUNET_CLIENT_notify_transmit_ready (h->monitor, |
230 | sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, | 230 | sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, |
231 | GNUNET_NO, &transmit_monitoring_init_message, h); | 231 | GNUNET_NO, &transmit_monitoring_init_message, h); |
232 | return GNUNET_OK; | ||
232 | } | 233 | } |
233 | 234 | ||
234 | 235 | ||
235 | /** | 236 | /** |
236 | * Setup a context for monitoring ARM. Note that this | 237 | * Setup a context for monitoring ARM, then |
237 | * can be done even if the ARM service is not yet running. | 238 | * start connecting to the ARM service for monitoring using that context. |
238 | * Never fails. | ||
239 | * | 239 | * |
240 | * @param cfg configuration to use (needed to contact ARM; | 240 | * @param cfg configuration to use (needed to contact ARM; |
241 | * the ARM service may internally use a different | 241 | * the ARM service may internally use a different |
242 | * configuration to determine how to start the service). | 242 | * configuration to determine how to start the service). |
243 | * @return context to use for further ARM monitoring operations | ||
244 | */ | ||
245 | struct GNUNET_ARM_MonitorHandle * | ||
246 | GNUNET_ARM_monitor_alloc (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
247 | { | ||
248 | struct GNUNET_ARM_MonitorHandle *ret; | ||
249 | |||
250 | ret = GNUNET_malloc (sizeof (struct GNUNET_ARM_MonitorHandle)); | ||
251 | ret->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
252 | ret->currently_down = GNUNET_YES; | ||
253 | ret->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
254 | ret->init_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
255 | return ret; | ||
256 | } | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Start connecting to the ARM service for monitoring using the context. | ||
261 | * | ||
262 | * @param h ARM monitor handle | ||
263 | * @param cont callback to invoke on status updates | 243 | * @param cont callback to invoke on status updates |
264 | * @param cont_cls closure | 244 | * @param cont_cls closure |
245 | * @return context to use for further ARM monitor operations, NULL on error. | ||
265 | */ | 246 | */ |
266 | void | 247 | struct GNUNET_ARM_MonitorHandle * |
267 | GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h, | 248 | GNUNET_ARM_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, |
268 | GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls) | 249 | GNUNET_ARM_ServiceStatusCallback cont, void *cont_cls) |
269 | { | 250 | { |
251 | struct GNUNET_ARM_MonitorHandle *h; | ||
252 | |||
253 | h = GNUNET_malloc (sizeof (struct GNUNET_ARM_MonitorHandle)); | ||
254 | h->cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
255 | h->currently_down = GNUNET_YES; | ||
256 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
257 | h->init_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
270 | h->service_status = cont; | 258 | h->service_status = cont; |
271 | h->cls = cont_cls; | 259 | h->cls = cont_cls; |
272 | reconnect_arm_monitor (h); | 260 | if (GNUNET_OK != reconnect_arm_monitor (h)) |
261 | { | ||
262 | GNUNET_free (h); | ||
263 | return NULL; | ||
264 | } | ||
265 | return h; | ||
273 | } | 266 | } |
274 | 267 | ||
275 | 268 | ||
@@ -280,7 +273,7 @@ GNUNET_ARM_monitor (struct GNUNET_ARM_MonitorHandle *h, | |||
280 | * @param h the handle that was being used | 273 | * @param h the handle that was being used |
281 | */ | 274 | */ |
282 | void | 275 | void |
283 | GNUNET_ARM_monitor_disconnect (struct GNUNET_ARM_MonitorHandle *handle) | 276 | GNUNET_ARM_monitor_disconnect_and_free (struct GNUNET_ARM_MonitorHandle *handle) |
284 | { | 277 | { |
285 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); | 278 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n"); |
286 | if (NULL != handle->cth) | 279 | if (NULL != handle->cth) |