-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.h
More file actions
56 lines (45 loc) · 1.39 KB
/
server.h
File metadata and controls
56 lines (45 loc) · 1.39 KB
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
//
// Created by Dan Cohen on 11/11/2024.
//
#ifndef GRPC_EXAMPLE_SERVER_H
#define GRPC_EXAMPLE_SERVER_H
#include <atomic>
#include <chrono>
#include <thread>
#include <memory>
#include "example/v1/example.grpc.pb.h"
#include "example/v1/example.pb.h"
#include "handlers.h"
#include "memory_pool.h"
using namespace grpc;
using namespace example::v1;
using namespace google::protobuf;
using std::thread;
using std::unique_ptr;
using std::chrono::system_clock;
class server {
public:
static server &get_server() {
static server _server;
return _server;
}
virtual ~server();
bool init_server();
void close_server();
private:
server() : _did_init(false), _server_thread(nullptr), _service(nullptr) {}
server(const server &other) = delete;
bool is_server_shutting_down() {
return _shutting_down.load();
}
void init_rpc_handlers();
void handle_requests_queue();
std::unique_ptr<thread> _server_thread;
std::unique_ptr<grpc::ServerCompletionQueue> _completion_queue;
std::shared_ptr<ExampleService::AsyncService> _service;
bool _did_init;
std::unique_ptr<Server> _server;
std::atomic_bool _shutting_down;
mem_pool _rpc_pool;
};
#endif //GRPC_EXAMPLE_SERVER_H