Skip to content

Commit

Permalink
ign -> gz Provisional Finale: Source Migration : gz-transport (#329)
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <[email protected]>
  • Loading branch information
methylDragon authored Jul 23, 2022
1 parent d2aa137 commit 012a19d
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 96 deletions.
2 changes: 2 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ release will remove the deprecated code.
1. `IGN_ZMQ_POST_4_3_1`
1. `IGN_CPPZMQ_POST_4_7_0`
1. `ign_strcat`, `ign_strcpy`, `ign_sprintf`, `ign_strdup`
1. The `IgnTransportNode` class is deprecated and will be removed in future versions. Use `GzTransportNode` instead.
Similarly, the `Ign` prefixed members of that class will be removed in future versions. Use the `Gz` prefixed members instead.

### Breaking Changes

Expand Down
12 changes: 6 additions & 6 deletions example/publisher_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ int main(int argc, char **argv)
signal(SIGTERM, signalHandler);

// Create a transport node.
IgnTransportNode *node = ignTransportNodeCreate(nullptr);
IgnTransportNode *nodeRed = ignTransportNodeCreate("red");
GzTransportNode *node = gzTransportNodeCreate(nullptr);
GzTransportNode *nodeRed = gzTransportNodeCreate("red");

const char *topic = "/foo";

Expand Down Expand Up @@ -81,8 +81,8 @@ int main(int argc, char **argv)
// Publish messages at 1Hz.
while (!g_terminatePub)
{
ignTransportPublish(node, topic, buffer, msg.GetTypeName().c_str());
ignTransportPublish(nodeRed, topic, bufferRed,
gzTransportPublish(node, topic, buffer, msg.GetTypeName().c_str());
gzTransportPublish(nodeRed, topic, bufferRed,
msgRed.GetTypeName().c_str());

printf("Publishing hello on topic %s.\n", topic);
Expand All @@ -91,8 +91,8 @@ int main(int argc, char **argv)

free(buffer);
free(bufferRed);
ignTransportNodeDestroy(&node);
ignTransportNodeDestroy(&nodeRed);
gzTransportNodeDestroy(&node);
gzTransportNodeDestroy(&nodeRed);

return 0;
}
12 changes: 6 additions & 6 deletions example/publisher_c_fast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ int main(int argc, char **argv)
signal(SIGTERM, signalHandler);

// Create a transport node.
IgnTransportNode *node = ignTransportNodeCreate(nullptr);
IgnTransportNode *nodeRed = ignTransportNodeCreate("red");
GzTransportNode *node = gzTransportNodeCreate(nullptr);
GzTransportNode *nodeRed = gzTransportNodeCreate("red");

const char *topic = "/foo";

Expand Down Expand Up @@ -73,17 +73,17 @@ int main(int argc, char **argv)
// Publish messages as fast as possible.
while (!g_terminatePub)
{
ignTransportPublish(node, topic, buffer, msg.GetTypeName().c_str());
ignTransportPublish(nodeRed, topic, bufferRed,
gzTransportPublish(node, topic, buffer, msg.GetTypeName().c_str());
gzTransportPublish(nodeRed, topic, bufferRed,
msgRed.GetTypeName().c_str());

printf("Publishing hello on topic %s.\n", topic);
}

free(buffer);
free(bufferRed);
ignTransportNodeDestroy(&node);
ignTransportNodeDestroy(&nodeRed);
gzTransportNodeDestroy(&node);
gzTransportNodeDestroy(&nodeRed);

return 0;
}
14 changes: 7 additions & 7 deletions example/subscriber_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,30 @@ int main(int argc, char **argv)
{
const char *partName = "red";
// Create a transport node.
IgnTransportNode *node = ignTransportNodeCreate(nullptr);
IgnTransportNode *nodeRed = ignTransportNodeCreate(partName);
GzTransportNode *node = gzTransportNodeCreate(nullptr);
GzTransportNode *nodeRed = gzTransportNodeCreate(partName);

const char *topic = "/foo";

// Subscribe to a topic by registering a callback.
if (ignTransportSubscribe(node, topic, cb, nullptr) != 0)
if (gzTransportSubscribe(node, topic, cb, nullptr) != 0)
{
printf("Error subscribing to topic %s.\n", topic);
return -1;
}

// Subscribe to a topic by registering a callback.
if (ignTransportSubscribe(nodeRed, topic, cb,
if (gzTransportSubscribe(nodeRed, topic, cb,
const_cast<char*>(partName)) != 0)
{
printf("Error subscribing to topic %s.\n", topic);
return -1;
}

// Zzzzzz.
ignTransportWaitForShutdown();
ignTransportNodeDestroy(&node);
ignTransportNodeDestroy(&nodeRed);
gzTransportWaitForShutdown();
gzTransportNodeDestroy(&node);
gzTransportNodeDestroy(&nodeRed);

return 0;
}
8 changes: 4 additions & 4 deletions example/subscriber_c_slow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ void cb(const char *_data, const size_t _size, const char *_msgType,
int main(int argc, char **argv)
{
// Create a transport node.
IgnTransportNode *node = ignTransportNodeCreate(nullptr);
GzTransportNode *node = gzTransportNodeCreate(nullptr);

const char *topic = "/foo";

SubscribeOpts opts;
opts.msgsPerSec = 1;

// Subscribe to a topic by registering a callback.
if (ignTransportSubscribeOptions(node, topic, opts, cb, nullptr) != 0)
if (gzTransportSubscribeOptions(node, topic, opts, cb, nullptr) != 0)
{
printf("Error subscribing to topic %s.\n", topic);
return -1;
}

// Zzzzzz.
ignTransportWaitForShutdown();
ignTransportNodeDestroy(&node);
gzTransportWaitForShutdown();
gzTransportNodeDestroy(&node);

return 0;
}
39 changes: 28 additions & 11 deletions include/gz/transport/CIface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,36 @@ extern "C" {
} SubscribeOpts;

/// \brief A transport node.
typedef struct IgnTransportNode IgnTransportNode;
typedef struct GzTransportNode GzTransportNode;

// TODO(CH3): Deprecated. Remove!
#ifdef _WIN32
using IgnTransportNode = GzTransportNode;
#else
using IgnTransportNode GZ_DEPRECATED(12) = GzTransportNode;
#endif

/// \brief Create a transport node.
/// \param[in] _partition Optional name of the partition to use.
/// Use nullptr to use the default value, which is specified via the
/// GZ_PARTITION environment variable.
/// \return A pointer to a new transport node. Do not manually delete this
/// pointer, instead use ignTransportNodeDestroy.
IgnTransportNode GZ_TRANSPORT_VISIBLE *ignTransportNodeCreate(
/// pointer, instead use gzTransportNodeDestroy.
GzTransportNode GZ_TRANSPORT_VISIBLE *gzTransportNodeCreate(
const char *_partition);

/// \brief Destroy a transport node.
/// \param[in, out] _node The transport node to destroy.
void GZ_TRANSPORT_VISIBLE
ignTransportNodeDestroy(IgnTransportNode **_node);
gzTransportNodeDestroy(GzTransportNode **_node);

/// \brief Advertise a topic.
/// \param[in] _node Pointer to a node.
/// \param[in] _topic Topic on which to publish the message.
/// \param[in] _msgType Name of the message type.
/// \return 0 on success.
int GZ_TRANSPORT_VISIBLE
ignTransportAdvertise(IgnTransportNode *_node,
gzTransportAdvertise(GzTransportNode *_node,
const char *_topic,
const char *_msgType);

Expand All @@ -64,7 +71,7 @@ extern "C" {
/// \param[in] _msgType Name of the message type.
/// \return 0 on success.
int GZ_TRANSPORT_VISIBLE
ignTransportPublish(IgnTransportNode *_node,
gzTransportPublish(GzTransportNode *_node,
const char *_topic,
const void *_data,
const char *_msgType);
Expand All @@ -76,7 +83,7 @@ extern "C" {
/// \param[in] _userData Arbitrary user data pointer.
/// \return 0 on success.
int GZ_TRANSPORT_VISIBLE
ignTransportSubscribe(IgnTransportNode *_node,
gzTransportSubscribe(GzTransportNode *_node,
const char *_topic,
void (*_callback)(const char *, size_t, const char *, void *),
void *_userData);
Expand All @@ -89,7 +96,7 @@ extern "C" {
/// \param[in] _userData Arbitrary user data pointer.
/// \return 0 on success.
int GZ_TRANSPORT_VISIBLE
ignTransportSubscribeOptions(IgnTransportNode *_node,
gzTransportSubscribeOptions(GzTransportNode *_node,
const char *_topic, SubscribeOpts _opts,
void (*_callback)(const char *, size_t, const char *, void *),
void *_userData);
Expand All @@ -101,7 +108,7 @@ extern "C" {
/// \param[in] _userData Arbitrary user data pointer.
/// \return 0 on success.
int GZ_TRANSPORT_VISIBLE
ignTransportSubscribeNonConst(IgnTransportNode *_node, char *_topic,
gzTransportSubscribeNonConst(GzTransportNode *_node, char *_topic,
void (*_callback)(char *, size_t, char *, void *),
void *_userData);

Expand All @@ -110,12 +117,22 @@ extern "C" {
/// \param[in] _topic Name of the topic.
/// \return 0 on success.
int GZ_TRANSPORT_VISIBLE
ignTransportUnsubscribe(IgnTransportNode *_node, const char *_topic);
gzTransportUnsubscribe(GzTransportNode *_node, const char *_topic);

/// \brief Block the current thread until a SIGINT or SIGTERM is received.
/// Note that this function registers a signal handler. Do not use this
/// function if you want to manage yourself SIGINT/SIGTERM.
void GZ_TRANSPORT_VISIBLE ignTransportWaitForShutdown();
void GZ_TRANSPORT_VISIBLE gzTransportWaitForShutdown();

const auto GZ_DEPRECATED(12) ignTransportNodeCreate = gzTransportNodeCreate;
const auto GZ_DEPRECATED(12) ignTransportNodeDestroy = gzTransportNodeDestroy;
const auto GZ_DEPRECATED(12) ignTransportAdvertise = gzTransportAdvertise;
const auto GZ_DEPRECATED(12) ignTransportPublish = gzTransportPublish;
const auto GZ_DEPRECATED(12) ignTransportSubscribe = gzTransportSubscribe;
const auto GZ_DEPRECATED(12) ignTransportSubscribeOptions = gzTransportSubscribeOptions;
const auto GZ_DEPRECATED(12) ignTransportSubscribeNonConst = gzTransportSubscribeNonConst;
const auto GZ_DEPRECATED(12) ignTransportUnsubscribe = gzTransportUnsubscribe;
const auto GZ_DEPRECATED(12) ignTransportWaitForShutdown = gzTransportWaitForShutdown;

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion include/gz/transport/TopicStatistics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace gz
public: void Update(const std::string &_sender,
uint64_t _stamp, uint64_t _seq);

/// \brief Populate an gz::msgs::Metric message with topic
/// \brief Populate a gz::msgs::Metric message with topic
/// statistics.
/// \param[in] _msg Message to populate.
public: void FillMessage(msgs::Metric &_msg) const;
Expand Down
2 changes: 1 addition & 1 deletion include/gz/transport/gz_auto_headers.hh.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Automatically generated
#include <gz/${GZ_DESIGNATION}/config.hh>
${ign_headers}
${gz_headers}
28 changes: 14 additions & 14 deletions src/CIface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "gz/transport/CIface.h"

/// \brief A wrapper to store a Gazebo Transport node and its publishers.
struct IgnTransportNode
struct GzTransportNode
{
/// \brief Pointer to the node.
std::unique_ptr<gz::transport::Node> nodePtr;
Expand All @@ -33,18 +33,18 @@ struct IgnTransportNode
};

/////////////////////////////////////////////////
IgnTransportNode *ignTransportNodeCreate(const char *_partition)
GzTransportNode *gzTransportNodeCreate(const char *_partition)
{
IgnTransportNode *ignTransportNode = new IgnTransportNode();
GzTransportNode *gzTransportNode = new GzTransportNode();
gz::transport::NodeOptions opts;
if (_partition)
opts.SetPartition(_partition);
ignTransportNode->nodePtr = std::make_unique<gz::transport::Node>(opts);
return ignTransportNode;
gzTransportNode->nodePtr = std::make_unique<gz::transport::Node>(opts);
return gzTransportNode;
}

/////////////////////////////////////////////////
void ignTransportNodeDestroy(IgnTransportNode **_node)
void gzTransportNodeDestroy(GzTransportNode **_node)
{
if (*_node)
{
Expand All @@ -54,7 +54,7 @@ void ignTransportNodeDestroy(IgnTransportNode **_node)
}

/////////////////////////////////////////////////
int ignTransportAdvertise(IgnTransportNode *_node, const char *_topic,
int gzTransportAdvertise(GzTransportNode *_node, const char *_topic,
const char *_msgType)
{
if (!_node)
Expand All @@ -68,14 +68,14 @@ int ignTransportAdvertise(IgnTransportNode *_node, const char *_topic,
}

/////////////////////////////////////////////////
int ignTransportPublish(IgnTransportNode *_node, const char *_topic,
int gzTransportPublish(GzTransportNode *_node, const char *_topic,
const void *_data, const char *_msgType)
{
if (!_node)
return 1;

// Create a publisher if one does not exist.
if (ignTransportAdvertise(_node, _topic, _msgType) == 0)
if (gzTransportAdvertise(_node, _topic, _msgType) == 0)
{
// Publish the message.
return _node->publishers[_topic].PublishRaw(
Expand All @@ -86,7 +86,7 @@ int ignTransportPublish(IgnTransportNode *_node, const char *_topic,
}

/////////////////////////////////////////////////
int ignTransportSubscribe(IgnTransportNode *_node, const char *_topic,
int gzTransportSubscribe(GzTransportNode *_node, const char *_topic,
void (*_callback)(const char *, size_t, const char *, void *),
void *_userData)
{
Expand All @@ -103,7 +103,7 @@ int ignTransportSubscribe(IgnTransportNode *_node, const char *_topic,
}

/////////////////////////////////////////////////
int ignTransportSubscribeOptions(IgnTransportNode *_node, const char *_topic,
int gzTransportSubscribeOptions(GzTransportNode *_node, const char *_topic,
SubscribeOpts _opts,
void (*_callback)(const char *, size_t, const char *, void *),
void *_userData)
Expand All @@ -128,7 +128,7 @@ int ignTransportSubscribeOptions(IgnTransportNode *_node, const char *_topic,


/////////////////////////////////////////////////
int ignTransportSubscribeNonConst(IgnTransportNode *_node, char *_topic,
int gzTransportSubscribeNonConst(GzTransportNode *_node, char *_topic,
void (*_callback)(char *, size_t, char *, void *), void *_userData)
{
if (!_node)
Expand All @@ -146,7 +146,7 @@ int ignTransportSubscribeNonConst(IgnTransportNode *_node, char *_topic,
}

/////////////////////////////////////////////////
int ignTransportUnsubscribe(IgnTransportNode *_node, const char *_topic)
int gzTransportUnsubscribe(GzTransportNode *_node, const char *_topic)
{
if (!_node)
return 1;
Expand All @@ -156,7 +156,7 @@ int ignTransportUnsubscribe(IgnTransportNode *_node, const char *_topic)


/////////////////////////////////////////////////
void ignTransportWaitForShutdown()
void gzTransportWaitForShutdown()
{
gz::transport::waitForShutdown();
}
Loading

0 comments on commit 012a19d

Please sign in to comment.