Skip to content

Commit

Permalink
Update codebase to new clang-format style
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Aug 9, 2024
1 parent 72a6fd6 commit 3c8571e
Show file tree
Hide file tree
Showing 90 changed files with 1,100 additions and 2,048 deletions.
47 changes: 17 additions & 30 deletions modules/comms/include/mvsim/Comms/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ class Client : public mrpt::system::COutputLogger
template <typename T>
void advertiseTopic(const std::string& topicName);

void publishTopic(
const std::string& topicName, const google::protobuf::Message& msg);
void publishTopic(const std::string& topicName, const google::protobuf::Message& msg);

template <typename MSG_T>
void subscribeTopic(
const std::string& topicName,
const std::function<void(const MSG_T&)>& callback);
const std::string& topicName, const std::function<void(const MSG_T&)>& callback);

template <typename INPUT_MSG_T, typename OUTPUT_MSG_T>
void advertiseService(
Expand All @@ -96,19 +94,17 @@ class Client : public mrpt::system::COutputLogger

template <typename INPUT_MSG_T, typename OUTPUT_MSG_T>
void callService(
const std::string& serviceName, const INPUT_MSG_T& input,
OUTPUT_MSG_T& output);
const std::string& serviceName, const INPUT_MSG_T& input, OUTPUT_MSG_T& output);

/// Overload for python wrapper
std::string callService(
const std::string& serviceName, const std::string& inputSerializedMsg);
std::string callService(const std::string& serviceName, const std::string& inputSerializedMsg);

/// Overload for python wrapper (callback accepts bytes-string)
void subscribeTopic(
const std::string& topicName,
const std::function<void(
const std::string& /*msgType*/,
const std::vector<uint8_t>& /*serializedMsg*/)>& callback);
const std::function<
void(const std::string& /*msgType*/, const std::vector<uint8_t>& /*serializedMsg*/)>&
callback);

struct InfoPerNode
{
Expand All @@ -126,8 +122,7 @@ class Client : public mrpt::system::COutputLogger

using topic_callback_t = std::function<void(const zmq::message_t& /*m*/)>;

void subscribe_topic_raw(
const std::string& topicName, const topic_callback_t& callback);
void subscribe_topic_raw(const std::string& topicName, const topic_callback_t& callback);

/** @} */

Expand Down Expand Up @@ -156,22 +151,17 @@ class Client : public mrpt::system::COutputLogger
void internalTopicUpdatesThread();
void internalTopicSubscribeThread(internal::InfoPerSubscribedTopic& ipt);

using service_callback_t =
std::function<std::shared_ptr<google::protobuf::Message>(
const std::string& /*inAsString*/)>;
using service_callback_t = std::function<std::shared_ptr<google::protobuf::Message>(
const std::string& /*inAsString*/)>;

void doAdvertiseTopic(
const std::string& topicName,
const google::protobuf::Descriptor* descriptor);
const std::string& topicName, const google::protobuf::Descriptor* descriptor);
void doAdvertiseService(
const std::string& serviceName,
const google::protobuf::Descriptor* descIn,
const google::protobuf::Descriptor* descOut,
service_callback_t callback);
const std::string& serviceName, const google::protobuf::Descriptor* descIn,
const google::protobuf::Descriptor* descOut, service_callback_t callback);

