-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrpcClient.impl
38 lines (32 loc) · 1.13 KB
/
GrpcClient.impl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef GRPC_CLIENT_IMPL
#define GRPC_CLIENT_IMPL
#include <grpcpp/grpcpp.h>
#include <iostream>
#include <memory>
template <class Service>
GrpcClient<Service>::GrpcClient(std::shared_ptr<grpc::Channel> channel)
: m_stub{Service::NewStub(channel)} {}
template <class Service>
template <class Call, class Reply>
void GrpcClient<Service>::makeCall(
const Call &call,
const typename GrpcClientCallData<typename Service::Stub, Call,
Reply>::CallPreparer &callPreparer,
const typename GrpcClientCallData<typename Service::Stub, Call,
Reply>::ReplyHandler &replyHandler) {
GrpcClientCallData<typename Service::Stub, Call, Reply>::create(
*m_stub.get(), call, callPreparer, replyHandler, &m_completionQueue);
}
template <class Service>
void GrpcClient<Service>::startHandlingReplies() {
void *tag;
bool ok = false;
while (m_completionQueue.Next(&tag, &ok)) {
if (!ok) {
std::cerr << "Error found while handling reply" << std::endl;
}
auto callData{static_cast<GrpcClientCallDataBase *>(tag)};
callData->finish();
}
}
#endif