#include "logger.hpp"
#include "tcp_server.hpp"
#include "tinypb.pb.h"
#include <google/protobuf/service.h>
#include <iostream>
using namespace std;
using namespace tinyrpc;

class QueryServiceImpl : public QueryService {
public:
    QueryServiceImpl() { }
    ~QueryServiceImpl() { }

    void query_name(google::protobuf::RpcController* controller,
        const ::queryNameReq* request,
        ::queryNameRes* response,
        ::google::protobuf::Closure* done) override
    {
        logger() << "QueryServiceImpl.query_name, req={" << request->ShortDebugString() << "}";
        response->set_ret_code(0);
        response->set_res_info("OK");
        response->set_req_no(request->req_no());
        response->set_id(request->id());
        response->set_name("yyy");
        done->Run();
    }

    void query_age(google::protobuf::RpcController* controller,
        const ::queryAgeReq* request,
        ::queryAgeRes* response,
        ::google::protobuf::Closure* done) override
    {
        logger() << "QueryServiceImpl.query_name, req={" << request->ShortDebugString() << "}";
        response->set_ret_code(0);
        response->set_res_info("OK");
        response->set_req_no(request->req_no());
        response->set_id(request->id());
        response->set_age(20);
        done->Run();
    }

private:
};

int main()
{
    TcpServer server("0.0.0.0", 9001);
    server.registerService(std::make_shared<QueryServiceImpl>());
    server.start();
    return 0;
}
