diff --git a/CMakeLists.txt b/CMakeLists.txt index b48d3fc25..64995b639 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,7 +431,7 @@ if ((VIAMCPPSDK_GRPCXX_VERSION VERSION_GREATER 1.51.1) AND (VIAMCPPSDK_PROTOC_VE endif() if (VIAMCPPSDK_GRPCXX_VERSION VERSION_LESS 1.32.0) - set(VIAMCPPSDK_GRPCXX_LEGACY_CLIENT_FWD 1) + set(VIAMCPPSDK_GRPCXX_LEGACY_FWD 1) endif() include(FetchContent) diff --git a/src/viam/sdk/CMakeLists.txt b/src/viam/sdk/CMakeLists.txt index fe5982e1f..ad2bfe793 100644 --- a/src/viam/sdk/CMakeLists.txt +++ b/src/viam/sdk/CMakeLists.txt @@ -30,7 +30,7 @@ message(WARNING "api proto label is ${VIAMCPPSDK_API_PROTO_LABEL}") configure_file(common/private/version_metadata.hpp.in common/private/version_metadata.hpp @ONLY) # Configure the grpc client forward declarations file -configure_file(common/grpc_client_fwd.hpp.in common/grpc_client_fwd.hpp) +configure_file(common/grpc_fwd.hpp.in common/grpc_fwd.hpp) # Set compile and link options based on arguments if (VIAMCPPSDK_USE_WALL_WERROR) @@ -192,7 +192,7 @@ target_sources(viamsdk ../../viam/sdk/spatialmath/geometry.hpp ../../viam/sdk/spatialmath/orientation.hpp ../../viam/sdk/spatialmath/orientation_types.hpp - ${CMAKE_CURRENT_BINARY_DIR}/../../viam/sdk/common/grpc_client_fwd.hpp + ${CMAKE_CURRENT_BINARY_DIR}/../../viam/sdk/common/grpc_fwd.hpp ) set_target_properties( diff --git a/src/viam/sdk/common/client_helper.hpp b/src/viam/sdk/common/client_helper.hpp index 27171c9e0..f4fb5406a 100644 --- a/src/viam/sdk/common/client_helper.hpp +++ b/src/viam/sdk/common/client_helper.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/src/viam/sdk/common/grpc_client_fwd.hpp.in b/src/viam/sdk/common/grpc_client_fwd.hpp.in deleted file mode 100644 index a855586df..000000000 --- a/src/viam/sdk/common/grpc_client_fwd.hpp.in +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#cmakedefine VIAMCPPSDK_GRPCXX_LEGACY_CLIENT_FWD - -#ifndef VIAMCPPSDK_GRPCXX_LEGACY_CLIENT_FWD - -// Forward declaration file for grpc ClientContext and ClientReaderInterface. -// This file provides includes for recent (>= 1.32.0) versions of grpc. - -namespace grpc { - -class Channel; - -class ClientContext; - -template -class ClientReaderInterface; - -} // namespace grpc - -namespace viam { -namespace sdk { - -using GrpcChannel = ::grpc::Channel; - -using GrpcClientContext = ::grpc::ClientContext; - -template -using GrpcClientReaderInterface = ::grpc::ClientReaderInterface; - -} // namespace sdk -} // namespace viam - -#else - -// Forward declaration file for grpc ClientContext and ClientReaderInterface. -// This file provides includes for the oldest supported versions of grpc (< 1.32.0). - -namespace grpc_impl { - -class Channel; - -class ClientContext; - -template -class ClientReaderInterface; - -} // namespace grpc_impl - -namespace viam { -namespace sdk { - -using GrpcChannel = ::grpc_impl::Channel; - -using GrpcClientContext = ::grpc_impl::ClientContext; - -template -using GrpcClientReaderInterface = ::grpc_impl::ClientReaderInterface; - -} // namespace sdk -} // namespace viam - -#endif diff --git a/src/viam/sdk/common/grpc_fwd.hpp.in b/src/viam/sdk/common/grpc_fwd.hpp.in new file mode 100644 index 000000000..39bafd3ac --- /dev/null +++ b/src/viam/sdk/common/grpc_fwd.hpp.in @@ -0,0 +1,89 @@ +#pragma once + +#cmakedefine VIAMCPPSDK_GRPCXX_LEGACY_FWD + +// Forward declaration file grpc client and server types. +// This file provides includes for recent (>= 1.32.0) versions of grpc or older +// versions, depending on if `VIAMCPPSDK_GRPCXX_LEGACY_FWD` is defined. +// The default behavior is for the variable to be undefined, providing the behavior for recent +// versions. If you are experiencing compilation errors in an installed version of the SDK it may be +// due to a mismatch with the configured version of this header and the grpc version found by the +// compiler. You may wish to comment/uncomment the define above as needed, or add the definition +// with `-D` to the compiler. +#ifndef VIAMCPPSDK_GRPCXX_LEGACY_FWD + +namespace grpc { + +class Channel; + +class ClientContext; + +template +class ClientReaderInterface; + +class Server; + +class ServerBuilder; + +class ServerCredentials; + +} // namespace grpc + +namespace viam { +namespace sdk { + +using GrpcChannel = ::grpc::Channel; + +using GrpcClientContext = ::grpc::ClientContext; + +template +using GrpcClientReaderInterface = ::grpc::ClientReaderInterface; + +using GrpcServer = ::grpc::Server; + +using GrpcServerBuilder = ::grpc::ServerBuilder; + +using GrpcServerCredentials = ::grpc::ServerCredentials; + +} // namespace sdk +} // namespace viam + +#else + +namespace grpc_impl { + +class Channel; + +class ClientContext; + +template +class ClientReaderInterface; + +class Server; + +class ServerBuilder; + +class ServerCredentials; + +} // namespace grpc_impl + +namespace viam { +namespace sdk { + +using GrpcChannel = ::grpc_impl::Channel; + +using GrpcClientContext = ::grpc_impl::ClientContext; + +template +using GrpcClientReaderInterface = ::grpc_impl::ClientReaderInterface; + +using GrpcServer = ::grpc_impl::Server; + +using GrpcServerBuilder = ::grpc_impl::ServerBuilder; + +using GrpcServerCredentials = ::grpc_impl::ServerCredentials; + +} // namespace sdk +} // namespace viam + +#endif diff --git a/src/viam/sdk/module/module.hpp b/src/viam/sdk/module/module.hpp index cdbe48f04..661da0f5f 100644 --- a/src/viam/sdk/module/module.hpp +++ b/src/viam/sdk/module/module.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include diff --git a/src/viam/sdk/registry/registry.hpp b/src/viam/sdk/registry/registry.hpp index 291ef11ef..b00d98833 100644 --- a/src/viam/sdk/registry/registry.hpp +++ b/src/viam/sdk/registry/registry.hpp @@ -5,12 +5,7 @@ #include -#include -#include -#include -#include - -#include +#include #include #include #include @@ -18,13 +13,21 @@ #include #include +namespace google { +namespace protobuf { + +class ServiceDescriptor; + +} +} // namespace google + namespace viam { namespace sdk { // TODO(RSDK-6617): one class per header class ResourceServerRegistration { public: - ResourceServerRegistration(const google::protobuf::ServiceDescriptor* service_descriptor); + ResourceServerRegistration(const ::google::protobuf::ServiceDescriptor* service_descriptor); virtual ~ResourceServerRegistration(); @@ -36,10 +39,10 @@ class ResourceServerRegistration { std::shared_ptr manager, Server& server) const = 0; /// @brief Returns a reference to the `ResourceServerRegistration`'s service descriptor. - const google::protobuf::ServiceDescriptor* service_descriptor() const; + const ::google::protobuf::ServiceDescriptor* service_descriptor() const; private: - const google::protobuf::ServiceDescriptor* service_descriptor_; + const ::google::protobuf::ServiceDescriptor* service_descriptor_; }; /// @class ResourceClientRegistration registry.hpp "registry/registry.hpp" diff --git a/src/viam/sdk/robot/client.hpp b/src/viam/sdk/robot/client.hpp index 8ba74f281..a86b4361a 100644 --- a/src/viam/sdk/robot/client.hpp +++ b/src/viam/sdk/robot/client.hpp @@ -3,10 +3,11 @@ /// @brief gRPC client implementation for a `robot`. #pragma once +#include #include #include -#include +#include #include #include #include diff --git a/src/viam/sdk/rpc/dial.hpp b/src/viam/sdk/rpc/dial.hpp index 1419b6193..a8e2bf07a 100644 --- a/src/viam/sdk/rpc/dial.hpp +++ b/src/viam/sdk/rpc/dial.hpp @@ -6,7 +6,7 @@ #include -#include +#include namespace viam { namespace sdk { diff --git a/src/viam/sdk/rpc/server.cpp b/src/viam/sdk/rpc/server.cpp index 94bb72542..408f23bf6 100644 --- a/src/viam/sdk/rpc/server.cpp +++ b/src/viam/sdk/rpc/server.cpp @@ -3,7 +3,10 @@ #include #include + +#include #include +#include #include #include diff --git a/src/viam/sdk/rpc/server.hpp b/src/viam/sdk/rpc/server.hpp index 6d9c8ba7b..e735a6351 100644 --- a/src/viam/sdk/rpc/server.hpp +++ b/src/viam/sdk/rpc/server.hpp @@ -3,14 +3,17 @@ /// @brief Defines the `Server` class. #pragma once -#include -#include -#include - +#include #include #include #include +namespace grpc { + +class Service; + +} // namespace grpc + namespace viam { // needed for later `friend` declaration. @@ -35,7 +38,7 @@ class Server { /// @brief Registers a gRPC service. /// @param service The gRPC service to be registered. /// @throws `Exception` if called after the server has been `start`ed. - void register_service(grpc::Service* service); + void register_service(::grpc::Service* service); /// @brief Returns reference to managed resource server. /// @param api The api of the managed resource server. @@ -52,7 +55,7 @@ class Server { /// @param creds The server credentials; defaults to a insecure server credentials. /// @throws `Exception` if called after the server has been `start`ed. void add_listening_port(const std::string& address, - std::shared_ptr creds = nullptr); + std::shared_ptr creds = nullptr); /// @brief waits on server close, only returning when the server is closed. void wait(); @@ -65,8 +68,8 @@ class Server { private: std::unordered_map> managed_servers_; - std::unique_ptr builder_; - std::unique_ptr server_; + std::unique_ptr builder_; + std::unique_ptr server_; }; } // namespace sdk