11#pragma once
22
3- #include < grpcpp/client_context.h>
4- #include < grpcpp/support/sync_stream.h>
5-
63#include < viam/sdk/common/exception.hpp>
4+ #include < viam/sdk/common/grpc_client_fwd.hpp>
75#include < viam/sdk/common/private/utils.hpp>
86#include < viam/sdk/common/proto_value.hpp>
9- #include < viam/sdk/common/utils.hpp>
107
118namespace grpc {
129
@@ -23,16 +20,39 @@ namespace client_helper_details {
2320
2421} // namespace client_helper_details
2522
23+ // the authority on a grpc::ClientContext is sometimes set to an invalid uri on mac, causing
24+ // `rust-utils` to fail to process gRPC requests. This class provides a convenience wrapper around a
25+ // grpc ClientContext that allows us to make any necessary modifications to authority or else where
26+ // to avoid runtime issues.
27+ // For more details, see https://viam.atlassian.net/browse/RSDK-5194.
28+ class ClientContext {
29+ public:
30+ ClientContext ();
31+ ~ClientContext ();
32+
33+ void try_cancel ();
34+
35+ operator GrpcClientContext*();
36+ operator const GrpcClientContext*() const ;
37+
38+ void set_debug_key (const std::string& debug_key);
39+
40+ private:
41+ void set_client_ctx_authority_ ();
42+ void add_viam_client_version_ ();
43+ std::unique_ptr<GrpcClientContext> wrapped_context_;
44+ };
45+
2646// Method type for a gRPC call that returns a response message type.
2747template <typename StubType, typename RequestType, typename ResponseType>
28- using SyncMethodType = ::grpc::Status (StubType::*)(::grpc::ClientContext *,
48+ using SyncMethodType = ::grpc::Status (StubType::*)(GrpcClientContext *,
2949 const RequestType&,
3050 ResponseType*);
3151
3252// Method type for a gRPC call that returns a stream of response message type.
3353template <typename StubType, typename RequestType, typename ResponseType>
34- using StreamingMethodType = std::unique_ptr<::grpc::ClientReaderInterface <ResponseType>> (
35- StubType::*)(::grpc::ClientContext *, const RequestType&);
54+ using StreamingMethodType = std::unique_ptr<GrpcClientReaderInterface <ResponseType>> (StubType::*) (
55+ GrpcClientContext *, const RequestType&);
3656
3757template <typename ClientType,
3858 typename StubType,
0 commit comments