Example #1
0
int conman_client_handle_events(struct conman_client_s *client)
{
  sq_queue_t qevents;
  int ret;

  sq_init(&qevents);

  ret = conman_wait_for_response(client, true, &qevents);

  handle_queued_events(client, &qevents);

  return ret;
}
Example #2
0
int conman_client_get_connection_status(struct conman_client_s *client,
                                        struct conman_status_s *status)
{
  sq_queue_t qevents;
  int ret;

  if (!status)
    {
      return ERROR;
    }

  ret = conman_send_req(client->sd, CONMAN_MSG_GET_CONNECTION_STATUS,
                        NULL, 0);
  if (ret != OK)
    {
      conman_dbg("conman_send_req failed\n");
      return ERROR;
    }

  sq_init(&qevents);

  ret = conman_wait_for_response(client, false, &qevents);
  if (ret != OK)
    {
      conman_dbg("conman communication failed\n");
      ret = ERROR;
      goto out;
    }

  if (client->respval != CONMAN_RESP_OK)
    {
      ret = ERROR;
      goto out;
    }

  DEBUGASSERT(sizeof(*status) == client->payloadlen);

  memcpy(status, client->payload, sizeof(*status));
  free(client->payload);
  client->payload = NULL;

  ret = OK;

out:
  handle_queued_events(client, &qevents);
  return ret;
}
Example #3
0
int conman_client_request_connection(struct conman_client_s *client,
                                     enum conman_connection_type_e type,
                                     uint32_t *connid)
{
  sq_queue_t qevents;
  int ret;

  ret = conman_send_req(client->sd, CONMAN_MSG_CREATE_CONNECTION, &type,
      sizeof(type));
  if (ret != OK)
    {
      conman_dbg("conman_send_req failed\n");
      return ERROR;
    }

  sq_init(&qevents);

  ret = conman_wait_for_response(client, false, &qevents);
  if (ret != OK)
    {
      conman_dbg("conman communication failed\n");
      ret = ERROR;
      goto out;
    }

  if (client->respval != CONMAN_RESP_OK)
    {
      ret = ERROR;
      goto out;
    }

  DEBUGASSERT(sizeof(*connid) == client->payloadlen);

  memcpy(connid, client->payload, sizeof(*connid));
  free(client->payload);
  client->payload = NULL;

  ret = OK;

out:
  handle_queued_events(client, &qevents);
  return ret;
}
Example #4
0
// Handle trigger requests from the sim module ("sim_exec.trigger")
static void trigger_cb (flux_t *h,
                        flux_msg_handler_t *w,
                        const flux_msg_t *msg,
                        void *arg)
{
    json_t *o = NULL;
    const char *json_str = NULL;
    double next_termination = -1;
    zhash_t *job_hash = NULL;
    ctx_t *ctx = (ctx_t *)arg;

    if (flux_msg_get_string (msg, &json_str) < 0 || json_str == NULL
        || !(o = Jfromstr (json_str))) {
        flux_log (h, LOG_ERR, "%s: bad message", __FUNCTION__);
        return;
    }

    // Logging
    flux_log (h,
              LOG_DEBUG,
              "received a trigger (sim_exec.trigger: %s",
              json_str);

    // Handle the trigger
    ctx->sim_state = json_to_sim_state (o);
    handle_queued_events (ctx);
#if SIMEXEC_IO
    job_hash = determine_all_min_bandwidth (ctx->rdl, ctx->running_jobs);
#endif
    advance_time (ctx, job_hash);
    handle_completed_jobs (ctx);
    next_termination =
        determine_next_termination (ctx, ctx->sim_state->sim_time, job_hash);
    set_event_timer (ctx, "sim_exec", next_termination);
    send_reply_request (h, module_name, ctx->sim_state);

    // Cleanup
    free_simstate (ctx->sim_state);
    ctx->sim_state = NULL;
    Jput (o);
    zhash_destroy (&job_hash);
}
Example #5
0
static int do_command_no_payload(struct conman_client_s *client, uint8_t type,
                                 const void *buf, size_t buflen)
{
  sq_queue_t qevents;
  int ret;

  ret = conman_send_req(client->sd, type, buf, buflen);
  if (ret != OK)
    {
      conman_dbg("conman_send_req failed\n");
      return ERROR;
    }

  sq_init(&qevents);

  ret = conman_wait_for_response(client, false, &qevents);
  if (ret != OK)
    {
      conman_dbg("conman communication failed\n");
      ret = ERROR;
      goto out;
    }

  if (client->respval != CONMAN_RESP_OK)
    {
      ret = ERROR;
      goto out;
    }

  DEBUGASSERT(client->payload == NULL);

  ret = OK;

out:
  handle_queued_events(client, &qevents);
  return ret;
}
Example #6
0
int conman_client_send_sms(struct conman_client_s *client,
                           const char *phonenumber, const char *message)
{
  struct conman_msg_send_sms_s sms = {};
  size_t receiverlen = strlen(phonenumber);
  size_t messagelen = strlen(message);
  struct iovec bufs[3];
  sq_queue_t qevents;
  int ret;

  sms.message_len = messagelen + 1;
  sms.receiver_len = receiverlen + 1;

  if (sms.message_len != messagelen + 1)
    {
      conman_dbg("Too long message\n");
      return ERROR;
    }

  if (sms.receiver_len != receiverlen + 1)
    {
      conman_dbg("Too long phone-number\n");
      return ERROR;
    }

  bufs[0].iov_base = &sms;
  bufs[0].iov_len = sizeof(sms);
  bufs[1].iov_base = (void *)phonenumber;
  bufs[1].iov_len = receiverlen + 1;
  bufs[2].iov_base = (void *)message;
  bufs[2].iov_len = messagelen + 1;

  ret = conman_send_reqv(client->sd, CONMAN_MSG_SEND_SMS, bufs, 3);
  if (ret != OK)
    {
      conman_dbg("conman_send_reqv failed\n");
      return ERROR;
    }

  sq_init(&qevents);

  ret = conman_wait_for_response(client, false, &qevents);
  if (ret != OK)
    {
      conman_dbg("conman communication failed\n");
      ret = ERROR;
      goto out;
    }

  DEBUGASSERT(client->payload == NULL);

  if (client->respval != CONMAN_RESP_OK)
    {
      ret = ERROR;
      goto out;
    }

  ret = OK;

out:
  handle_queued_events(client, &qevents);
  return ret;
}