Skip to content

Commit

Permalink
Tweak deprecations. (gazebosim#136)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Aguero <[email protected]>
  • Loading branch information
caguero and caguero authored May 15, 2020
1 parent 598f100 commit 09723c4
Show file tree
Hide file tree
Showing 22 changed files with 1,233 additions and 264 deletions.
31 changes: 30 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,36 @@

## Ignition Transport 7

### Ignition Transport 7.X.X
### Ignition Transport 7.x.x (202x-xx-xx)

1. Handle `getpwduid_r` error cases. This addresses issue #118. Solution was
created in pull request #441 by Poh Zhi-Ee.
* [BitBucket pull request 444](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-transport/pull-requests/444)

### Ignition Transport 7.4.0 (2020-03-09)

1. Removed a `sleep` from NodeShared. The sleep was meant to guarantee
message delivery during `connect`. This approach would fail if the delay
between nodes was too large.
* [BitBucket pull request 436](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-transport/pull-requests/436)

1. Set default message buffer sizes to 1000, for both send and receive
buffers.
* [BitBucket pull request 433](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-transport/pull-requests/433)

1. Added support for configuring message buffers via environment variables.
* [BitBucket pull request 430](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-transport/pull-requests/430)

### Ignition Transport 7.3.0

1. Write to disk from a background thread in log recorder
* [BitBucket pull request 428](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-transport/pull-requests/428)

1. Restore original Playback::Start and add overload with new parameter to fix ABI.
* [BitBucket pull request 427](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-transport/pull-requests/427)

1. Improve compiler support for c++ filesystem.
* [BitBucket pull request 422](https://osrf-migration.github.io/ignition-gh-pages/#!/ignitionrobotics/ign-transport/pull-requests/422)

### Ignition Transport 7.2.1

Expand Down
16 changes: 6 additions & 10 deletions example/publisher_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ int main(int argc, char **argv)
msg.set_data("HELLO");

// Get the size of the serialized message
#if GOOGLE_PROTOBUF_VERSION < 3001000
int size = msg.ByteSize();
#else
// ByteSizeLong appeared in version 3.1 of Protobuf, and ByteSize
// became deprecated.
#if GOOGLE_PROTOBUF_VERSION >= 3004000
int size = msg.ByteSizeLong();
#else
int size = msg.ByteSize();
#endif

// Allocate space for the serialized message
Expand All @@ -68,12 +66,10 @@ int main(int argc, char **argv)
msgRed.set_data("RED HELLO");

// Get the size of the serialized message
#if GOOGLE_PROTOBUF_VERSION < 3001000
int sizeRed = msgRed.ByteSize();
#else
// ByteSizeLong appeared in version 3.1 of Protobuf, and ByteSize
// became deprecated.
#if GOOGLE_PROTOBUF_VERSION >= 3004000
int sizeRed = msgRed.ByteSizeLong();
#else
int sizeRed = msgRed.ByteSize();
#endif

// Allocate space for the serialized message
Expand Down
87 changes: 77 additions & 10 deletions include/ignition/transport/Discovery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,22 @@ namespace ignition
return true;
}

/// \brief Register a node from this process as a remote subscriber.
/// \param[in] _pub Contains information about the subscriber.
public: void Register(const MessagePublisher &_pub) const
{
this->SendMsg(
DestinationType::ALL, msgs::Discovery::NEW_CONNECTION, _pub);
}

/// \brief Unregister a node from this process as a remote subscriber.
/// \param[in] _pub Contains information about the subscriber.
public: void Unregister(const MessagePublisher &_pub) const
{
this->SendMsg(
DestinationType::ALL, msgs::Discovery::END_CONNECTION, _pub);
}

/// \brief Get the discovery information.
/// \return Reference to the discovery information object.
public: const TopicStorage<Pub> &Info() const
Expand Down Expand Up @@ -520,6 +536,24 @@ namespace ignition
this->disconnectionCb = _cb;
}

/// \brief Register a callback to receive an event when a new remote
/// node subscribes to a topic within this process.
/// \param[in] _cb Function callback.
public: void RegistrationsCb(const DiscoveryCallback<Pub> &_cb)
{
std::lock_guard<std::mutex> lock(this->mutex);
this->registrationCb = _cb;
}

/// \brief Register a callback to receive an event when a remote
/// node unsubscribes to a topic within this process.
/// \param[in] _cb Function callback.
public: void UnregistrationsCb(const DiscoveryCallback<Pub> &_cb)
{
std::lock_guard<std::mutex> lock(this->mutex);
this->unregistrationCb = _cb;
}

