예제 #1
0
ConsoleEvent
QmfObject::method_call(std::string method,
		       qpid::types::Variant::Map in_args)
{
	Agent a = _qmf_data.getAgent();
	return a.callMethod(method, in_args, _qmf_data.getAddr());
}
int main(int argc, char **argv)
{
    qpid::types::Variant::Map options;
    qpid::types::Variant::Map callOptions;
    qpid::messaging::Connection connection;
    string sessionOptions;
    ConsoleEvent event;
    Agent agent;

    mh_log_init("sysconfig-console", LOG_TRACE, TRUE);

    mh_add_option('U', required_argument, "uri", "URI of configuration", &options, NULL);
    mh_add_option('d', no_argument, "daemon", "run as a daemon", NULL, mh_should_daemonize);

    qpid::types::Variant::Map amqp_options = mh_parse_options("sysconfig-console", argc, argv, options);

    callOptions["uri"] = options["uri"];

    mh_log_init("sysconfig-console", mh_log_level, mh_log_level > LOG_INFO);

    connection = mh_connect(options, amqp_options, TRUE);
    connection.open();

    ConsoleSession session(connection, sessionOptions);
    // Only filter connecting agents under matahariproject.org vendor and Config product
    session.setAgentFilter("[and, [eq, _vendor, [quote, 'matahariproject.org']], [eq, _product, [quote, 'Sysconfig']]]");
    session.open();

    while(session.getAgentCount() == 0) {
        g_usleep(1000);
    }

    while (true) {
        if(session.nextEvent(event)) {
            switch(event.getType()) {
                case CONSOLE_AGENT_ADD:
                    {
                        agent = event.getAgent();
                        DataAddr agent_event_addr("Sysconfig", agent.getName(), 0);
                        ConsoleEvent result(agent.callMethod("run_uri",
                                                              callOptions,
                                                              agent_event_addr));
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return 0;
}