diff options
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index 767d91cb9..09e9cacb5 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -293,6 +293,13 @@ struct RunContext | |||
293 | 293 | ||
294 | }; | 294 | }; |
295 | 295 | ||
296 | |||
297 | /** | ||
298 | * Return a 32-bit key from a pointer | ||
299 | * | ||
300 | * @param rcop the pointer | ||
301 | * @return 32-bit key | ||
302 | */ | ||
296 | static uint32_t | 303 | static uint32_t |
297 | rcop_key (void *rcop) | 304 | rcop_key (void *rcop) |
298 | { | 305 | { |
@@ -300,13 +307,31 @@ rcop_key (void *rcop) | |||
300 | } | 307 | } |
301 | 308 | ||
302 | 309 | ||
310 | /** | ||
311 | * Context information used for finding a pointer in the rcop_map | ||
312 | */ | ||
303 | struct SearchContext | 313 | struct SearchContext |
304 | { | 314 | { |
315 | /** | ||
316 | * The operation pointer to look for | ||
317 | */ | ||
305 | struct GNUNET_TESTBED_Operation *query; | 318 | struct GNUNET_TESTBED_Operation *query; |
306 | 319 | ||
320 | /** | ||
321 | * The Run context operation which has the operation being queried | ||
322 | */ | ||
307 | struct RunContextOperation *result; | 323 | struct RunContextOperation *result; |
308 | }; | 324 | }; |
309 | 325 | ||
326 | |||
327 | /** | ||
328 | * Iterator for searching over the elements matching a given query | ||
329 | * | ||
330 | * @param cls the SearchContext | ||
331 | * @param key the 32-bit key | ||
332 | * @param value the RunContextOperation element | ||
333 | * @return GNUNET_YES to continue iteration; GNUNET_NO to cancel it | ||
334 | */ | ||
310 | static int | 335 | static int |
311 | search_iterator (void *cls, uint32_t key, void *value) | 336 | search_iterator (void *cls, uint32_t key, void *value) |
312 | { | 337 | { |
@@ -323,6 +348,15 @@ search_iterator (void *cls, uint32_t key, void *value) | |||
323 | return GNUNET_YES; | 348 | return GNUNET_YES; |
324 | } | 349 | } |
325 | 350 | ||
351 | |||
352 | /** | ||
353 | * Initiate a search for the given operation in the rcop_map | ||
354 | * | ||
355 | * @param rc the RunContext whose rcop_map will be searched for the given | ||
356 | * operation | ||
357 | * @param op the given operation to search for | ||
358 | * @return the matching RunContextOperation if found; NULL if not | ||
359 | */ | ||
326 | static struct RunContextOperation * | 360 | static struct RunContextOperation * |
327 | search_rcop (struct RunContext *rc, struct GNUNET_TESTBED_Operation *op) | 361 | search_rcop (struct RunContext *rc, struct GNUNET_TESTBED_Operation *op) |
328 | { | 362 | { |
@@ -342,6 +376,13 @@ search_rcop (struct RunContext *rc, struct GNUNET_TESTBED_Operation *op) | |||
342 | return NULL; | 376 | return NULL; |
343 | } | 377 | } |
344 | 378 | ||
379 | |||
380 | /** | ||
381 | * Insert an RunContextOperation into the rcop_map of the given RunContext | ||
382 | * | ||
383 | * @param rc the RunContext into whose map is to be used for insertion | ||
384 | * @param rcop the RunContextOperation to insert | ||
385 | */ | ||
345 | static void | 386 | static void |
346 | insert_rcop (struct RunContext *rc, struct RunContextOperation *rcop) | 387 | insert_rcop (struct RunContext *rc, struct RunContextOperation *rcop) |
347 | { | 388 | { |
@@ -351,6 +392,14 @@ insert_rcop (struct RunContext *rc, struct RunContextOperation *rcop) | |||
351 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 392 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
352 | } | 393 | } |
353 | 394 | ||
395 | |||
396 | /** | ||
397 | * Remove a RunContextOperation from the rcop_map of the given RunContext | ||
398 | * | ||
399 | * @param rc the RunContext from whose map the given RunContextOperaton has to | ||
400 | * be removed | ||
401 | * @param rcop the RunContextOperation | ||
402 | */ | ||
354 | static void | 403 | static void |
355 | remove_rcop (struct RunContext *rc, struct RunContextOperation *rcop) | 404 | remove_rcop (struct RunContext *rc, struct RunContextOperation *rcop) |
356 | { | 405 | { |
@@ -395,6 +444,15 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
395 | GNUNET_free (rc); | 444 | GNUNET_free (rc); |
396 | } | 445 | } |
397 | 446 | ||
447 | |||
448 | /** | ||
449 | * Iterator for cleaning up elements from rcop_map | ||
450 | * | ||
451 | * @param cls the RunContext | ||
452 | * @param key the 32-bit key | ||
453 | * @param value the RunContextOperation element | ||
454 | * @return always GNUNET_YES | ||
455 | */ | ||
398 | static int | 456 | static int |
399 | rcop_cleanup_iterator (void *cls, uint32_t key, void *value) | 457 | rcop_cleanup_iterator (void *cls, uint32_t key, void *value) |
400 | { | 458 | { |
@@ -408,6 +466,13 @@ rcop_cleanup_iterator (void *cls, uint32_t key, void *value) | |||
408 | return GNUNET_YES; | 466 | return GNUNET_YES; |
409 | } | 467 | } |
410 | 468 | ||
469 | |||
470 | /** | ||
471 | * Frees memory, closes pending operations, cancels actives tasks of the given | ||
472 | * RunContext | ||
473 | * | ||
474 | * @param rc the RunContext | ||
475 | */ | ||
411 | static void | 476 | static void |
412 | cleanup (struct RunContext *rc) | 477 | cleanup (struct RunContext *rc) |
413 | { | 478 | { |
@@ -509,6 +574,12 @@ shutdown_now (struct RunContext *rc) | |||
509 | } | 574 | } |
510 | 575 | ||
511 | 576 | ||
577 | /** | ||
578 | * Task run upon any interrupt. Common ones are SIGINT & SIGTERM. | ||
579 | * | ||
580 | * @param cls the RunContext which has to be acted upon | ||
581 | * @param tc the scheduler task context | ||
582 | */ | ||
512 | static void | 583 | static void |
513 | interrupt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 584 | interrupt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
514 | { | 585 | { |