Skip to content

Commit

Permalink
update rpccode
Browse files Browse the repository at this point in the history
  • Loading branch information
ingangi committed Jul 9, 2020
1 parent f7338a9 commit 886bf0a
Show file tree
Hide file tree
Showing 9 changed files with 678 additions and 48 deletions.
25 changes: 6 additions & 19 deletions examples/rpc_example/test_client/test_client.cpp
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
#include "test_client.hpp"

call_Test_HowAreYou::call_Test_HowAreYou(chr::grpc_async_client_t *client) : test_rsp_sync_call_t(client)
template <>
int call_Service_API<rpcpb::Test, rpcpb::TestReq, rpcpb::TestRsp>::call_impl()
{
}

call_Test_HowAreYou::call_Test_HowAreYou(call_Test_HowAreYou &other) : test_rsp_sync_call_t(other)
{
m_req = other.m_req;
}

int call_Test_HowAreYou::call_impl()
{
m_stub = rpcpb::Test::NewStub(m_client_ptr->m_channel);
m_rsp_reader = m_stub->AsyncHowAreYou(&m_context, m_req, &m_client_ptr->m_completion_que);
m_rsp_reader->Finish(&m_result, &m_status, (void*)this);
return 0;
}

chr::client_call_it * call_Test_HowAreYou::clone_me()
{
return new call_Test_HowAreYou(*this);
m_stub = rpcpb::Test::NewStub(m_client_ptr->m_channel);
m_rsp_reader = m_stub->AsyncHowAreYou(&m_context, m_req, &m_client_ptr->m_completion_que);
m_rsp_reader->Finish(&m_result, &m_status, (void*)this);
return 0;
}
18 changes: 1 addition & 17 deletions examples/rpc_example/test_client/test_client.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@
#include "test.grpc.pb.h"
#include "grpc_sync_client_for_chroutine.hpp"

typedef chr::client_sync_call_t<rpcpb::TestRsp> test_rsp_sync_call_t;

class call_Test_HowAreYou final : public test_rsp_sync_call_t
{
public:
call_Test_HowAreYou(chr::grpc_async_client_t *client);
call_Test_HowAreYou(call_Test_HowAreYou &other);

private:
chr::client_call_it * clone_me();
int call_impl();

public:
std::unique_ptr<rpcpb::Test::Stub> m_stub;
rpcpb::TestReq m_req;
std::unique_ptr<::grpc::ClientAsyncResponseReader<rpcpb::TestRsp> > m_rsp_reader;
};
template <> int call_Service_API<rpcpb::Test, rpcpb::TestReq, rpcpb::TestRsp>::call_impl(); // for API: Test::HowAreYou

#endif
4 changes: 2 additions & 2 deletions examples/rpc_example/test_client/test_client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char **argv)
SPDLOG(INFO, "grpc_async_client_t {:p} created, is it ready? {}", (void*)client, client->ready());

int i = 0;
call_Test_HowAreYou caller(client);
call_Service_API<rpcpb::Test, rpcpb::TestReq, rpcpb::TestRsp> howareyou_caller(client);
rpcpb::TestRsp rsp;

while (client) {
Expand All @@ -31,7 +31,7 @@ int main(int argc, char **argv)
// }

SPDLOG(INFO, "try to call call_Test_HowAreYou the {}th time, is it ready? {}", i, client->ready());
::grpc::StatusCode code = caller.call_sync(rsp);
::grpc::StatusCode code = howareyou_caller.call_sync(rsp);
SPDLOG(INFO, "call_Test_HowAreYou code={} , rsp:{}. clinet ready? {} ", code, rsp.rsp(), client->ready());

// how we destroy a client
Expand Down
30 changes: 30 additions & 0 deletions net/proto_code/test.grpc.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 886bf0a

Please sign in to comment.