AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
grpcServer.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2026 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-rest-grpc-export.hpp"
23
24#include <map>
25#include <memory>
26#include <string>
27#include <string_view>
28
29#include <grpcpp/security/server_credentials.h>
30#include <grpcpp/server.h>
31#include <grpcpp/server_builder.h>
32
33#include "rest/rpcService.hpp"
34
35namespace anch::rest {
36
50 class ANCH_REST_GRPC_EXPORT GrpcServer {
51
53 class Dispatcher;
54
55 // Attributes +
56 private:
58 grpc::ServerBuilder _builder;
59
61 std::map<std::string, const anch::rest::RpcService*, std::less<>> _services;
62
64 std::unique_ptr<Dispatcher> _dispatcher;
65
67 std::unique_ptr<grpc::Server> _server;
68
70 int _port;
71 // Attributes -
72
73 // Constructors +
74 public:
79
81 GrpcServer(const GrpcServer&) = delete;
82 // Constructors -
83
84 // Destructor +
85 public:
89 virtual ~GrpcServer();
90 // Destructor -
91
92 // Methods +
93 public:
104
113 GrpcServer& listen(const std::string& address,
114 std::shared_ptr<grpc::ServerCredentials> credentials = grpc::InsecureServerCredentials());
115
121 grpc::ServerBuilder& builder() noexcept;
122
130 int start();
131
135 void wait();
136
140 void shutdown();
141
143 GrpcServer& operator=(const GrpcServer&) = delete;
144 // Methods -
145
146 // Accessors +
147 public:
153 int getPort() const noexcept;
154 // Accessors -
155
156 };
157
158}
int getPort() const noexcept
grpc::ServerBuilder & builder() noexcept
GrpcServer(const GrpcServer &)=delete
GrpcServer & addService(const anch::rest::RpcService &service)
GrpcServer & listen(const std::string &address, std::shared_ptr< grpc::ServerCredentials > credentials=grpc::InsecureServerCredentials())
Definition rpcService.hpp:194
AnCH REST library namespace.
Definition auth.hpp:29