diff --git a/src/viam/sdk/common/grpc_client_fwd.hpp.in b/src/viam/sdk/common/grpc_client_fwd.hpp.in index e6ba5799f..a855586df 100644 --- a/src/viam/sdk/common/grpc_client_fwd.hpp.in +++ b/src/viam/sdk/common/grpc_client_fwd.hpp.in @@ -9,6 +9,8 @@ namespace grpc { +class Channel; + class ClientContext; template @@ -19,6 +21,8 @@ class ClientReaderInterface; namespace viam { namespace sdk { +using GrpcChannel = ::grpc::Channel; + using GrpcClientContext = ::grpc::ClientContext; template @@ -34,6 +38,8 @@ using GrpcClientReaderInterface = ::grpc::ClientReaderInterface; namespace grpc_impl { +class Channel; + class ClientContext; template @@ -44,6 +50,8 @@ class ClientReaderInterface; namespace viam { namespace sdk { +using GrpcChannel = ::grpc_impl::Channel; + using GrpcClientContext = ::grpc_impl::ClientContext; template diff --git a/src/viam/sdk/module/module.hpp b/src/viam/sdk/module/module.hpp index 18c7a0b82..cdbe48f04 100644 --- a/src/viam/sdk/module/module.hpp +++ b/src/viam/sdk/module/module.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -18,14 +19,14 @@ class Module { bool ready() const; const HandlerMap_& handles() const; HandlerMap_& mutable_handles(); - const std::shared_ptr& channel() const; + const std::shared_ptr& channel() const; private: std::string name_; std::string addr_; bool ready_; HandlerMap_ handles_; - std::shared_ptr channel_; + std::shared_ptr channel_; }; } // namespace sdk diff --git a/src/viam/sdk/registry/registry.cpp b/src/viam/sdk/registry/registry.cpp index 5e99cb6f8..57e857f00 100644 --- a/src/viam/sdk/registry/registry.cpp +++ b/src/viam/sdk/registry/registry.cpp @@ -55,9 +55,32 @@ namespace viam { namespace sdk { +ResourceServerRegistration::ResourceServerRegistration( + const google::protobuf::ServiceDescriptor* service_descriptor) + : service_descriptor_(service_descriptor) {} + ResourceServerRegistration::~ResourceServerRegistration() = default; ResourceClientRegistration::~ResourceClientRegistration() = default; +ModelRegistration::ModelRegistration( + API api, + Model model, + std::function(Dependencies, ResourceConfig)> constructor) + : construct_resource(std::move(constructor)), + validate(default_validator), + model_(std::move(model)), + api_(std::move(api)) {} + +ModelRegistration::ModelRegistration( + API api, + Model model, + std::function(Dependencies, ResourceConfig)> constructor, + std::function(ResourceConfig)> validator) + : construct_resource(std::move(constructor)), + validate(std::move(validator)), + model_(std::move(model)), + api_(std::move(api)) {} + const API& ModelRegistration::api() const { return api_; }; diff --git a/src/viam/sdk/registry/registry.hpp b/src/viam/sdk/registry/registry.hpp index 144c22a71..291ef11ef 100644 --- a/src/viam/sdk/registry/registry.hpp +++ b/src/viam/sdk/registry/registry.hpp @@ -7,10 +7,10 @@ #include #include -#include #include #include +#include #include #include #include @@ -24,6 +24,8 @@ namespace sdk { // TODO(RSDK-6617): one class per header class ResourceServerRegistration { public: + ResourceServerRegistration(const google::protobuf::ServiceDescriptor* service_descriptor); + virtual ~ResourceServerRegistration(); /// @brief Create a resource's gRPC server. @@ -36,9 +38,6 @@ class ResourceServerRegistration { /// @brief Returns a reference to the `ResourceServerRegistration`'s service descriptor. const google::protobuf::ServiceDescriptor* service_descriptor() const; - ResourceServerRegistration(const google::protobuf::ServiceDescriptor* service_descriptor) - : service_descriptor_(service_descriptor){}; - private: const google::protobuf::ServiceDescriptor* service_descriptor_; }; @@ -47,6 +46,8 @@ class ResourceServerRegistration { /// @brief Defines registered `Resource` client creation functionality. class ResourceClientRegistration { public: + ResourceClientRegistration() = default; + virtual ~ResourceClientRegistration(); /// @brief Create gRPC client to a resource. @@ -54,9 +55,7 @@ class ResourceClientRegistration { /// @param channel A channel connected to the client. /// @return A `shared_ptr` to the resource client. virtual std::shared_ptr create_rpc_client( - std::string name, std::shared_ptr channel) const = 0; - - ResourceClientRegistration() = default; + std::string name, std::shared_ptr channel) const = 0; }; // TODO(RSDK-6616): instead of std::functions, consider making these functions @@ -68,21 +67,13 @@ class ModelRegistration { ModelRegistration( API api, Model model, - std::function(Dependencies, ResourceConfig)> constructor) - : construct_resource(std::move(constructor)), - validate(default_validator), - model_(std::move(model)), - api_(std::move(api)){}; + std::function(Dependencies, ResourceConfig)> constructor); ModelRegistration( API api, Model model, std::function(Dependencies, ResourceConfig)> constructor, - std::function(ResourceConfig)> validator) - : construct_resource(std::move(constructor)), - validate(std::move(validator)), - model_(std::move(model)), - api_(std::move(api)){}; + std::function(ResourceConfig)> validator); const API& api() const; const Model& model() const; @@ -134,7 +125,7 @@ class Registry { using ResourceClientRegistration::ResourceClientRegistration; std::shared_ptr create_rpc_client( - std::string name, std::shared_ptr chan) const override { + std::string name, std::shared_ptr chan) const override { return std::make_shared(std::move(name), std::move(chan)); } }; diff --git a/src/viam/sdk/robot/client.hpp b/src/viam/sdk/robot/client.hpp index e5c16a51f..8ba74f281 100644 --- a/src/viam/sdk/robot/client.hpp +++ b/src/viam/sdk/robot/client.hpp @@ -6,8 +6,7 @@ #include #include -#include - +#include #include #include #include @@ -20,8 +19,6 @@ namespace viam { namespace sdk { -using grpc::Channel; - /// @defgroup Robot Classes related to a Robot representation. /// @class RobotClient client.hpp "robot/client.hpp" @@ -152,7 +149,7 @@ class RobotClient { std::vector> threads_; std::atomic should_refresh_; unsigned int refresh_interval_; - std::shared_ptr channel_; + std::shared_ptr channel_; std::shared_ptr viam_channel_; bool should_close_channel_; struct impl; diff --git a/src/viam/sdk/rpc/dial.hpp b/src/viam/sdk/rpc/dial.hpp index 86fbf582a..1419b6193 100644 --- a/src/viam/sdk/rpc/dial.hpp +++ b/src/viam/sdk/rpc/dial.hpp @@ -1,10 +1,12 @@ #pragma once +#include #include #include #include -#include + +#include namespace viam { namespace sdk { @@ -13,14 +15,14 @@ class DialOptions; class ViamChannel { public: void close(); - ViamChannel(std::shared_ptr channel, const char* path, void* runtime); + ViamChannel(std::shared_ptr channel, const char* path, void* runtime); static std::shared_ptr dial(const char* uri, const boost::optional& options); - const std::shared_ptr& channel() const; + const std::shared_ptr& channel() const; private: - std::shared_ptr channel_; + std::shared_ptr channel_; const char* path_; bool closed_; void* rust_runtime_;