Skip to content

Commit

Permalink
TMsgService* -> SMsgService*
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Feb 12, 2025
1 parent db8c73d commit 968806e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* - Offers methods for synchronous and asynchronous service invocations that support
* automatic parsing of the responses into user-defined protobuf message types.
* - Uses templated call methods to ensure that responses are converted to the expected
* type (TMsgServiceResponse) as specified by the caller.
* type (SMsgServiceResponse) as specified by the caller.
*
* Both classes inherit from the common base class, CServiceClientBase, which now is parameterized
* on both the service description type and the client instance wrapper type. This base class encapsulates
Expand All @@ -55,11 +55,11 @@
* Key Features:
* - Blocking calls using CallWithResponse:
* * Untyped version returns a vector of SServiceResponse.
* * Typed version returns a vector of TMsgServiceResponse<ResponseT>.
* * Typed version returns a vector of SMsgServiceResponse<ResponseT>.
*
* - Asynchronous calls using CallWithCallback and CallWithCallbackAsync:
* * Untyped version uses ResponseCallbackT for generic response handling.
* * Typed version uses TMsgResponseCallbackT<ResponseT> to automatically parse and
* * Typed version uses SMsgResponseCallbackT<ResponseT> to automatically parse and
* deliver typed responses.
*
* Usage Examples:
Expand Down Expand Up @@ -237,11 +237,11 @@ namespace eCAL
* @return A pair containing an overall success flag and a vector of typed responses.
*/
template <typename ResponseT>
std::pair<bool, TMsgServiceResponseVecT<ResponseT>> CallWithResponse(const std::string& method_name_,
std::pair<bool, SMsgServiceResponseVecT<ResponseT>> CallWithResponse(const std::string& method_name_,
const google::protobuf::Message& request_,
int timeout_ms_ = DEFAULT_TIME_ARGUMENT) const
{
return this->template ProcessInstances<TMsgServiceResponse<ResponseT>>(
return this->template ProcessInstances<SMsgServiceResponse<ResponseT>>(
[&](auto& instance) {
return instance.template CallWithResponse<ResponseT>(method_name_, request_, timeout_ms_);
}
Expand All @@ -263,7 +263,7 @@ namespace eCAL
template <typename ResponseT>
bool CallWithCallback(const std::string& method_name_,
const google::protobuf::Message& request_,
const TMsgResponseCallbackT<ResponseT>& response_callback_,
const SMsgResponseCallbackT<ResponseT>& response_callback_,
int timeout_ms_ = DEFAULT_TIME_ARGUMENT) const
{
bool overall_success = true;
Expand All @@ -288,7 +288,7 @@ namespace eCAL
template <typename ResponseT>
bool CallWithCallbackAsync(const std::string& method_name_,
const google::protobuf::Message& request_,
const TMsgResponseCallbackT<ResponseT>& response_callback_) const
const SMsgResponseCallbackT<ResponseT>& response_callback_) const
{
bool overall_success = true;
for (auto& instance : this->GetClientInstances())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* Key functionalities include:
* - **CallWithResponse**: A templated blocking call that, given an expected response type (ResponseT),
* returns a pair of a success flag and a parsed response encapsulated in a TMsgServiceResponse<ResponseT> structure.
* returns a pair of a success flag and a parsed response encapsulated in a SMsgServiceResponse<ResponseT> structure.
* - **CallWithCallback**: A templated callback-based call that parses the raw response and delivers it
* to a callback expecting a typed response.
* - **CallWithCallbackAsync**: A non-blocking variant of the typed callback-based call.
Expand Down Expand Up @@ -241,14 +241,14 @@ namespace eCAL
* @return A pair consisting of a success flag and a typed response.
*/
template <typename ResponseT>
std::pair<bool, TMsgServiceResponse<ResponseT>> CallWithResponse(const std::string& method_name_,
std::pair<bool, SMsgServiceResponse<ResponseT>> CallWithResponse(const std::string& method_name_,
const google::protobuf::Message& request_,
int timeout_ms_ = eCAL::CClientInstance::DEFAULT_TIME_ARGUMENT)
{
const std::string serialized_request = request_.SerializeAsString();

auto ret = m_instance.CallWithResponse(method_name_, serialized_request, timeout_ms_);
TMsgServiceResponse<ResponseT> msg_response = ConvertResponse<ResponseT>(ret.second);
SMsgServiceResponse<ResponseT> msg_response = ConvertResponse<ResponseT>(ret.second);

bool success = ret.first && (msg_response.call_state == eCallState::executed);
return std::make_pair(success, msg_response);
Expand All @@ -269,13 +269,13 @@ namespace eCAL
template <typename ResponseT>
bool CallWithCallback(const std::string& method_name_,
const google::protobuf::Message& request_,
const TMsgResponseCallbackT<ResponseT>& response_callback_,
const SMsgResponseCallbackT<ResponseT>& response_callback_,
int timeout_ms_ = eCAL::CClientInstance::DEFAULT_TIME_ARGUMENT)
{
const std::string serialized_request = request_.SerializeAsString();
auto wrapper = [this, method_name_, response_callback_](const SServiceResponse& service_response)
{
TMsgServiceResponse<ResponseT> msg_response = ConvertResponse<ResponseT>(service_response);
SMsgServiceResponse<ResponseT> msg_response = ConvertResponse<ResponseT>(service_response);
response_callback_(msg_response);
};
return m_instance.CallWithCallback(method_name_, serialized_request, wrapper, timeout_ms_);
Expand All @@ -295,12 +295,12 @@ namespace eCAL
template <typename ResponseT>
bool CallWithCallbackAsync(const std::string& method_name_,
const google::protobuf::Message& request_,
const TMsgResponseCallbackT<ResponseT>& response_callback_)
const SMsgResponseCallbackT<ResponseT>& response_callback_)
{
const std::string serialized_request = request_.SerializeAsString();
auto wrapper = [this, method_name_, response_callback_](const SServiceResponse& service_response)
{
TMsgServiceResponse<ResponseT> msg_response = ConvertResponse<ResponseT>(service_response);
SMsgServiceResponse<ResponseT> msg_response = ConvertResponse<ResponseT>(service_response);
response_callback_(msg_response);
};
return m_instance.CallWithCallbackAsync(method_name_, serialized_request, wrapper);
Expand Down Expand Up @@ -328,12 +328,12 @@ namespace eCAL
*
* @tparam ResponseT The expected protobuf response type.
* @param service_response The raw service response.
* @return A TMsgServiceResponse<ResponseT> structure containing the parsed response and metadata.
* @return A SMsgServiceResponse<ResponseT> structure containing the parsed response and metadata.
*/
template <typename ResponseT>
static TMsgServiceResponse<ResponseT> ConvertResponse(const SServiceResponse& service_response)
static SMsgServiceResponse<ResponseT> ConvertResponse(const SServiceResponse& service_response)
{
TMsgServiceResponse<ResponseT> msg_response;
SMsgServiceResponse<ResponseT> msg_response;
// Attempt to parse the raw response into a ResponseT object.
if (!msg_response.response.ParseFromString(service_response.response))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace eCAL
* @tparam ResponseT The expected protobuf response type.
*/
template <typename ResponseT>
struct TMsgServiceResponse
struct SMsgServiceResponse
{
eCallState call_state = eCallState::none; //!< Call state (success/failure)
SServiceId server_id; //!< Identifier of the server that executed the call
Expand All @@ -57,14 +57,14 @@ namespace eCAL
* @tparam ResponseT The expected protobuf response type.
*/
template <typename ResponseT>
using TMsgServiceResponseVecT = std::vector<TMsgServiceResponse<ResponseT>>;
using SMsgServiceResponseVecT = std::vector<SMsgServiceResponse<ResponseT>>;

/**
* @brief Typed callback for responses.
*
* @tparam ResponseT The expected protobuf response type.
*/
template <typename ResponseT>
using TMsgResponseCallbackT = std::function<void(const TMsgServiceResponse<ResponseT>&)>;
using SMsgResponseCallbackT = std::function<void(const SMsgServiceResponse<ResponseT>&)>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void OnClientState(const eCAL::SServiceId& service_id_, const eCAL::SClientEvent
}

// Callback for math service responses (for the callback variants).
void OnMathResponse(const eCAL::protobuf::TMsgServiceResponse<SFloat>& service_response_)
void OnMathResponse(const eCAL::protobuf::SMsgServiceResponse<SFloat>& service_response_)
{
const std::string& method_name = service_response_.service_method_information.method_name;
const std::string& host_name = service_response_.server_id.service_id.host_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ TEST(core_cpp_clientserver_proto, IterativeClientInstances_Typed_Math_Callback)
std::promise<std::vector<double>> prom;
auto fut = prom.get_future();

auto callback = [&mtx, &responses, expected_responses, &prom](const eCAL::protobuf::TMsgServiceResponse<SFloat>& resp)
auto callback = [&mtx, &responses, expected_responses, &prom](const eCAL::protobuf::SMsgServiceResponse<SFloat>& resp)
{
{
std::lock_guard<std::mutex> lock(mtx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST(core_cpp_clientserver_proto, TypedCallback_Math)
std::promise<double> prom;
auto fut = prom.get_future();

auto callback = [&prom](const eCAL::protobuf::TMsgServiceResponse<SFloat>& resp)
auto callback = [&prom](const eCAL::protobuf::SMsgServiceResponse<SFloat>& resp)
{
prom.set_value(resp.response.out());
};
Expand Down Expand Up @@ -115,7 +115,7 @@ TEST(core_cpp_clientserver_proto, TypedCallbackAsync_Math)
std::promise<double> prom;
auto fut = prom.get_future();

auto callback = [&prom](const eCAL::protobuf::TMsgServiceResponse<SFloat>& resp)
auto callback = [&prom](const eCAL::protobuf::SMsgServiceResponse<SFloat>& resp)
{
prom.set_value(resp.response.out());
};
Expand Down Expand Up @@ -177,7 +177,7 @@ TEST(core_cpp_clientserver_proto, TypedCallback_Ping)
std::promise<std::string> prom;
auto fut = prom.get_future();

auto callback = [&prom](const eCAL::protobuf::TMsgServiceResponse<PingResponse>& resp)
auto callback = [&prom](const eCAL::protobuf::SMsgServiceResponse<PingResponse>& resp)
{
prom.set_value(resp.response.answer());
};
Expand Down

0 comments on commit 968806e

Please sign in to comment.