/// \brief Print the current discovery state.
public: void PrintCurrentState() const
{
Expand Down Expand Up @@ -867,11 +901,15 @@ namespace ignition
// Update timestamp and cache the callbacks.
DiscoveryCallback<Pub> connectCb;
DiscoveryCallback<Pub> disconnectCb;
DiscoveryCallback<Pub> registerCb;
DiscoveryCallback<Pub> unregisterCb;
{
std::lock_guard<std::mutex> lock(this->mutex);
this->activity[recvPUuid] = std::chrono::steady_clock::now();
connectCb = this->connectionCb;
disconnectCb = this->disconnectionCb;
registerCb = this->registrationCb;
unregisterCb = this->unregistrationCb;
}

switch (msg.type())
Expand Down Expand Up @@ -950,6 +988,28 @@ namespace ignition

break;
}
case msgs::Discovery::NEW_CONNECTION:
{
// Read the rest of the fields.
Pub publisher;
publisher.SetFromDiscovery(msg);

if (registerCb)
registerCb(publisher);

break;
}
case msgs::Discovery::END_CONNECTION:
{
// Read the rest of the fields.
Pub publisher;
publisher.SetFromDiscovery(msg);

if (unregisterCb)
unregisterCb(publisher);

break;
}
case msgs::Discovery::HEARTBEAT:
{
// The timestamp has already been updated.
Expand Down Expand Up @@ -1036,6 +1096,8 @@ namespace ignition
{
case msgs::Discovery::ADVERTISE:
case msgs::Discovery::UNADVERTISE:
case msgs::Discovery::NEW_CONNECTION:
case msgs::Discovery::END_CONNECTION:
{
_pub.FillDiscovery(discoveryMsg);
break;
Expand Down Expand Up @@ -1082,12 +1144,10 @@ namespace ignition
{
uint16_t msgSize;

// ByteSizeLong appeared in version 3.1 of Protobuf, and ByteSize
// became deprecated.
#if GOOGLE_PROTOBUF_VERSION < 3001000
int msgSizeFull = _msg.ByteSize();
#else
#if GOOGLE_PROTOBUF_VERSION >= 3004000
size_t msgSizeFull = _msg.ByteSizeLong();
#else
int msgSizeFull = _msg.ByteSize();
#endif
if (msgSizeFull + sizeof(msgSize) > this->kMaxRcvStr)
{
Expand Down Expand Up @@ -1135,12 +1195,10 @@ namespace ignition
{
uint16_t msgSize;

// ByteSizeLong appeared in version 3.1 of Protobuf, and ByteSize
// became deprecated.
#if GOOGLE_PROTOBUF_VERSION < 3001000
int msgSizeFull = _msg.ByteSize();
#else
#if GOOGLE_PROTOBUF_VERSION >= 3004000
size_t msgSizeFull = _msg.ByteSizeLong();
#else
int msgSizeFull = _msg.ByteSize();
#endif
if (msgSizeFull + sizeof(msgSize) > this->kMaxRcvStr)
{
Expand All @@ -1160,6 +1218,7 @@ namespace ignition
// sockets.
for (const auto &sock : this->Sockets())
{
errno = 0;
if (sendto(sock, reinterpret_cast<const raw_type *>(
reinterpret_cast<const unsigned char*>(buffer)),
totalSize, 0,
Expand Down Expand Up @@ -1342,6 +1401,14 @@ namespace ignition
/// \brief Callback executed when new topics are invalid.
private: DiscoveryCallback<Pub> disconnectionCb;

/// \brief Callback executed when a new remote subscriber is registered.
/// ToDo: Remove static when possible.
private: inline static DiscoveryCallback<Pub> registrationCb;

/// \brief Callback executed when a new remote subscriber is unregistered.
/// ToDo: Remove static when possible.
private: inline static DiscoveryCallback<Pub> unregistrationCb;

/// \brief Addressing information.
private: TopicStorage<Pub> info;

Expand Down
10 changes: 10 additions & 0 deletions include/ignition/transport/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef IGN_TRANSPORT_HELPERS_HH_
#define IGN_TRANSPORT_HELPERS_HH_

#include <zmq.h>

#include <cstdint>
#include <cstdio>
#include <cstring>
Expand All @@ -28,6 +30,14 @@
#include "ignition/transport/config.hh"
#include "ignition/transport/Export.hh"

#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)

// Avoid using deprecated message send/receive function when possible.
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 4, 0)
#define IGN_ZMQ_POST_4_4_0
#endif

namespace ignition
{
namespace transport
Expand Down
3 changes: 3 additions & 0 deletions include/ignition/transport/NetUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace ignition

/// \brief Determine your login name.
/// \return Name used to gain access to the computer.
/// On linux and Mac only, if determination
/// of your login name failes then a string of the form "error-UUID"
/// is returned where UUID is a universally unique identifier.
std::string IGNITION_TRANSPORT_VISIBLE username();
}
}
Expand Down
24 changes: 24 additions & 0 deletions include/ignition/transport/Node.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ namespace ignition
// Forward declarations.
class NodePrivate;

/// \brief Get the capacity of the buffer (High Water Mark)
/// that stores incoming Ignition Transport messages. Note that this is a
/// global queue shared by all subscribers within the same process.
/// \return The capacity of the buffer storing incoming messages (units are
/// messages). A value of 0 indicates an unlimited buffer and -1
/// that the socket cannot be queried. The default buffer size is
/// contained in the #kDefaultRcvHwm variable.
/// If the buffer is set to unlimited, then your buffer will grow until
/// you run out of memory (and probably crash).
/// If your buffer reaches the maximum capacity data will be dropped.
int IGNITION_TRANSPORT_VISIBLE rcvHwm();

/// \brief Get the capacity of the buffer (High Water Mark)
/// that stores outgoing Ignition Transport messages. Note that this is a
/// global queue shared by all publishers within the same process.
/// \return The capacity of the buffer storing outgoing messages (units are
/// messages). A value of 0 indicates an unlimited buffer and -1
/// that the socket cannot be queried. The default buffer size is
/// contained in the #kDefaultSndHwm variable.
/// If the buffer is set to unlimited, then your buffer will grow until
/// you run out of memory (and probably crash).
/// If your buffer reaches the maximum capacity data will be dropped.
int IGNITION_TRANSPORT_VISIBLE sndHwm();

/// \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.
Expand Down
33 changes: 33 additions & 0 deletions include/ignition/transport/NodeShared.hh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ namespace ignition

/// \brief Method in charge of receiving the control updates (when a new
/// remote subscriber notifies its presence for example).
/// ToDo: Remove this function when possible.
public: void RecvControlUpdate();

/// \brief Method in charge of receiving the service call requests.
Expand Down Expand Up @@ -219,6 +220,14 @@ namespace ignition
/// \param[in] _pub Information of the publisher in charge of the service.
public: void OnNewSrvDisconnection(const ServicePublisher &_pub);

/// \brief Callback executed when a remote subscriber connects.
/// \param[in] _pub Information of the remote subscriber.
public: void OnNewRegistration(const MessagePublisher &_pub);

/// \brief Callback executed when a remote subscriber unregisters.
/// \param[in] _pub Information of the remote subscriber.
public: void OnEndRegistration(const MessagePublisher &_pub);

/// \brief Pass through to bool Publishers(const std::string &_topic,
/// Addresses_M<Pub> &_publishers) const
/// \param[in] _topic Service name.
Expand All @@ -245,6 +254,30 @@ namespace ignition
/// \sa Pass through to bool Advertise(const Pub &_publisher)
public: bool AdvertisePublisher(const ServicePublisher &_publisher);

/// \brief Get the capacity of the buffer (High Water Mark)
/// that stores incoming Ignition Transport messages. Note that this is a
/// global queue shared by all subscribers within the same process.
/// \return The capacity of the buffer storing incoming messages (units
/// are messages). A value of 0 indicates an unlimited buffer and -1
/// that the socket cannot be queried. The default buffer size is
/// contained in the #kDefaultRcvHwm variable.
/// If the buffer is set to unlimited, then your buffer will grow until
/// you run out of memory (and probably crash).
/// If your buffer reaches the maximum capacity data will be dropped.
public: int RcvHwm();

/// \brief Get the capacity of the buffer (High Water Mark)
/// that stores outgoing Ignition Transport messages. Note that this is a
/// global queue shared by all publishers within the same process.
/// \return The capacity of the buffer storing outgoing messages (units
/// are messages). A value of 0 indicates an unlimited buffer and -1
/// that the socket cannot be queried. The default buffer size is
/// contained in the #kDefaultSndHwm variable.
/// If the buffer is set to unlimited, then your buffer will grow until
/// you run out of memory (and probably crash).
/// If your buffer reaches the maximum capacity data will be dropped.
public: int SndHwm();

/// \brief Constructor.
protected: NodeShared();

Expand Down
3 changes: 1 addition & 2 deletions include/ignition/transport/Packet.hh
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ namespace ignition
private: transport::Header header;

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::string
// Disable warning C4251 which is triggered by std::string
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
Expand Down
8 changes: 8 additions & 0 deletions include/ignition/transport/TransportTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ namespace ignition

/// \brief The string type used for generic messages.
const std::string kGenericMessageType = "google.protobuf.Message";

/// \brief The high water mark of the recieve message buffer.
/// \sa NodeShared::RcvHwm
const int kDefaultRcvHwm = 1000;

/// \brief The high water mark of the send message buffer.
/// \sa NodeShared::SndHwm
const int kDefaultSndHwm = 1000;
}
}
}
Expand Down
Loading

0 comments on commit 09723c4

Please sign in to comment.