Viam C++ SDK current
Loading...
Searching...
No Matches
server.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <chrono>
7#include <optional>
8
9#include <viam/sdk/common/grpc_fwd.hpp>
10#include <viam/sdk/resource/resource.hpp>
11#include <viam/sdk/resource/resource_api.hpp>
12#include <viam/sdk/resource/resource_server_base.hpp>
13
14namespace grpc {
15
16class Service;
17
18} // namespace grpc
19
20namespace viam {
21
22// needed for later `friend` declaration.
23namespace sdktests {
24class TestServer;
25}
26
27namespace sdk {
28
31class Server {
32 public:
33 Server();
34 ~Server();
35
39 void start();
40
44 void register_service(::grpc::Service* service);
45
49 std::shared_ptr<ResourceServer> lookup_resource_server(const API& api);
50
54 void add_resource(std::shared_ptr<Resource> resource);
55
61 void add_resource(std::shared_ptr<Resource> resource,
62 std::optional<std::chrono::system_clock::time_point> deadline);
63
68 void add_listening_port(const std::string& address,
69 std::shared_ptr<GrpcServerCredentials> creds = nullptr);
70
72 void wait();
73
75 void shutdown();
76
77 // friend declaration to allow TestServer to access the private server_ field.
78 friend class ::viam::sdktests::TestServer;
79
80 private:
81 std::unordered_map<API, std::shared_ptr<ResourceServer>> managed_servers_;
82 std::unique_ptr<GrpcServerBuilder> builder_;
83 std::unique_ptr<GrpcServer> server_;
84};
85
86} // namespace sdk
87} // namespace viam
Definition resource_api.hpp:21
Defines gRPC Server functionality.
Definition server.hpp:31
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 add_resource(std::shared_ptr< Resource > resource, std::optional< std::chrono::system_clock::time_point > deadline)
Adds a specific managed resource to the associated resource server.
void shutdown()
Shutdown the gRPC server.