-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrpcServerCallData.impl
57 lines (53 loc) · 1.84 KB
/
GrpcServerCallData.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef GRPC_SERVER_CALL_DATA_IMPL
#define GRPC_SERVER_CALL_DATA_IMPL
template <class Service, class Call, class Reply>
void GrpcServerCallData<Service, Call, Reply>::create(
Service &service,
const GrpcServerCallData<Service, Call, Reply>::CallRequest &request,
const GrpcServerCallData<Service, Call, Reply>::CallHandler &handler,
grpc::ServerCompletionQueue *completionQueue) {
auto instance{std::unique_ptr<GrpcServerCallData>(
new GrpcServerCallData{service, request, handler, completionQueue})};
instance->m_self = std::move(instance);
}
template <class Service, class Call, class Reply>
GrpcServerCallData<Service, Call, Reply>::GrpcServerCallData(
Service &service,
const GrpcServerCallData<Service, Call, Reply>::CallRequest &request,
const GrpcServerCallData<Service, Call, Reply>::CallHandler &handler,
grpc::ServerCompletionQueue *completionQueue)
: m_request{request},
m_handler{handler},
m_service{service},
m_call{},
m_reply{},
m_status{Status::Create},
m_self{},
m_serverContext{},
m_responder{&m_serverContext},
m_completionQueue{completionQueue} {
proceed();
}
template <class Service, class Call, class Reply>
void GrpcServerCallData<Service, Call, Reply>::proceed() {
switch (m_status) {
case Status::Create:
std::invoke(m_request, m_service, &m_serverContext, &m_call, &m_responder,
m_completionQueue, m_completionQueue, this);
m_status = Status::Process;
return;
case Status::Process: {
create(m_service, m_request, m_handler, m_completionQueue);
std::invoke(m_handler, m_call, m_reply);
m_responder.Finish(m_reply, grpc::Status::OK, this);
m_status = Status::Finish;
return;
}
case Status::Finish:
m_self.reset();
return;
default:
return;
}
}
#endif