/**
 * Function run on shutdown.
 *
 * @param cls closure
 */
static void
do_shutdown (void *cls)
{
  if (NULL != timeout_task)
  {
    GNUNET_SCHEDULER_cancel (timeout_task);
    timeout_task = NULL;
  }
  if (NULL != op)
  {
    GNUNET_IDENTITY_cancel (op);
    op = NULL;
  }
  if (NULL != call1)
  {
    GNUNET_CONVERSATION_call_stop (call1);
    call1 = NULL;
  }
  if (NULL != call2)
  {
    GNUNET_CONVERSATION_call_stop (call2);
    call2 = NULL;
  }
  if (NULL != phone)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n");
    GNUNET_CONVERSATION_phone_destroy (phone);
    phone = NULL;
  }
  if (NULL != id)
  {
    GNUNET_IDENTITY_disconnect (id);
    id = NULL;
  }
  if (NULL != qe)
  {
    GNUNET_NAMESTORE_cancel (qe);
    qe = NULL;
  }
  if (NULL != ns)
  {
    GNUNET_NAMESTORE_disconnect (ns);
    ns = NULL;
  }
}
/**
 * Signature of the main function of a task.
 *
 * @param cls closure
 * @param tc context information (why was this task triggered now)
 */
static void
end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
    GNUNET_SCHEDULER_shutdown ();
    if (NULL != op)
    {
        GNUNET_IDENTITY_cancel (op);
        op = NULL;
    }
    if (NULL != call)
    {
        GNUNET_CONVERSATION_call_stop (call);
        call = NULL;
    }
    if (NULL != phone)
    {
        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n");
        GNUNET_CONVERSATION_phone_destroy (phone);
        phone = NULL;
    }
    if (NULL != id)
    {
        GNUNET_IDENTITY_disconnect (id);
        id = NULL;
    }
    if (NULL != qe)
    {
        GNUNET_NAMESTORE_cancel (qe);
        qe = NULL;
    }
    if (NULL != ns)
    {
        GNUNET_NAMESTORE_disconnect (ns);
        ns = NULL;
    }
}