Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refer to grpc::Channel by forward decl #342

Merged
merged 34 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6bd64aa
update response metadata and timestamp/duration
lia-viam Dec 11, 2024
c245126
Merge branch 'main' of github.com:viamrobotics/viam-cpp-sdk into misc…
lia-viam Dec 11, 2024
7c76e43
insulate grpc client context
lia-viam Dec 11, 2024
0729e87
clean up resource_manager includes
lia-viam Dec 11, 2024
73aa00d
name to/from
lia-viam Dec 12, 2024
75d6d3a
class to struct
lia-viam Dec 13, 2024
1d26302
insulate resource and utils
lia-viam Dec 13, 2024
2fa362f
symmetric ws
lia-viam Dec 13, 2024
924bd86
remove spurious ret
lia-viam Dec 13, 2024
ecf734b
formatting and defaulted ctors
lia-viam Dec 13, 2024
c768df8
de-insulate grpc client context
lia-viam Dec 16, 2024
6a2710f
Merge branch 'main' into misc-proto-update
lia-viam Dec 16, 2024
b18f477
put grpc includes back
lia-viam Dec 17, 2024
a20fb42
generate header for grpc client fwd
lia-viam Dec 17, 2024
c223260
use add
lia-viam Dec 17, 2024
557eefe
Merge branch 'misc-proto-update' into client-fwd
lia-viam Dec 17, 2024
6978fdf
use explicit ctor/assign
lia-viam Dec 17, 2024
f59997f
initialize unique_ptr
lia-viam Dec 17, 2024
7d26e94
Merge branch 'misc-proto-update' into client-fwd
lia-viam Dec 17, 2024
772efcb
client context out of utils
lia-viam Dec 17, 2024
fc38fff
commit configure input file
lia-viam Dec 18, 2024
89bfa8b
refer to grpc::Channel by forward decl
lia-viam Dec 18, 2024
03104a3
de-inline modelregistration ctor
lia-viam Dec 18, 2024
de2c1ef
Merge branch 'main' of github.com:viamrobotics/viam-cpp-sdk into clie…
lia-viam Dec 18, 2024
0262a08
use the typedef
lia-viam Dec 18, 2024
fee421d
Merge branch 'client-fwd' into channel-fwd
lia-viam Dec 18, 2024
eb5d242
add a channel fwd
lia-viam Dec 18, 2024
77f060c
use client reader fwd
lia-viam Dec 18, 2024
e6a493e
Merge branch 'client-fwd' into channel-fwd
lia-viam Dec 18, 2024
55e0717
use grpcchannel alias in public headers
lia-viam Dec 18, 2024
16a7c0d
add missing chrono include
lia-viam Dec 18, 2024
66b3b30
fix installation of generated file
lia-viam Dec 23, 2024
a11987e
Merge branch 'client-fwd' into channel-fwd
lia-viam Dec 23, 2024
db3e326
Merge branch 'main' into channel-fwd
lia-viam Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/viam/sdk/common/grpc_client_fwd.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace grpc {

class Channel;

class ClientContext;

template <typename>
Expand All @@ -19,6 +21,8 @@ class ClientReaderInterface;
namespace viam {
namespace sdk {

using GrpcChannel = ::grpc::Channel;

using GrpcClientContext = ::grpc::ClientContext;

template <typename T>
Expand All @@ -34,6 +38,8 @@ using GrpcClientReaderInterface = ::grpc::ClientReaderInterface<T>;

namespace grpc_impl {

class Channel;

class ClientContext;

template <typename>
Expand All @@ -44,6 +50,8 @@ class ClientReaderInterface;
namespace viam {
namespace sdk {

using GrpcChannel = ::grpc_impl::Channel;

using GrpcClientContext = ::grpc_impl::ClientContext;

template <typename T>
Expand Down
5 changes: 3 additions & 2 deletions src/viam/sdk/module/module.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <viam/sdk/common/grpc_client_fwd.hpp>
#include <viam/sdk/module/handler_map.hpp>
#include <viam/sdk/resource/resource.hpp>
#include <viam/sdk/resource/resource_manager.hpp>
Expand All @@ -18,14 +19,14 @@ class Module {
bool ready() const;
const HandlerMap_& handles() const;
HandlerMap_& mutable_handles();
const std::shared_ptr<grpc::Channel>& channel() const;
const std::shared_ptr<GrpcChannel>& channel() const;

private:
std::string name_;
std::string addr_;
bool ready_;
HandlerMap_ handles_;
std::shared_ptr<grpc::Channel> channel_;
std::shared_ptr<GrpcChannel> channel_;
};

} // namespace sdk
Expand Down
23 changes: 23 additions & 0 deletions src/viam/sdk/registry/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_ptr<Resource>(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<std::shared_ptr<Resource>(Dependencies, ResourceConfig)> constructor,
std::function<std::vector<std::string>(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_;
};
Expand Down
27 changes: 9 additions & 18 deletions src/viam/sdk/registry/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>
#include <grpcpp/channel.h>
#include <grpcpp/impl/service_type.h>
#include <grpcpp/server.h>

#include <viam/sdk/common/grpc_client_fwd.hpp>
#include <viam/sdk/config/resource.hpp>
#include <viam/sdk/resource/resource.hpp>
#include <viam/sdk/resource/resource_api.hpp>
Expand All @@ -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.
Expand All @@ -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_;
};
Expand All @@ -47,16 +46,16 @@ class ResourceServerRegistration {
/// @brief Defines registered `Resource` client creation functionality.
class ResourceClientRegistration {
public:
ResourceClientRegistration() = default;

virtual ~ResourceClientRegistration();

/// @brief Create gRPC client to a resource.
/// @param name The name of the resource.
/// @param channel A channel connected to the client.
/// @return A `shared_ptr` to the resource client.
virtual std::shared_ptr<Resource> create_rpc_client(
std::string name, std::shared_ptr<grpc::Channel> channel) const = 0;

ResourceClientRegistration() = default;
std::string name, std::shared_ptr<GrpcChannel> channel) const = 0;
};

// TODO(RSDK-6616): instead of std::functions, consider making these functions
Expand All @@ -68,21 +67,13 @@ class ModelRegistration {
ModelRegistration(
API api,
Model model,
std::function<std::shared_ptr<Resource>(Dependencies, ResourceConfig)> constructor)
: construct_resource(std::move(constructor)),
validate(default_validator),
model_(std::move(model)),
api_(std::move(api)){};
std::function<std::shared_ptr<Resource>(Dependencies, ResourceConfig)> constructor);

ModelRegistration(
API api,
Model model,
std::function<std::shared_ptr<Resource>(Dependencies, ResourceConfig)> constructor,
std::function<std::vector<std::string>(ResourceConfig)> validator)
: construct_resource(std::move(constructor)),
validate(std::move(validator)),
model_(std::move(model)),
api_(std::move(api)){};
std::function<std::vector<std::string>(ResourceConfig)> validator);

const API& api() const;
const Model& model() const;
Expand Down Expand Up @@ -134,7 +125,7 @@ class Registry {
using ResourceClientRegistration::ResourceClientRegistration;

std::shared_ptr<Resource> create_rpc_client(
std::string name, std::shared_ptr<grpc::Channel> chan) const override {
std::string name, std::shared_ptr<GrpcChannel> chan) const override {
return std::make_shared<ResourceClientT>(std::move(name), std::move(chan));
}
};
Expand Down
7 changes: 2 additions & 5 deletions src/viam/sdk/robot/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <string>
#include <thread>

#include <grpcpp/channel.h>

#include <viam/sdk/common/grpc_client_fwd.hpp>
#include <viam/sdk/common/pose.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/common/world_state.hpp>
Expand All @@ -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"
Expand Down Expand Up @@ -152,7 +149,7 @@ class RobotClient {
std::vector<std::shared_ptr<std::thread>> threads_;
std::atomic<bool> should_refresh_;
unsigned int refresh_interval_;
std::shared_ptr<Channel> channel_;
std::shared_ptr<GrpcChannel> channel_;
std::shared_ptr<ViamChannel> viam_channel_;
bool should_close_channel_;
struct impl;
Expand Down
10 changes: 6 additions & 4 deletions src/viam/sdk/rpc/dial.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#include <chrono>
#include <memory>
#include <string>

#include <boost/optional.hpp>
#include <grpcpp/channel.h>

#include <viam/sdk/common/grpc_client_fwd.hpp>

namespace viam {
namespace sdk {
Expand All @@ -13,14 +15,14 @@ class DialOptions;
class ViamChannel {
public:
void close();
ViamChannel(std::shared_ptr<grpc::Channel> channel, const char* path, void* runtime);
ViamChannel(std::shared_ptr<GrpcChannel> channel, const char* path, void* runtime);
static std::shared_ptr<ViamChannel> dial(const char* uri,
const boost::optional<DialOptions>& options);

const std::shared_ptr<grpc::Channel>& channel() const;
const std::shared_ptr<GrpcChannel>& channel() const;

private:
std::shared_ptr<grpc::Channel> channel_;
std::shared_ptr<GrpcChannel> channel_;
const char* path_;
bool closed_;
void* rust_runtime_;
Expand Down
Loading