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
8#include <viam/sdk/common/grpc_fwd.hpp>
9#include <viam/sdk/resource/resource.hpp>
10#include <viam/sdk/resource/resource_api.hpp>
11#include <viam/sdk/resource/resource_server_base.hpp>
12
13namespace grpc {
14
15class Service;
16
17} // namespace grpc
18
19namespace viam {
20
21// needed for later `friend` declaration.
22namespace sdktests {
23class TestServer;
24}
25
26namespace sdk {
27
30class Server {
31 public:
32 Server();
33 ~Server();
34
38 void start();
39
43 void register_service(::grpc::Service* service);
44
48 std::shared_ptr<ResourceServer> lookup_resource_server(const API& api);
49
53 void add_resource(std::shared_ptr<Resource> resource);
54
60 void add_resource(std::shared_ptr<Resource> resource,
61 boost::optional<std::chrono::system_clock::time_point> deadline);
62
67 void add_listening_port(const std::string& address,
68 std::shared_ptr<GrpcServerCredentials> creds = nullptr);
69
71 void wait();
72
74 void shutdown();
75
76 // friend declaration to allow TestServer to access the private server_ field.
77 friend class ::viam::sdktests::TestServer;
78
79 private:
80 std::unordered_map<API, std::shared_ptr<ResourceServer>> managed_servers_;
81 std::unique_ptr<GrpcServerBuilder> builder_;
82 std::unique_ptr<GrpcServer> server_;
83};
84
85} // namespace sdk
86} // namespace viam
Definition resource_api.hpp:21
Defines gRPC Server functionality.
Definition server.hpp:30
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, boost::optional< std::chrono::system_clock::time_point > deadline)
Adds a specific managed resource to the associated resource server.
void shutdown()
Shutdown the gRPC server.