@@ -54,8 +54,7 @@ struct RpcClient {
5454 // / For guidance on the permeission_level and token parameters, see:
5555 // / https://github.com/eclipse-uprotocol/up-spec/blob/main/basics/permissions.adoc
5656 explicit RpcClient (std::shared_ptr<transport::UTransport> transport,
57- v1::UUri&& method, v1::UPriority priority,
58- std::chrono::milliseconds ttl,
57+ v1::UPriority priority, std::chrono::milliseconds ttl,
5958 std::optional<v1::UPayloadFormat> payload_format = {},
6059 std::optional<uint32_t > permission_level = {},
6160 std::optional<std::string> token = {});
@@ -113,6 +112,7 @@ struct RpcClient {
113112
114113 // / @brief Invokes an RPC method by sending a request message.
115114 // /
115+ // / @param The method that will be invoked
116116 // / @param A Payload builder containing the payload to be sent with the
117117 // / request.
118118 // / @param A callback that will be called with the result.
@@ -124,11 +124,13 @@ struct RpcClient {
124124 // / * A UStatus based on the commstatus received in the response
125125 // / message (if not OK).
126126 // / * A UMessage containing the response from the RPC target.
127- [[nodiscard]] InvokeHandle invokeMethod (datamodel::builder::Payload&&,
127+ [[nodiscard]] InvokeHandle invokeMethod (const v1::UUri&,
128+ datamodel::builder::Payload&&,
128129 Callback&&);
129130
130131 // / @brief Invokes an RPC method by sending a request message.
131132 // /
133+ // / @param The method that will be invoked
132134 // / @param A Payload builder containing the payload to be sent with the
133135 // / request.
134136 // /
@@ -141,13 +143,15 @@ struct RpcClient {
141143 // / * A UStatus based on the commstatus received in the response
142144 // / message (if not OK).
143145 // / * A UMessage containing the response from the RPC target.
144- [[nodiscard]] InvokeFuture invokeMethod (datamodel::builder::Payload&&);
146+ [[nodiscard]] InvokeFuture invokeMethod (const v1::UUri&,
147+ datamodel::builder::Payload&&);
145148
146149 // / @brief Invokes an RPC method by sending a request message.
147150 // /
148151 // / Request is sent with an empty payload. Can only be called if no payload
149152 // / format was provided at construction time.
150153 // /
154+ // / @param The method that will be invoked
151155 // / @param A callback that will be called with the result.
152156 // /
153157 // / @post The provided callback will be called with one of:
@@ -157,13 +161,14 @@ struct RpcClient {
157161 // / * A UStatus based on the commstatus received in the response
158162 // / message (if not OK).
159163 // / * A UMessage containing the response from the RPC target.
160- [[nodiscard]] InvokeHandle invokeMethod (Callback&&);
164+ [[nodiscard]] InvokeHandle invokeMethod (const v1::UUri&, Callback&&);
161165
162166 // / @brief Invokes an RPC method by sending a request message.
163167 // /
164168 // / Request is sent with an empty payload. Can only be called if no payload
165169 // / format was provided at construction time.
166170 // /
171+ // / @param The method that will be invoked
167172 // / @remarks This is a wrapper around the callback form of invokeMethod.
168173 // /
169174 // / @returns A promised future that can resolve to one of:
@@ -173,7 +178,83 @@ struct RpcClient {
173178 // / * A UStatus based on the commstatus received in the response
174179 // / message (if not OK).
175180 // / * A UMessage containing the response from the RPC target.
176- [[nodiscard]] InvokeFuture invokeMethod ();
181+ [[nodiscard]] InvokeFuture invokeMethod (const v1::UUri&);
182+
183+ template <typename R>
184+ InvokeHandle invokeMethodToProto (const v1::UUri& method,
185+ const R& request_message,
186+ Callback&& callback) {
187+ auto payload_or_status =
188+ uprotocol::utils::ProtoConverter::protoToPayload (request_message);
189+
190+ if (!payload_or_status.has_value ()) {
191+ return {};
192+ }
193+
194+ datamodel::builder::Payload tmp_payload (payload_or_status.value ());
195+ auto handle = invokeMethod (
196+ builder_.withMethod (method).build (std::move (tmp_payload)),
197+ std::move (callback));
198+
199+ return handle;
200+ }
201+
202+ template <typename T, typename R>
203+ InvokeProtoFuture<T> invokeMethodToProto (const v1::UUri& method,
204+ const R& request_message) {
205+ auto result_promise =
206+ std::make_shared<std::promise<ResponseOrStatus<T>>>();
207+ auto future = result_promise->get_future ();
208+ auto handle = invokeMethodToProto (
209+ method, request_message,
210+ [result_promise](const MessageOrStatus& message_or_status) {
211+ if (!message_or_status.has_value ()) {
212+ result_promise->set_value (ResponseOrStatus<T>(
213+ UnexpectedStatus (message_or_status.error ())));
214+ return ;
215+ }
216+ auto response_or_status =
217+ utils::ProtoConverter::extractFromProtobuf<T>(
218+ message_or_status.value ());
219+
220+ if (!response_or_status.has_value ()) {
221+ spdlog::error (
222+ " invokeProtoMethod: Error when extracting response "
223+ " from "
224+ " protobuf." );
225+ result_promise->set_value (response_or_status);
226+ return ;
227+ }
228+
229+ result_promise->set_value (
230+ ResponseOrStatus<T>(response_or_status.value ()));
231+ });
232+
233+ return {std::move (future), std::move (handle)};
234+ }
235+
236+ template <typename R>
237+ InvokeFuture invokeMethodToProto (const v1::UUri& method,
238+ const R& request_message) {
239+ auto result_promise =
240+ std::make_shared<std::promise<ResponseOrStatus<v1::UMessage>>>();
241+ auto future = result_promise->get_future ();
242+
243+ auto handle = invokeMethodToProto (
244+ method, request_message,
245+ [result_promise](const MessageOrStatus& message_or_status) {
246+ if (!message_or_status.has_value ()) {
247+ result_promise->set_value (ResponseOrStatus<v1::UMessage>(
248+ UnexpectedStatus (message_or_status.error ())));
249+ return ;
250+ }
251+
252+ result_promise->set_value (
253+ ResponseOrStatus<v1::UMessage>(message_or_status.value ()));
254+ });
255+
256+ return {std::move (future), std::move (handle)};
257+ }
177258
178259 template <typename R>
179260 InvokeHandle invokeProtoMethod (const R& request_message,
0 commit comments