Exemple #1
0
void db_event_handler(struct mg_connection* nc, int ev, void* ev_data)
{
    struct http_message* hm = (struct http_message*) ev_data;

    switch (ev) {
    case MG_EV_HTTP_REQUEST:
        if (mg_vcmp(&hm->uri, "/pictDB/list") == 0) {
            handle_list_call(nc);
        } else if (mg_vcmp(&hm->uri, "/pictDB/read") == 0) {
            handle_read_call(nc, hm);
        } else if (mg_vcmp(&hm->uri, "/pictDB/insert") == 0) {
            handle_insert_call(nc, hm);
        } else if (mg_vcmp(&hm->uri, "/pictDB/delete") == 0) {
            handle_delete_call(nc, hm);
        } else {
            mg_serve_http(nc, hm, s_http_server_opts); // Serve static content
        }
        break;
    default:
        break;
    }
}
static int pseudo_device_ioctl(struct inode *inode, struct file *file,
                               unsigned int cmd, unsigned long arg)
{

    switch (cmd)
    {

    case RD_INIT:
        down_interruptible(&mutex);
        handle_init();
        up(&mutex);
        break;
    case RD_CREAT:
        down_interruptible(&mutex);
        handle_creat_call(arg);
        up(&mutex);
        break;

    case RD_MKDIR:
        down_interruptible(&mutex);
        handle_mkdir_call(arg);
        up(&mutex);
        break;

    case RD_OPEN:
        down_interruptible(&mutex);
        handle_open_call(arg);
        up(&mutex);
        break;

    case RD_CLOSE:
        down_interruptible(&mutex);
        handle_close_call(arg);
        up(&mutex);
        break;

    case RD_READ:
        down_interruptible(&mutex);
        handle_read_call(arg);
        up(&mutex);
        break;

    case RD_WRITE:
        down_interruptible(&mutex);
        handle_write_call(arg);
        up(&mutex);
        break;

    case RD_SEEK:
        down_interruptible(&mutex);
        handle_seek_call(arg);
        up(&mutex);
        break;

    case RD_READDIR:
        down_interruptible(&mutex);
        handle_readdir_call(arg);
        up(&mutex);
        break;

    case RD_UNLINK:
        down_interruptible(&mutex);
        handle_unlink_call(arg);
        up(&mutex);
        break;

    case RD_TEST:
        down_interruptible(&mutex);
        handle_test(arg);
        up(&mutex);        

    default:
        return -EINVAL;
        break;
    }

    return 0;
}