removed GNUNET_TESTBED_operation_cancel
[oweals/gnunet.git] / src / testbed / testbed_api_test.c
index 0b3844011e9f872f33737bf754bc3ea2df959af0..580917aa76e0c50969c1b256b1e45efcf0217807 100644 (file)
@@ -42,7 +42,22 @@ struct TestRunContext
    * Closure for test master
    */
   void *test_master_cls;
+
+  /**
+   * The controller event callback
+   */
+  GNUNET_TESTBED_ControllerCallback cc;
+
+  /**
+   * Closure for the above callback
+   */
+  void *cc_cls;
   
+  /**
+   * event mask for the controller callback
+   */
+  uint64_t event_mask;
+
   /**
    * Number of peers to start
    */
@@ -72,11 +87,13 @@ controller_event_cb (void *cls,
 {
   struct TestRunContext *rc = cls;
 
+  if ((NULL != rc->cc) && (0 != (rc->event_mask & (1LL << event->type))))
+    rc->cc (rc->cc_cls, event);
   if (rc->peer_cnt == rc->num_peers)
     return;
   GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type);
   GNUNET_assert (NULL == rc->peers[rc->peer_cnt]);
-  GNUNET_assert (NULL != event->details.peer_start.peer);  
+  GNUNET_assert (NULL != event->details.peer_start.peer);
   rc->peers[rc->peer_cnt++] = event->details.peer_start.peer;
 }
 
@@ -91,7 +108,7 @@ static void
 master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct TestRunContext *rc = cls;
-  
+
   GNUNET_assert (rc->peer_cnt == rc->num_peers);
   rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers);
 }
@@ -103,16 +120,19 @@ master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param cls NULL
  * @param args arguments passed to GNUNET_PROGRAM_run
  * @param cfgfile the path to configuration file
- * @param cfg the configuration file handle
+ * @param config the configuration file handle
  */
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *config)
 {
   struct TestRunContext *rc = cls;
-
-  GNUNET_TESTBED_run (NULL, config, rc->num_peers, 0, &controller_event_cb,
-                      rc, &master_task, rc);
+  uint64_t event_mask;
+  
+  event_mask = rc->event_mask;
+  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
+  GNUNET_TESTBED_run (NULL, config, rc->num_peers, event_mask,
+                      &controller_event_cb, rc, &master_task, rc);
 }
 
 
@@ -136,12 +156,24 @@ run (void *cls, char *const *args, const char *cfgfile,
  * @param cfg_filename configuration filename to use
  *              (for testbed, controller and peers)
  * @param num_peers number of peers to start
+ * @param event_mask bit mask with set of events to call 'cc' for;
+ *                   or-ed values of "1LL" shifted by the
+ *                   respective 'enum GNUNET_TESTBED_EventType'
+ *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
+ * @param cc controller callback to invoke on events; This callback is called
+ *        for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
+ *        set in the event_mask as this is the only way get access to the
+ *        handle of each peer
+ * @param cc_cls closure for cc
  * @param test_master task to run once the test is ready
  * @param test_master_cls closure for 'task'.
  */
 void
 GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename,
                          unsigned int num_peers,
+                         uint64_t event_mask,
+                         GNUNET_TESTBED_ControllerCallback cc,
+                         void *cc_cls,
                          GNUNET_TESTBED_TestMaster test_master,
                          void *test_master_cls)
 {
@@ -155,22 +187,24 @@ GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename,
     GNUNET_GETOPT_OPTION_END
   };
   struct TestRunContext *rc;
-  
+
   argv2[0] = GNUNET_strdup (testname);
   argv2[2] = GNUNET_strdup (cfg_filename);
   GNUNET_assert (NULL != test_master);
+  GNUNET_assert (num_peers > 0);
   rc = GNUNET_malloc (sizeof (struct TestRunContext) +
                       (num_peers * sizeof (struct GNUNET_TESTBED_Peer *)));
   rc->test_master = test_master;
   rc->test_master_cls = test_master_cls;
-  rc->num_peers = rc->num_peers;
+  rc->num_peers = num_peers;
+  rc->event_mask = event_mask;
+  rc->cc = cc;
+  rc->cc_cls = cc_cls;
   (void) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
-                             "testname", "nohelp", options, &run, rc);
+                             testname, "nohelp", options, &run, rc);
   GNUNET_free (rc);
   GNUNET_free (argv2[0]);
   GNUNET_free (argv2[2]);
 }
 
-
-
 /* end of testbed_api_test.c */