コード例 #1
0
static void mongoose_ev_handler(struct mg_connection *c, int ev, void *p) {
  LOG(LL_VERBOSE_DEBUG,
      ("%p ev %d p %p fl %lx l %lu %lu", c, ev, p, c->flags,
       (unsigned long) c->recv_mbuf.len, (unsigned long) c->send_mbuf.len));

  switch (ev) {
    case MG_EV_ACCEPT: {
      char addr[32];
      mg_sock_addr_to_str(&c->sa, addr, sizeof(addr),
                          MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
      LOG(LL_INFO, ("%p HTTP connection from %s", c, addr));
      break;
    }
    case MG_EV_HTTP_REQUEST: {
      struct http_message *hm = (struct http_message *) p;
      LOG(LL_INFO, ("%p %.*s %.*s", c, (int) hm->method.len, hm->method.p,
                    (int) hm->uri.len, hm->uri.p));

      mg_serve_http(c, p, s_http_server_opts);
      c->flags |= MG_F_SEND_AND_CLOSE;
      break;
    }
    case MG_EV_CLOSE: {
      /* If we've sent the reply to the server, and should reboot, reboot */
      if (c->flags & MG_F_RELOAD_CONFIG) {
        c->flags &= ~MG_F_RELOAD_CONFIG;
        device_reboot();
      }
      break;
    }
  }
}
コード例 #2
0
static int do_firmware_update(void *param)
{
    int   retValue;
    PHYSICAL_DEVICE *physical_device = (PHYSICAL_DEVICE *) param;
    
    LogInfo("do_firmware_update('%s')", physical_device->new_firmware_URI);
    if (!set_physical_device_fwupdate_status(physical_device, downloading))
    {
        LogError("failed to update device status");
        retValue = -1;
    }
    else
    {
        bool result = device_download_firmware(physical_device->new_firmware_URI);
        if (result)
        {
            if (!set_physical_device_fwupdate_status(physical_device, downloadComplete))
            {
                LogError("failed to update device status");
                retValue = -1;
            }
            else
            {
                LogInfo("starting fw update");
                if (!set_physical_device_fwupdate_status(physical_device, applying))
                {
                    LogError("failed to update device status");
                    retValue = -1;
                }
                else
                {
                    result = device_update_firmware();
                    if (result)
                    {
                        device_reboot();
                        retValue = 0;
                    }
                    else
                    {
                        if (!set_physical_device_fwupdate_status(physical_device, applyFailed))
                        {
                            LogError("failed to update device status");
                        }
                        LogError("firmware update failed during apply");
                        retValue = -1;
                    }
                }
            }
        }
        else
        {
            LogError("failed to download new firmware image from '%s'", physical_device->new_firmware_URI);
            if (!set_physical_device_fwupdate_status(physical_device, downloadFailed))
            {
                LogError("failed to update device status");
            }
            retValue = -1;
        }
    }
    return retValue;
}