Skip to content

Commit 0f636c5

Browse files
authored
Miscellaneous google header insulation (#346)
1 parent 3f70b94 commit 0f636c5

File tree

11 files changed

+123
-87
lines changed

11 files changed

+123
-87
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ if ((VIAMCPPSDK_GRPCXX_VERSION VERSION_GREATER 1.51.1) AND (VIAMCPPSDK_PROTOC_VE
431431
endif()
432432

433433
if (VIAMCPPSDK_GRPCXX_VERSION VERSION_LESS 1.32.0)
434-
set(VIAMCPPSDK_GRPCXX_LEGACY_CLIENT_FWD 1)
434+
set(VIAMCPPSDK_GRPCXX_LEGACY_FWD 1)
435435
endif()
436436

437437
include(FetchContent)

src/viam/sdk/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ message(WARNING "api proto label is ${VIAMCPPSDK_API_PROTO_LABEL}")
3030
configure_file(common/private/version_metadata.hpp.in common/private/version_metadata.hpp @ONLY)
3131

3232
# Configure the grpc client forward declarations file
33-
configure_file(common/grpc_client_fwd.hpp.in common/grpc_client_fwd.hpp)
33+
configure_file(common/grpc_fwd.hpp.in common/grpc_fwd.hpp)
3434

3535
# Set compile and link options based on arguments
3636
if (VIAMCPPSDK_USE_WALL_WERROR)
@@ -192,7 +192,7 @@ target_sources(viamsdk
192192
../../viam/sdk/spatialmath/geometry.hpp
193193
../../viam/sdk/spatialmath/orientation.hpp
194194
../../viam/sdk/spatialmath/orientation_types.hpp
195-
${CMAKE_CURRENT_BINARY_DIR}/../../viam/sdk/common/grpc_client_fwd.hpp
195+
${CMAKE_CURRENT_BINARY_DIR}/../../viam/sdk/common/grpc_fwd.hpp
196196
)
197197

198198
set_target_properties(

src/viam/sdk/common/client_helper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include <viam/sdk/common/exception.hpp>
4-
#include <viam/sdk/common/grpc_client_fwd.hpp>
4+
#include <viam/sdk/common/grpc_fwd.hpp>
55
#include <viam/sdk/common/private/utils.hpp>
66
#include <viam/sdk/common/proto_value.hpp>
77

src/viam/sdk/common/grpc_client_fwd.hpp.in

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#pragma once
2+
3+
#cmakedefine VIAMCPPSDK_GRPCXX_LEGACY_FWD
4+
5+
// Forward declaration file grpc client and server types.
6+
// This file provides includes for recent (>= 1.32.0) versions of grpc or older
7+
// versions, depending on if `VIAMCPPSDK_GRPCXX_LEGACY_FWD` is defined.
8+
// The default behavior is for the variable to be undefined, providing the behavior for recent
9+
// versions. If you are experiencing compilation errors in an installed version of the SDK it may be
10+
// due to a mismatch with the configured version of this header and the grpc version found by the
11+
// compiler. You may wish to comment/uncomment the define above as needed, or add the definition
12+
// with `-D` to the compiler.
13+
#ifndef VIAMCPPSDK_GRPCXX_LEGACY_FWD
14+
15+
namespace grpc {
16+
17+
class Channel;
18+
19+
class ClientContext;
20+
21+
template <typename>
22+
class ClientReaderInterface;
23+
24+
class Server;
25+
26+
class ServerBuilder;
27+
28+
class ServerCredentials;
29+
30+
} // namespace grpc
31+
32+
namespace viam {
33+
namespace sdk {
34+
35+
using GrpcChannel = ::grpc::Channel;
36+
37+
using GrpcClientContext = ::grpc::ClientContext;
38+
39+
template <typename T>
40+
using GrpcClientReaderInterface = ::grpc::ClientReaderInterface<T>;
41+
42+
using GrpcServer = ::grpc::Server;
43+
44+
using GrpcServerBuilder = ::grpc::ServerBuilder;
45+
46+
using GrpcServerCredentials = ::grpc::ServerCredentials;
47+
48+
} // namespace sdk
49+
} // namespace viam
50+
51+
#else
52+
53+
namespace grpc_impl {
54+
55+
class Channel;
56+
57+
class ClientContext;
58+
59+
template <typename>
60+
class ClientReaderInterface;
61+
62+
class Server;
63+
64+
class ServerBuilder;
65+
66+
class ServerCredentials;
67+
68+
} // namespace grpc_impl
69+
70+
namespace viam {
71+
namespace sdk {
72+
73+
using GrpcChannel = ::grpc_impl::Channel;
74+
75+
using GrpcClientContext = ::grpc_impl::ClientContext;
76+
77+
template <typename T>
78+
using GrpcClientReaderInterface = ::grpc_impl::ClientReaderInterface<T>;
79+
80+
using GrpcServer = ::grpc_impl::Server;
81+
82+
using GrpcServerBuilder = ::grpc_impl::ServerBuilder;
83+
84+
using GrpcServerCredentials = ::grpc_impl::ServerCredentials;
85+
86+
} // namespace sdk
87+
} // namespace viam
88+
89+
#endif

src/viam/sdk/module/module.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <viam/sdk/common/grpc_client_fwd.hpp>
3+
#include <viam/sdk/common/grpc_fwd.hpp>
44
#include <viam/sdk/module/handler_map.hpp>
55
#include <viam/sdk/resource/resource.hpp>
66
#include <viam/sdk/resource/resource_manager.hpp>

src/viam/sdk/registry/registry.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@
55

66
#include <string>
77

8-
#include <google/protobuf/descriptor.h>
9-
#include <google/protobuf/message.h>
10-
#include <grpcpp/impl/service_type.h>
11-
#include <grpcpp/server.h>
12-
13-
#include <viam/sdk/common/grpc_client_fwd.hpp>
8+
#include <viam/sdk/common/grpc_fwd.hpp>
149
#include <viam/sdk/config/resource.hpp>
1510
#include <viam/sdk/resource/resource.hpp>
1611
#include <viam/sdk/resource/resource_api.hpp>
1712
#include <viam/sdk/resource/resource_manager.hpp>
1813
#include <viam/sdk/resource/resource_server_base.hpp>
1914
#include <viam/sdk/rpc/server.hpp>
2015

16+
namespace google {
17+
namespace protobuf {
18+
19+
class ServiceDescriptor;
20+
21+
}
22+
} // namespace google
23+
2124
namespace viam {
2225
namespace sdk {
2326

2427
// TODO(RSDK-6617): one class per header
2528
class ResourceServerRegistration {
2629
public:
27-
ResourceServerRegistration(const google::protobuf::ServiceDescriptor* service_descriptor);
30+
ResourceServerRegistration(const ::google::protobuf::ServiceDescriptor* service_descriptor);
2831

2932
virtual ~ResourceServerRegistration();
3033

@@ -36,10 +39,10 @@ class ResourceServerRegistration {
3639
std::shared_ptr<ResourceManager> manager, Server& server) const = 0;
3740

3841
/// @brief Returns a reference to the `ResourceServerRegistration`'s service descriptor.
39-
const google::protobuf::ServiceDescriptor* service_descriptor() const;
42+
const ::google::protobuf::ServiceDescriptor* service_descriptor() const;
4043

4144
private:
42-
const google::protobuf::ServiceDescriptor* service_descriptor_;
45+
const ::google::protobuf::ServiceDescriptor* service_descriptor_;
4346
};
4447

4548
/// @class ResourceClientRegistration registry.hpp "registry/registry.hpp"

src/viam/sdk/robot/client.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
/// @brief gRPC client implementation for a `robot`.
44
#pragma once
55

6+
#include <atomic>
67
#include <string>
78
#include <thread>
89

9-
#include <viam/sdk/common/grpc_client_fwd.hpp>
10+
#include <viam/sdk/common/grpc_fwd.hpp>
1011
#include <viam/sdk/common/pose.hpp>
1112
#include <viam/sdk/common/utils.hpp>
1213
#include <viam/sdk/common/world_state.hpp>

src/viam/sdk/rpc/dial.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <boost/optional.hpp>
88

9-
#include <viam/sdk/common/grpc_client_fwd.hpp>
9+
#include <viam/sdk/common/grpc_fwd.hpp>
1010

1111
namespace viam {
1212
namespace sdk {

src/viam/sdk/rpc/server.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#include <sstream>
44

55
#include <boost/log/trivial.hpp>
6+
7+
#include <grpcpp/impl/service_type.h>
68
#include <grpcpp/security/server_credentials.h>
9+
#include <grpcpp/server_builder.h>
710

811
#include <viam/sdk/common/exception.hpp>
912
#include <viam/sdk/registry/registry.hpp>

0 commit comments

Comments
 (0)