aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_testbed.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-12-12 15:47:30 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-12-12 15:47:30 +0000
commitff2dda0f622660d3bea5fe889029d04d59706e0a (patch)
treeab0d9a96af78860d318de8adb0d0d0be81c42c22 /src/testbed/testbed_api_testbed.c
parent51cea9066b6b3ce46913edce9978c8b90e4c9fd9 (diff)
downloadgnunet-ff2dda0f622660d3bea5fe889029d04d59706e0a.tar.gz
gnunet-ff2dda0f622660d3bea5fe889029d04d59706e0a.zip
- de-duplicate
Diffstat (limited to 'src/testbed/testbed_api_testbed.c')
-rw-r--r--src/testbed/testbed_api_testbed.c57
1 files changed, 41 insertions, 16 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index dc5546644..5c07fbfab 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -394,6 +394,30 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
394 * @param tc the task context from scheduler 394 * @param tc the task context from scheduler
395 */ 395 */
396static void 396static void
397shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
398
399
400/**
401 * Function to shutdown now
402 *
403 * @param rc the RunContext
404 */
405static void
406shutdown_now (struct RunContext *rc)
407{
408 if (GNUNET_SCHEDULER_NO_TASK != rc->shutdown_run_task)
409 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task);
410 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
411}
412
413
414/**
415 * Stops the testbed run and releases any used resources
416 *
417 * @param cls the tesbed run handle
418 * @param tc the task context from scheduler
419 */
420static void
397shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 421shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
398{ 422{
399 struct RunContext *rc = cls; 423 struct RunContext *rc = cls;
@@ -552,8 +576,7 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
552 { 576 {
553 LOG (GNUNET_ERROR_TYPE_ERROR, 577 LOG (GNUNET_ERROR_TYPE_ERROR,
554 _("Linking controllers failed. Exiting")); 578 _("Linking controllers failed. Exiting"));
555 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task); 579 shutdown_now (rc);
556 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
557 } 580 }
558 else 581 else
559 rc->reg_hosts++; 582 rc->reg_hosts++;
@@ -568,9 +591,8 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
568 } 591 }
569 return; 592 return;
570 default: 593 default:
571 GNUNET_assert (0); 594 GNUNET_break (0);
572 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task); 595 shutdown_now (rc);
573 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
574 return; 596 return;
575 } 597 }
576 } 598 }
@@ -583,9 +605,8 @@ event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
583 rc->oc_count++; 605 rc->oc_count++;
584 break; 606 break;
585 default: 607 default:
586 GNUNET_assert (0); 608 GNUNET_break (0);
587 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task); 609 shutdown_now (rc);
588 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
589 return; 610 return;
590 } 611 }
591 if (rc->oc_count == rc->num_oc) 612 if (rc->oc_count == rc->num_oc)
@@ -733,8 +754,7 @@ host_registration_completion (void *cls, const char *emsg)
733 { 754 {
734 LOG (GNUNET_ERROR_TYPE_WARNING, 755 LOG (GNUNET_ERROR_TYPE_WARNING,
735 _("Host registration failed for a host. Error: %s\n"), emsg); 756 _("Host registration failed for a host. Error: %s\n"), emsg);
736 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task); 757 shutdown_now (rc);
737 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
738 return; 758 return;
739 } 759 }
740 rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, rc); 760 rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, rc);
@@ -800,8 +820,15 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
800 820
801 if (status != GNUNET_OK) 821 if (status != GNUNET_OK)
802 { 822 {
803 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n"); 823 switch (rc->state)
804 return; 824 {
825 case RC_INIT:
826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n");
827 return;
828 default:
829 shutdown_now (rc);
830 return;
831 }
805 } 832 }
806 GNUNET_CONFIGURATION_destroy (rc->cfg); 833 GNUNET_CONFIGURATION_destroy (rc->cfg);
807 rc->cfg = GNUNET_CONFIGURATION_dup (cfg); 834 rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
@@ -853,8 +880,7 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, int status
853 GNUNET_TESTBED_host_get_hostname (host)); 880 GNUNET_TESTBED_host_get_hostname (host));
854 else 881 else
855 LOG (GNUNET_ERROR_TYPE_ERROR, _("Testbed cannot be started on localhost\n")); 882 LOG (GNUNET_ERROR_TYPE_ERROR, _("Testbed cannot be started on localhost\n"));
856 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task); 883 shutdown_now (rc);
857 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
858 return; 884 return;
859 } 885 }
860 rc->reg_hosts++; 886 rc->reg_hosts++;
@@ -879,8 +905,7 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, int status
879 if (NULL == rc->cproc) 905 if (NULL == rc->cproc)
880 { 906 {
881 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller")); 907 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller"));
882 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task); 908 shutdown_now (rc);
883 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
884 } 909 }
885} 910}
886 911