+ * We have requested a service to be started, this function
+ * is called with the result of the operation. Informs the
+ * use of the result; on success, we continue with the event
+ * loop, on failure we terminate the process.
+ *
+ * @param cls closure unused
+ * @param rs what happened to our request
+ * @param result if the request was processed, this is the result
+ * according to ARM
+ */
+static void
+init_callback (void *cls,
+ enum GNUNET_ARM_RequestStatus rs,
+ enum GNUNET_ARM_Result result)
+{
+ (void) cls;
+ op = NULL;
+ if (GNUNET_ARM_REQUEST_SENT_OK != rs)
+ {
+ FPRINTF (stdout,
+ _("Failed to send a request to start the `%s' service: %s\n"),
+ init,
+ req_string (rs));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if ((GNUNET_ARM_RESULT_STARTING != result) &&
+ (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
+ {
+ FPRINTF (stdout,
+ _("Failed to start the `%s' service: %s\n"),
+ init,
+ ret_string (result));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service %s [re]started successfully\n",
+ init);
+ GNUNET_free (init);
+ init = NULL;
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+}
+
+
+/**
+ * We have requested a service to be stopped, this function
+ * is called with the result of the operation. Informs the
+ * use of the result; on success, we continue with the event
+ * loop, on failure we terminate the process.
+ *
+ * @param cls closure unused
+ * @param rs what happened to our request
+ * @param result if the request was processed, this is the result
+ * according to ARM
+ */
+static void
+term_callback (void *cls,
+ enum GNUNET_ARM_RequestStatus rs,
+ enum GNUNET_ARM_Result result)
+{
+ char *msg;
+
+ (void) cls;
+ op = NULL;
+ if (GNUNET_ARM_REQUEST_SENT_OK != rs)
+ {
+ GNUNET_asprintf (&msg,
+ _("Failed to send a request to kill the `%s' service: %%s\n"),
+ term);
+ FPRINTF (stdout, msg, req_string (rs));
+ GNUNET_free (msg);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if ((GNUNET_ARM_RESULT_STOPPED != result) &&
+ (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
+ {
+ FPRINTF (stdout,
+ _("Failed to kill the `%s' service: %s\n"),
+ term,
+ ret_string (result));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Service %s stopped successfully\n",
+ term);
+ GNUNET_free (term);
+ term = NULL;
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+}
+
+
+/**
+ * Function called with the list of running services. Prints
+ * the list to stdout, then starts the event loop again.
+ * Prints an error message and terminates the process on errors.
+ *
+ * @param cls closure (unused)
+ * @param rs request status (success, failure, etc.)
+ * @param count number of services in the list
+ * @param list list of services that are running
+ */
+static void
+list_callback (void *cls,
+ enum GNUNET_ARM_RequestStatus rs,
+ unsigned int count,
+ const char *const*list)
+{
+ unsigned int i;
+
+ (void) cls;
+ op = NULL;
+ if (GNUNET_ARM_REQUEST_SENT_OK != rs)
+ {
+ char *msg;
+
+ GNUNET_asprintf (&msg, "%s",
+ _("Failed to request a list of services: %s\n"));
+ FPRINTF (stdout, msg, req_string (rs));
+ GNUNET_free (msg);
+ ret = 3;
+ GNUNET_SCHEDULER_shutdown ();
+ }
+ if (NULL == list)
+ {
+ FPRINTF (stderr, "%s",
+ _("Error communicating with ARM. ARM not running?\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ ret = 3;
+ return;
+ }
+ if (! quiet)
+ FPRINTF (stdout, "%s", _("Running services:\n"));
+ for (i = 0; i < count; i++)
+ FPRINTF (stdout, "%s\n", list[i]);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+}
+
+
+/**
+ * Main action loop. Runs the various jobs that we've been asked to
+ * do, in order.