Esempio n. 1
0
void node_received(char *line) {
    fprintf(stderr, "app:  Received: '%s'\n", line);

    json_error_t error;
    json_t *incoming = json_loads(line, 0, &error);
    const char *command = json_string_value(json_array_get(incoming, 0));
    assert(command);
    json_t *arg = json_array_get(incoming, 1);

    msg_func_t handler = find_msg_handler(command);
    if (handler == NULL) {
        fprintf(stderr,  "app:  Unknown command received: '%s'", command);
        exit(1);
    } else {
        json_t *response = handler(arg);
        if (json_array_size(incoming) > 2) {
            json_t *response_command = json_array_get(incoming, 2);
            json_t *array = json_array();
            json_array_append(array, response_command);
            if (response)
                json_array_append_new(array, response);
            else
                json_array_append_new(array, json_null());
            node_send_json(array);
        } else {
            if (response)
                json_decref(response);
        }
    }

    json_decref(incoming);
    free(line);
}
Esempio n. 2
0
int process_msg(struct rpc *r, struct iovec *buf)
{
    msg_handler_t msg_handler;

    int msg_id = rpc_packet_parse(r);
    if (find_msg_handler(msg_id, &msg_handler) == 0) {
        msg_handler.cb(r, buf->iov_base, buf->iov_len);
    } else {
        //loge("no callback for this MSG ID(0x%08x) in process_msg\n", msg_id);
    }
    return 0;
}
Esempio n. 3
0
int process_msg2(struct rpc *r, struct iobuf *buf)
{
    msg_handler_t msg_handler;

    int msg_id = rpc_packet_parse(r);
//    logi("msg_id = %x\n", msg_id);
    if (find_msg_handler(msg_id, &msg_handler) == 0 ) {
        msg_handler.cb(r, buf->addr, buf->len);
    } else {
        loge("no callback for this MSG ID in process_msg\n");
    }
    return 0;
}
Esempio n. 4
0
File: rpcd.c Progetto: gozfree/src
int process_msg(struct rpc *r, struct iobuf *buf)
{
    int ret;
    msg_handler_t msg_handler;
    struct rpc_header *h = &r->packet.header;
    int msg_id = rpc_packet_parse(r);

    if (find_msg_handler(msg_id, &msg_handler) == 0) {
        msg_handler.cb(r, buf->addr, buf->len);
    } else {
        loge("no callback for this MSG ID in process_msg\n");
        char *valfd = (char *)dict_get(_rpcd->dict_uuid2fd, h->uuid_dst, NULL);
        if (!valfd) {
            loge("dict_get failed: key=%s\n", h->uuid_dst);
            return -1;
        }
        int dst_fd = strtol(valfd, NULL, 16);
        r->fd = dst_fd;
        ret = rpc_send(r, buf->addr, buf->len);
    }
    return ret;
}