-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrpcServer.cpp
39 lines (32 loc) · 921 Bytes
/
GrpcServer.cpp
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
#include "GrpcServer.hpp"
#include <iostream>
GrpcServer::GrpcServer()
: m_builder{},
m_completionQueue{m_builder.AddCompletionQueue()},
m_server{} {}
GrpcServer::~GrpcServer() {
if (m_server) {
m_server->Shutdown();
}
m_completionQueue->Shutdown();
}
void GrpcServer::addListeningPort(
const std::string &address,
const std::shared_ptr<grpc::ServerCredentials> &credentials) {
m_builder.AddListeningPort(address, credentials);
}
void GrpcServer::registerService(grpc::Service *service) {
m_builder.RegisterService(service);
}
void GrpcServer::buildAndStart() { m_server = m_builder.BuildAndStart(); }
void GrpcServer::startHandlingCalls() {
void *tag;
bool ok;
while (true) {
m_completionQueue->Next(&tag, &ok);
if (!ok) {
std::cerr << "Error found while handling call" << std::endl;
}
static_cast<GrpcServerCallDataBase *>(tag)->proceed();
}
}