void doSubscribeTopic(
const std::string& topicName,
const google::protobuf::Descriptor* descriptor,
const std::string& topicName, const google::protobuf::Descriptor* descriptor,
const topic_callback_t& callback);
void doCallService(
const std::string& serviceName, const std::string& inputSerializedMsg,
Expand All @@ -191,8 +181,7 @@ void Client::advertiseTopic(const std::string& topicName)

template <typename INPUT_MSG_T, typename OUTPUT_MSG_T>
void Client::advertiseService(
const std::string& serviceName,
const std::function<OUTPUT_MSG_T(const INPUT_MSG_T&)>& callback)
const std::string& serviceName, const std::function<OUTPUT_MSG_T(const INPUT_MSG_T&)>& callback)
{
doAdvertiseService(
serviceName, INPUT_MSG_T::descriptor(), OUTPUT_MSG_T::descriptor(),
Expand All @@ -207,8 +196,7 @@ void Client::advertiseService(

template <typename MSG_T>
void Client::subscribeTopic(
const std::string& topicName,
const std::function<void(const MSG_T&)>& callback)
const std::string& topicName, const std::function<void(const MSG_T&)>& callback)
{
doSubscribeTopic(
topicName, MSG_T::descriptor(),
Expand All @@ -223,8 +211,7 @@ void Client::subscribeTopic(

template <typename INPUT_MSG_T, typename OUTPUT_MSG_T>
void Client::callService(
const std::string& serviceName, const INPUT_MSG_T& input,
OUTPUT_MSG_T& output)
const std::string& serviceName, const INPUT_MSG_T& input, OUTPUT_MSG_T& output)
{
doCallService(serviceName, input.SerializeAsString(), output);
}
Expand Down
16 changes: 5 additions & 11 deletions modules/comms/include/mvsim/Comms/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ class Server : public mrpt::system::COutputLogger
const std::string& serviceName, std::string& publisherEndpoint,
std::string& nodeName) const;

void db_add_topic_subscriber(
const std::string& topicName, const std::string& updatesEndPoint);
void db_add_topic_subscriber(const std::string& topicName, const std::string& updatesEndPoint);

/** Send to updatesEndPoint only, if given; otherwise, send to all
* subscribers */
Expand Down Expand Up @@ -153,8 +152,7 @@ class Server : public mrpt::system::COutputLogger
struct InfoPerPublisher
{
InfoPerPublisher(
const std::string& topic_name,
const std::string& publisher_node_name,
const std::string& topic_name, const std::string& publisher_node_name,
const std::string& publisher_endpoint)
: topicName(topic_name),
publisherNodeName(publisher_node_name),
Expand All @@ -168,11 +166,8 @@ class Server : public mrpt::system::COutputLogger

struct InfoPerSubscriber
{
InfoPerSubscriber(
const std::string& topic_name,
const std::string& sub_updates_endpoint)
: topicName(topic_name),
subscriberUpdatesEndpoint(sub_updates_endpoint)
InfoPerSubscriber(const std::string& topic_name, const std::string& sub_updates_endpoint)
: topicName(topic_name), subscriberUpdatesEndpoint(sub_updates_endpoint)
{
}
const std::string topicName;
Expand All @@ -182,8 +177,7 @@ class Server : public mrpt::system::COutputLogger
struct InfoPerTopic
{
InfoPerTopic() = default;
InfoPerTopic(
const std::string& name, const std::string& topic_type_name)
InfoPerTopic(const std::string& name, const std::string& topic_type_name)
: topicName(name), topicTypeName(topic_type_name)
{
}
Expand Down
17 changes: 5 additions & 12 deletions modules/comms/include/mvsim/Comms/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,19 @@ zmq::message_t receiveMessage(zmq::socket_t& s);
*
* \exception std::runtime_error If the message type does not match with out.
*/
void parseMessage(
const zmq::message_t& msg, google::protobuf::MessageLite& out);
void parseMessage(const zmq::message_t& msg, google::protobuf::MessageLite& out);

class UnexpectedMessageException : public std::runtime_error
{
public:
UnexpectedMessageException(const char* reason) : std::runtime_error(reason)
{
}
UnexpectedMessageException(const char* reason) : std::runtime_error(reason) {}
};
namespace internal
{
std::tuple<std::string, std::string> parseMessageToParts(
const zmq::message_t& msg);
std::tuple<std::string, std::string> parseMessageToParts(const zmq::message_t& msg);

template <typename variant_t, size_t IDX = 0>
variant_t recursiveParse(
const std::string& typeName, const std::string& serializedData)
variant_t recursiveParse(const std::string& typeName, const std::string& serializedData)
{
if constexpr (IDX < std::variant_size_v<variant_t>)
{
Expand All @@ -81,9 +76,7 @@ variant_t recursiveParse(
return recursiveParse<variant_t, IDX + 1>(typeName, serializedData);
}
throw UnexpectedMessageException(
mrpt::format(
"Type '%s' not found in expected list of variant arguments.",
typeName.c_str())
mrpt::format("Type '%s' not found in expected list of variant arguments.", typeName.c_str())
.c_str());
}
} // namespace internal
Expand Down
6 changes: 2 additions & 4 deletions modules/comms/include/mvsim/Comms/zmq_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ class SocketMonitor : public zmq::monitor_t
}

void on_event_disconnected(
[[maybe_unused]] const zmq_event_t& event_,
[[maybe_unused]] const char* addr_) override
[[maybe_unused]] const zmq_event_t& event_, [[maybe_unused]] const char* addr_) override
{
setConnected(false);
}

void on_event_connected(
[[maybe_unused]] const zmq_event_t& event_,
[[maybe_unused]] const char* addr_) override
[[maybe_unused]] const zmq_event_t& event_, [[maybe_unused]] const char* addr_) override
{
setConnected(true);
}
Expand Down
Loading

0 comments on commit 3c8571e

Please sign in to comment.