Viam C++ SDK current
Loading...
Searching...
No Matches
service.hpp
1#pragma once
2
3#include <signal.h>
4
5#include <viam/api/component/generic/v1/generic.grpc.pb.h>
6#include <viam/api/module/v1/module.grpc.pb.h>
7
8#include <viam/sdk/module/module.hpp>
9#include <viam/sdk/module/signal_manager.hpp>
11#include <viam/sdk/resource/resource.hpp>
13
14namespace viam {
15namespace sdk {
16
18
24class ModuleService : viam::module::v1::ModuleService::Service {
25 public:
28 explicit ModuleService(std::string addr);
29
36 explicit ModuleService(int argc,
37 char** argv,
38 const std::vector<std::shared_ptr<ModelRegistration>>& registrations);
40
43 void serve();
44
51
52 private:
53 ::grpc::Status AddResource(::grpc::ServerContext* context,
54 const ::viam::module::v1::AddResourceRequest* request,
55 ::viam::module::v1::AddResourceResponse* response) override;
56
57 ::grpc::Status ReconfigureResource(
58 ::grpc::ServerContext* context,
59 const ::viam::module::v1::ReconfigureResourceRequest* request,
60 ::viam::module::v1::ReconfigureResourceResponse* response) override;
61
62 ::grpc::Status RemoveResource(::grpc::ServerContext* context,
63 const ::viam::module::v1::RemoveResourceRequest* request,
64 ::viam::module::v1::RemoveResourceResponse* response) override;
65
66 ::grpc::Status Ready(::grpc::ServerContext* context,
67 const ::viam::module::v1::ReadyRequest* request,
68 ::viam::module::v1::ReadyResponse* response) override;
69
70 ::grpc::Status ValidateConfig(::grpc::ServerContext* context,
71 const ::viam::module::v1::ValidateConfigRequest* request,
72 ::viam::module::v1::ValidateConfigResponse* response) override;
73
74 void add_model_from_registry_inlock_(API api, Model model, const std::lock_guard<std::mutex>&);
75 Dependencies get_dependencies_(google::protobuf::RepeatedPtrField<std::string> const& proto,
76 std::string const& resource_name);
77 std::shared_ptr<Resource> get_parent_resource_(const Name& name);
78
79 std::mutex lock_;
80 std::unique_ptr<Module> module_;
81 std::shared_ptr<RobotClient> parent_;
82 std::string parent_addr_;
83 std::unique_ptr<Server> server_;
84 SignalManager signal_manager_;
85};
86
87} // namespace sdk
88} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Defines the namespace_, family, and name for a particular resource model.
Definition resource_api.hpp:117
Defines the gRPC receiving logic for a module. C++ module authors can construct a ModuleService and u...
Definition service.hpp:24
ModuleService(int argc, char **argv, const std::vector< std::shared_ptr< ModelRegistration > > &registrations)
Creates a new ModuleService. Socket path and log level will be inferred from passed in command line a...
void serve()
Starts module. serve will return when SIGINT or SIGTERM is received (this happens when the RDK shuts ...
void add_model_from_registry(API api, Model model)
Adds an API/model pair to the module; both the API and model should have already been registered....
ModuleService(std::string addr)
Creates a new ModuleService that can serve on the provided socket.
A name for specific instances of resources.
Definition resource_api.hpp:63
Defines handling logic for SIGINT and SIGTERM required by all C++ modules.
Definition signal_manager.hpp:12
Defines the resource registry and associated types.
Defines the Server class.