コード例 #1
0
void AdStreamReceiveServer::dispatch(msgpack::rpc::request req)
{
    try
    {
        std::string method;
        req.method().convert(&method);


        if (method == AdStreamReceiveServerRequest::method_names[AdStreamReceiveServerRequest::METHOD_TEST])
        {
            LOG(INFO) << "got heart check msg.";
            //msgpack::type::tuple<bool> params;
            //req.params().convert(&params);
            req.result(true);
        }
        else if (method == AdStreamReceiveServerRequest::method_names[AdStreamReceiveServerRequest::METHOD_PUSH_ADMESSAGE])
        {
            //LOG(INFO) << "got pushed ad msg";
            //LOG(INFO) << "data:" << req.params();

            msgpack::type::tuple<AdMessageListData> params;
            req.params().convert(&params);
            AdMessageListData& data_list = params.get<0>();
            AdStreamSubscriber::get()->onAdMessage(data_list.msg_list);
            req.result(true);
        }
        else
        {
            req.error(msgpack::rpc::NO_METHOD_ERROR);
        }
    }
    catch (const msgpack::type_error& e)
    {
        req.error(msgpack::rpc::ARGUMENT_ERROR);
        LOG(WARNING) << "type error in rpc server." << e.what();
    }
    catch (const std::exception& e)
    {
        req.error(std::string(e.what()));
        LOG(WARNING) << "exception in rpc server." << e.what();
    }
}
コード例 #2
0
void QContentHubServer::dispatch(msgpack::rpc::request req) {
    try {
        std::string method;
        req.method().convert(&method);

        if(method == "push") {
            msgpack::type::tuple<std::string, std::string> params;
            req.params().convert(&params);
            push_queue(req, params.get<0>(), params.get<1>());
        } else if(method == "pop") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            pop_queue(req, params.get<0>());
        } else if(method == "push_nowait") {
            msgpack::type::tuple<std::string, std::string> params;
            req.params().convert(&params);
            push_queue_nowait(req, params.get<0>(), params.get<1>());
        } else if(method == "pop_nowait") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            pop_queue_nowait(req, params.get<0>());
        } else if(method == "add") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            add_queue(req, params.get<0>(), params.get<1>());
        /*
        } else if(method == "del") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            del_queue(req, params.get<0>());
        } else if(method == "fdel") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            force_del_queue(req, params.get<0>());
        */
        } else if(method == "set_capacity") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            set_queue_capacity(req, params.get<0>(), params.get<1>());
        } else if(method == "start") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            start_queue(req, params.get<0>());
        } else if(method == "stop") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stop_queue(req, params.get<0>());
        } else if(method == "clear") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            clear_queue(req, params.get<0>());
        } else if(method == "stats") {
            stats(req);
        } else if(method == "stat_queue") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stat_queue(req, params.get<0>());
        } else {
            req.error(msgpack::rpc::NO_METHOD_ERROR);
        }
    } catch (msgpack::type_error& e) {
        req.error(msgpack::rpc::ARGUMENT_ERROR);
        return;

    } catch (std::exception& e) {
        req.error(std::string(e.what()));
        return;
    }
}
コード例 #3
0
ファイル: qurlqueue_rpc.cpp プロジェクト: Kayven/qcontent
void QUrlQueueServer::dispatch(msgpack::rpc::request req)
{
    try {
        std::string method;
        req.method().convert(&method);

        if(method == "push") {
            msgpack::type::tuple<int, std::string, std::string> params;
            req.params().convert(&params);
            push_url(req, params.get<0>(), params.get<1>(), params.get<2>());
        } else if(method == "pop") {
            pop_url(req);
        } else if(method == "push_url_front") {
            msgpack::type::tuple<int, std::string, std::string> params;
            req.params().convert(&params);
            push_url_front(req, params.get<0>(), params.get<1>(), params.get<2>());
        } else if(method == "start_dump_all") {
            start_dump_all(req);
        } else if(method == "dump_all") {
            dump_all(req);
        } else if(method == "stats") {
            stats(req);
        } else if(method == "set_default_interval") {
            msgpack::type::tuple<int> params;
            req.params().convert(&params);
            set_default_interval(req, params.get<0>());
        } else if(method == "set_site_interval") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            set_site_interval(req, params.get<0>(), params.get<1>());
        } else if(method == "stat_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stat_site(req, params.get<0>());
        } else if(method == "dump_ordered_site") {
            msgpack::type::tuple<int> params;
            req.params().convert(&params);
            dump_ordered_site(req, params.get<0>());
        } else if(method == "start_all") {
            start_all(req);
        } else if(method == "stop_all") {
            stop_all(req);
        } else if(method == "start_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            start_site(req, params.get<0>());
        } else if(method == "stop_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stop_site(req, params.get<0>());
        } else if(method == "clear_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            clear_site(req, params.get<0>());
        } else if(method == "start_dump_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            start_dump_site(req, params.get<0>());
        } else if(method == "dump_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            dump_site(req, params.get<0>());
        } else if(method == "clear_empty_site") {
            clear_empty_site(req);
        } else {
            req.error(msgpack::rpc::NO_METHOD_ERROR);
        }
    } catch (msgpack::type_error& e) {
        req.error(msgpack::rpc::ARGUMENT_ERROR);
        return;

    } catch (std::exception& e) {
        req.error(std::string(e.what()));
        return;
    }
}