Viam C++ SDK current
Loading...
Searching...
No Matches
server.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <viam/sdk/common/grpc_fwd.hpp>
7#include <viam/sdk/resource/resource.hpp>
8#include <viam/sdk/resource/resource_api.hpp>
9#include <viam/sdk/resource/resource_server_base.hpp>
10
11namespace grpc {
12
13class Service;
14
15} // namespace grpc
16
17namespace viam {
18
19// needed for later `friend` declaration.
20namespace sdktests {
21class TestServer;
22}
23
24namespace sdk {
25
28class Server {
29 public:
30 Server();
31 ~Server();
32
36 void start();
37
41 void register_service(::grpc::Service* service);
42
46 std::shared_ptr<ResourceServer> lookup_resource_server(const API& api);
47
51 void add_resource(std::shared_ptr<Resource> resource);
52
57 void add_listening_port(const std::string& address,
58 std::shared_ptr<GrpcServerCredentials> creds = nullptr);
59
61 void wait();
62
64 void shutdown();
65
66 // friend declaration to allow TestServer to access the private server_ field.
67 friend class ::viam::sdktests::TestServer;
68
69 private:
70 std::unordered_map<API, std::shared_ptr<ResourceServer>> managed_servers_;
71 std::unique_ptr<GrpcServerBuilder> builder_;
72 std::unique_ptr<GrpcServer> server_;
73};
74
75} // namespace sdk
76} // namespace viam
Definition resource_api.hpp:21
Defines gRPC Server functionality.
Definition server.hpp:28
void register_service(::grpc::Service *service)
Registers a gRPC service.
void add_listening_port(const std::string &address, std::shared_ptr< GrpcServerCredentials > creds=nullptr)
Adds a listening port to the server.
std::shared_ptr< ResourceServer > lookup_resource_server(const API &api)
Returns reference to managed resource server.
void start()
Starts the grpc server. Can only be called once.
void wait()
waits on server close, only returning when the server is closed.
void add_resource(std::shared_ptr< Resource > resource)
Adds a specific managed resource to the associated resource server.
void shutdown()
Shutdown the gRPC server.