static int parse_nodes(char *p_hostfile, int nodes)
{
    int i = 0, ret = 0, parsed = 0;
    char buf[TC_BUF_LINE];

    if (nodes > PVM_MAX_NODES) {
        tc_log_warn(__FILE__, "excessive nodes requested, autolimit to %i",
                    PVM_MAX_NODES);
        nodes = PVM_MAX_NODES;
    }

    for (i = 0; i < nodes; i++) {
        tc_snprintf(buf, sizeof(buf), "Node%i", i+1);

        ret = module_read_config(p_hostfile, buf, node_conf[i], __FILE__);
        if (ret) {
            int done = dispatch_node(i, &nodes_data[i], &s_pvm_conf);
            if (done) {
                parsed++;
            }
        }
    }
    return parsed;
}
Exemple #2
0
int dispatch(int fd, const char * buf, uint32_t len)
{
    c_node * p_node = find_node_by_fd(fd);
    if (NULL != p_node)
    {
        return dispatch_node(p_node, buf, len);
    }


    const head_proto_t * pkg = reinterpret_cast<const head_proto_t *>(buf);


    uint16_t cmd = pkg->cmd;
    uint32_t seq = pkg->seq;
    uint32_t node_id = pkg->id;
    uint32_t body_len = len - sizeof(head_proto_t);

    TRACE_LOG("dispatch[%u] sender=%u, fd=%u, seq=%u, len=%u",
			cmd, node_id, fd, seq, len);

    // if (head_p_get_version_cmd == cmd)
    // {
        // return get_version();
    // }
    // else if (head_p_node_register_cmd == cmd)
    // {
        // return head_p_node_register(fd, pkg->body, body_len);
    // }
    // else if (head_p_get_node_data_cmd == cmd)
    // {
        // return head_p_get_node_data(fd, node_id);
    // }
    // else
    // {
        // p_node = find_node(node_id);
        // if (NULL == p_node)
        // {
            // ERROR_LOG("unregistered node, fd: %d, node id: %u", fd, node_id);
            // net_close_cli(fd);
            // return -1;
        // }
    // }


    const cmd_proto_t * p_cmd = find_head_cmd(cmd);
    if (NULL == p_cmd)
    {
        ERROR_LOG("cmdid not existed: %u", cmd);
        return 0;
    }


    bool read_ret = p_cmd->p_in->read_from_buf_ex(pkg->body, body_len);
    if (!read_ret) 
    {
        ERROR_LOG("read_from_buf_ex error cmd=%u, u=%u", cmd, node_id);
        return -1;
    }



    int cmd_ret = p_cmd->func(&fd, p_cmd->p_in, p_cmd->p_out);


    return cmd_ret;
}