diff --git a/include/ignition/transport/AdvertiseOptions.hh b/include/ignition/transport/AdvertiseOptions.hh index b561e84d2..54f4d6e15 100644 --- a/include/ignition/transport/AdvertiseOptions.hh +++ b/include/ignition/transport/AdvertiseOptions.hh @@ -114,22 +114,6 @@ namespace ignition /// \sa Scope_t. public: void SetScope(const Scope_t &_scope); - /// \brief Serialize the options. The caller has ownership of the - /// buffer and is responsible for its [de]allocation. - /// \param[out] _buffer Destination buffer in which the options - /// will be serialized. - /// \return Number of bytes serialized. - public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const; - - /// \brief Deserialize and set the options. The input buffer is - /// unpacked and used to set this object's options. - /// \param[in] _buffer Input buffer with the data to be deserialized. - public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer); - - /// \brief Get the total length of the message. - /// \return Return the length of the message in bytes. - public: size_t IGN_DEPRECATED(8) MsgLength() const; - #ifdef _WIN32 // Disable warning C4251 which is triggered by // std::unique_ptr @@ -213,21 +197,6 @@ namespace ignition /// \param[in] _newMsgsPerSec Maximum number of messages per second. public: void SetMsgsPerSec(const uint64_t _newMsgsPerSec); - /// \brief Serialize the options. The caller has ownership of the - /// buffer and is responsible for its [de]allocation. - /// \param[out] _buffer Destination buffer in which the options - /// will be serialized. - /// \return Number of bytes serialized. - public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const; - - /// \brief Unserialize the options. - /// \param[in] _buffer Input buffer with the data to be unserialized. - public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer); - - /// \brief Get the total length of the message. - /// \return Return the length of the message in bytes. - public: size_t IGN_DEPRECATED(8) MsgLength() const; - #ifdef _WIN32 // Disable warning C4251 which is triggered by // std::unique_ptr @@ -285,21 +254,6 @@ namespace ignition return _out; } - /// \brief Serialize the options. The caller has ownership of the - /// buffer and is responsible for its [de]allocation. - /// \param[out] _buffer Destination buffer in which the options - /// will be serialized. - /// \return Number of bytes serialized. - public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const; - - /// \brief Unserialize the options. - /// \param[in] _buffer Input buffer with the data to be unserialized. - public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer); - - /// \brief Get the total length of the message. - /// \return Return the length of the message in bytes. - public: size_t IGN_DEPRECATED(8) MsgLength() const; - #ifdef _WIN32 // Disable warning C4251 which is triggered by // std::unique_ptr diff --git a/include/ignition/transport/NodeShared.hh b/include/ignition/transport/NodeShared.hh index cb65697c7..67f2e70e9 100644 --- a/include/ignition/transport/NodeShared.hh +++ b/include/ignition/transport/NodeShared.hh @@ -160,19 +160,6 @@ namespace ignition const std::string &_topic, const std::string &_msgType) const; - /// \brief Call the SubscriptionHandler callbacks (local and raw) for this - /// NodeShared. - /// \param[in] _topic The topic name - /// \param[in] _msgData The raw serialized data for the message - /// \param[in] _msgType The name of the message type - /// \param[in] _handlerInfo Information for the handlers of this node, - /// as generated by CheckHandlerInfo(const std::string&) const - public: void IGN_DEPRECATED(8.0) TriggerSubscriberCallbacks( - const std::string &_topic, - const std::string &_msgData, - const std::string &_msgType, - const HandlerInfo &_handlerInfo); - /// \brief Call the SubscriptionHandler callbacks (local and raw) for this /// NodeShared. /// \param[in] _info Message information. diff --git a/include/ignition/transport/Packet.hh b/include/ignition/transport/Packet.hh index d5cc1e69d..ea7117ff0 100644 --- a/include/ignition/transport/Packet.hh +++ b/include/ignition/transport/Packet.hh @@ -59,318 +59,6 @@ namespace ignition "UNINITIALIZED", "ADVERTISE", "SUBSCRIBE", "UNADVERTISE", "HEARTBEAT", "BYE", "NEW_CONNECTION", "END_CONNECTION" }; - - /// \class Header Packet.hh ignition/transport/Packet.hh - /// \brief Header included in each discovery message containing the version - /// of the discovery protocol, the process UUID of the sender node, the type - /// of message (ADV, SUB, ... ) and optional flags. - /// \deprecated This class is deprecated. Discovery uses the - /// ignition::msgs::Discovery message. - class IGNITION_TRANSPORT_VISIBLE Header - { - /// \brief Constructor. - public: IGN_DEPRECATED(8) Header() = default; - - /// \brief Constructor. - /// \param[in] _version Version of the discovery protocol. - /// \param[in] _pUuid Every process has a unique UUID. - /// \param[in] _type Message type (ADVERTISE, SUBSCRIPTION, ...) - /// \param[in] _flags Optional flags included in the header. - public: IGN_DEPRECATED(8) Header(const uint16_t _version, - const std::string &_pUuid, - const uint8_t _type, - const uint16_t _flags = 0); - - /// \brief Destructor. - public: virtual ~Header() = default; - - /// \brief Get the discovery protocol version. - /// \return The discovery protocol version. - /// \sa SetVersion. - public: uint16_t Version() const; - - /// \brief Get the process uuid. - /// \return A unique global identifier for every process. - /// \sa SetPUuid. - public: std::string PUuid() const; - - /// \brief Get the message type. - /// \return Message type (ADVERTISE, SUBSCRIPTION, ...) - /// \sa SetType. - public: uint8_t Type() const; - - /// \brief Get the message flags. - /// \return Message flags used for compression or other optional features. - /// \sa SetFlags. - public: uint16_t Flags() const; - - /// \brief Set the discovery protocol version. - /// \param[in] _version Discovery protocol version. - /// \sa Version. - public: void SetVersion(const uint16_t _version); - - /// \brief Set the process uuid. - /// \param[in] _pUuid A unique global identifier for every process. - /// \sa PUuid. - public: void SetPUuid(const std::string &_pUuid); - - /// \brief Set the message type. - /// \param[in] _type Message type (ADVERTISE, SUBSCRIPTION, ...). - /// \sa Type. - public: void SetType(const uint8_t _type); - - /// \brief Set the message flags. - /// \param[in] _flags Used for enable optional features. - /// \sa Flags. - public: void SetFlags(const uint16_t _flags); - - /// \brief Get the header length. - /// \return The header length in bytes. - public: int HeaderLength() const; - - /// \brief Serialize the header. The caller has ownership of the - /// buffer and is responsible for its [de]allocation. - /// \param[out] _buffer Destination buffer in which the header - /// will be serialized. - /// \return Number of bytes serialized. - public: size_t Pack(char *_buffer) const; - - /// \brief Unserialize the header. - /// \param[in] _buffer Input buffer with the data to be unserialized. - public: size_t Unpack(const char *_buffer); - - /// \brief Stream insertion operator. - /// \param[out] _out The output stream. - /// \param[in] _msg Header to write to the stream. - public: friend std::ostream &operator<<(std::ostream &_out, - const Header &_header) - { - _out << "--------------------------------------\n" - << "Header:" << std::endl - << "\tVersion: " << _header.Version() << "\n" - << "\tProcess UUID: " << _header.PUuid() << "\n" - << "\tType: " << MsgTypesStr.at(_header.Type()) << "\n" - << "\tFlags: " << _header.Flags() << "\n"; - return _out; - } - - /// \brief Discovery protocol version. - private: uint16_t version = 0; - -#ifdef _WIN32 -// Disable warning C4251 which is triggered by -// std::string -#pragma warning(push) -#pragma warning(disable: 4251) -#endif - /// \brief Global identifier. Every process has a unique UUID. - private: std::string pUuid = ""; -#ifdef _WIN32 -#pragma warning(pop) -#endif - - /// \brief Message type (ADVERTISE, SUBSCRIPTION, ...). - private: uint8_t type = Uninitialized; - - /// \brief Optional flags that you want to include in the header. - private: uint16_t flags = 0; - }; - - /// \class SubscriptionMsg Packet.hh ignition/transport/Packet.hh - /// \brief Subscription packet used in the discovery protocol for requesting - /// information about a given topic. - /// \deprecated This class is deprecated. Discovery uses the - /// ignition::msgs::Discovery message. - class IGNITION_TRANSPORT_VISIBLE SubscriptionMsg - { - /// \brief Constructor. - public: IGN_DEPRECATED(8) SubscriptionMsg() = default; - - /// \brief Constructor. - /// \param[in] _header Message header. - /// \param[in] _topic Topic name. - public: IGN_DEPRECATED(8) SubscriptionMsg( - const transport::Header &_header, - const std::string &_topic); - - /// \brief Get the message header. - /// \return Reference to the message header. - /// \sa SetHeader. - public: transport::Header Header() const; - - /// \brief Get the topic. - /// \return Topic name. - /// \sa SetTopic. - public: std::string Topic() const; - - /// \brief Set the header of the message. - /// \param[in] _header Message header. - /// \sa Header. - public: void SetHeader(const transport::Header &_header); - - /// \brief Set the topic. - /// \param[in] _topic Topic name. - /// \sa Topic. - public: void SetTopic(const std::string &_topic); - - /// \brief Get the total length of the message. - /// \return Return the length of the message in bytes. - public: size_t MsgLength() const; - - /// \brief Stream insertion operator. - /// \param[out] _out The output stream. - /// \param[in] _msg SubscriptionMsg message to write to the stream. - public: friend std::ostream &operator<<(std::ostream &_out, - const SubscriptionMsg &_msg) - { - _out << _msg.Header() - << "Body:" << std::endl - << "\tTopic: [" << _msg.Topic() << "]" << std::endl; - - return _out; - } - - /// \brief Serialize the subscription message. - /// \param[out] _buffer Buffer where the message will be serialized. - /// \return The length of the serialized message in bytes. - public: size_t Pack(char *_buffer) const; - - /// \brief Unserialize a stream of bytes into a Sub. - /// \param[out] _buffer Unpack the body from the buffer. - /// \return The number of bytes from the body. - public: size_t Unpack(const char *_buffer); - - /// \brief Message header. - private: transport::Header header; - -#ifdef _WIN32 -// Disable warning C4251 which is triggered by std::string -#pragma warning(push) -#pragma warning(disable: 4251) -#endif - /// \brief Topic. - private: std::string topic = ""; -#ifdef _WIN32 -#pragma warning(pop) -#endif - }; - - /// \class AdvertiseMessage Packet.hh ignition/transport/Packet.hh - /// \brief Advertise packet used in the discovery protocol to broadcast - /// information about the node advertising a topic. The information sent - /// contains the name of the protobuf message type advertised. This message - /// is used for advertising messages and services. 'T' is the Publisher - /// type used inside this AdvertiseMessage object. - /// \deprecated This class is deprecated. Discovery uses the - /// ignition::msgs::Discovery message. - template class AdvertiseMessage - { - /// \brief Constructor. - public: IGN_DEPRECATED(8) AdvertiseMessage() = default; - - /// \brief Constructor. - /// \param[in] _header Message header. - /// \param[in] _publisher Contains the topic name, UUIDs, addresses. - public: IGN_DEPRECATED(8) AdvertiseMessage(const Header &_header, - const T &_publisher) - : header(_header), - publisher(_publisher) - { - } - - /// \brief Get the message header. - /// \return Reference to the message header. - /// \sa SetHeader. - public: transport::Header Header() const - { - return this->header; - } - - /// \brief Get the publisher of this message. - /// \return Publisher. - /// \sa SetPublisher. - public: T& Publisher() - { - return this->publisher; - } - - /// \brief Set the header of the message. - /// \param[in] _header Message header. - /// \sa Header. - public: void SetHeader(const transport::Header &_header) - { - this->header = _header; - } - - /// \brief Set the publisher of this message. - /// \param[in] _publisher New publisher. - /// \sa Publisher. - public: void SetPublisher(const T &_publisher) - { - this->publisher = _publisher; - } - - /// \brief Get the total length of the message. - /// \return Return the length of the message in bytes. - public: size_t MsgLength() const - { - return this->header.HeaderLength() + this->publisher.MsgLength(); - } - - /// \brief Serialize the advertise message. - /// \param[out] _buffer Buffer where the message will be serialized. - /// \return The length of the serialized message in bytes. - public: size_t Pack(char *_buffer) const - { - // Pack the common part of any advertise message. - size_t len = this->header.Pack(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Pack the part of the publisher. - if (this->publisher.Pack(_buffer) == 0) - return 0; - - return this->MsgLength(); - } - - /// \brief Unserialize a stream of bytes into an AdvertiseMessage. - /// \param[out] _buffer Unpack the body from the buffer. - /// \return The number of bytes from the body. - public: size_t Unpack(const char *_buffer) - { - // Unpack the message publisher. - if (this->publisher.Unpack(_buffer) == 0) - return 0; - - return this->publisher.MsgLength(); - } - - /// \brief Set from discovery message. - /// \param[in] _msg Discovery message. - public: void SetFromDiscovery(const msgs::Discovery &_msg) - { - this->publisher.SetFromDiscovery(_msg); - } - - /// \brief Stream insertion operator. - /// \param[out] _out The output stream. - /// \param[in] _msg AdvertiseMsg to write to the stream. - public: friend std::ostream &operator<<(std::ostream &_out, - const AdvertiseMessage &_msg) - { - _out << _msg.header << _msg.publisher; - return _out; - } - - /// \brief The name of the protobuf message advertised. - private: transport::Header header; - - /// \brief Publisher information (topic, ZMQ address, UUIDs, etc.). - private: T publisher; - }; } } } diff --git a/include/ignition/transport/Publisher.hh b/include/ignition/transport/Publisher.hh index e1a2d2f23..7f51779fb 100644 --- a/include/ignition/transport/Publisher.hh +++ b/include/ignition/transport/Publisher.hh @@ -115,21 +115,6 @@ namespace ignition /// \sa Options. public: void SetOptions(const AdvertiseOptions &_opts); - /// \brief Serialize the publisher. The caller has ownership of the - /// buffer and is responsible for its [de]allocation. - /// \param[out] _buffer Destination buffer in which the publisher - /// will be serialized. - /// \return Number of bytes serialized. - public: virtual size_t IGN_DEPRECATED(8) Pack(char *_buffer) const; - - /// \brief Unserialize the publisher. - /// \param[in] _buffer Input buffer with the data to be unserialized. - public: virtual size_t IGN_DEPRECATED(8) Unpack(const char *_buffer); - - /// \brief Get the total length of the message. - /// \return Return the length of the message in bytes. - public: virtual size_t IGN_DEPRECATED(8) MsgLength() const; - /// \brief Populate a discovery message. /// \param[in] _msg Message to fill. public: virtual void FillDiscovery(msgs::Discovery &_msg) const; @@ -173,23 +158,6 @@ namespace ignition return _out; } - /// \brief Serialize all fields except the advertise options. This is - /// useful when we are serializing a derived class that contains its own - /// advertise options. - protected: size_t IGN_DEPRECATED(8) PackInternal(char *_buffer) const; - - /// \brief Unserialize all fields except the advertise options. This is - /// useful when we are unserializing a derived class that contains its own - /// advertise options. - protected: size_t IGN_DEPRECATED(8) UnpackInternal(const char *_buffer); - - /// \brief Get the total length of the message without counting the - /// advertised options. This is useful when [un]serializing a derived - /// publisher because we want to ignore the advertised options in the base - /// publisher. - /// \return Return the length of the message in bytes. - protected: size_t IGN_DEPRECATED(8) MsgLengthInternal() const; - #ifdef _WIN32 // Disable warning C4251 which is triggered by // std::string @@ -247,15 +215,6 @@ namespace ignition /// \brief Destructor. public: virtual ~MessagePublisher() = default; - // Documentation inherited. - public: virtual size_t IGN_DEPRECATED(8) Pack(char *_buffer) const; - - // Documentation inherited. - public: virtual size_t IGN_DEPRECATED(8) Unpack(const char *_buffer); - - // Documentation inherited. - public: virtual size_t IGN_DEPRECATED(8) MsgLength() const; - /// \brief Get the ZeroMQ control address. This address is used by the /// subscribers to notify the publisher about the new subscription. /// \return ZeroMQ control address of the publisher. @@ -382,15 +341,6 @@ namespace ignition /// \brief Destructor. public: virtual ~ServicePublisher() = default; - // Documentation inherited. - public: size_t IGN_DEPRECATED(8) Pack(char *_buffer) const; - - // Documentation inherited. - public: size_t IGN_DEPRECATED(8) Unpack(const char *_buffer); - - // Documentation inherited. - public: size_t IGN_DEPRECATED(8) MsgLength() const; - /// \brief Get the ZeroMQ socket ID used by this publisher. /// \return The socket ID. /// \sa SetSocketId. diff --git a/src/AdvertiseOptions.cc b/src/AdvertiseOptions.cc index 9a3fb83b5..042e1c654 100644 --- a/src/AdvertiseOptions.cc +++ b/src/AdvertiseOptions.cc @@ -122,55 +122,6 @@ void AdvertiseOptions::SetScope(const Scope_t &_scope) this->dataPtr->scope = _scope; } -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif -////////////////////////////////////////////////// -size_t AdvertiseOptions::Pack(char *_buffer) const -{ - // null buffer. - if (!_buffer) - { - std::cerr << "AdvertiseOptions::Pack() error: NULL output buffer" - << std::endl; - return 0; - } - - // Pack the scope. - uint8_t intscope = static_cast(this->Scope()); - memcpy(_buffer, &intscope, sizeof(intscope)); - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t AdvertiseOptions::Unpack(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "AdvertiseOptions::Unpack() error: NULL input buffer" - << std::endl; - return 0; - } - - uint8_t intscope; - memcpy(&intscope, _buffer, sizeof(intscope)); - this->SetScope(static_cast(intscope)); - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t AdvertiseOptions::MsgLength() const -{ - return sizeof(uint8_t); -} -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif - ////////////////////////////////////////////////// AdvertiseMessageOptions::AdvertiseMessageOptions() : AdvertiseOptions(), @@ -233,71 +184,6 @@ void AdvertiseMessageOptions::SetMsgsPerSec(const uint64_t _newMsgsPerSec) this->dataPtr->msgsPerSec = _newMsgsPerSec; } -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif -////////////////////////////////////////////////// -size_t AdvertiseMessageOptions::Pack(char *_buffer) const -{ - // null buffer. - if (!_buffer) - { - std::cerr << "AdvertiseMessageOptions::Pack() error: NULL output buffer" - << std::endl; - return 0; - } - - // Pack the common part of any Advertise object. - size_t len = AdvertiseOptions::Pack(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Pack the msgsPerSec. - memcpy(_buffer, &this->dataPtr->msgsPerSec, - sizeof(this->dataPtr->msgsPerSec)); - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t AdvertiseMessageOptions::Unpack(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "AdvertiseMessageOptions::Unpack() error: NULL input buffer" - << std::endl; - return 0; - } - - // Unpack the common part of any Advertise object. - size_t len = AdvertiseOptions::Unpack(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Unpack the msgsPerSec. - uint64_t newMsgsPerSec; - memcpy(&newMsgsPerSec, _buffer, sizeof(newMsgsPerSec)); - this->SetMsgsPerSec(newMsgsPerSec); - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t AdvertiseMessageOptions::MsgLength() const -{ - return AdvertiseOptions::MsgLength() + - sizeof(this->dataPtr->msgsPerSec); -} -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif - ////////////////////////////////////////////////// AdvertiseServiceOptions::AdvertiseServiceOptions() : AdvertiseOptions(), @@ -339,54 +225,3 @@ bool AdvertiseServiceOptions::operator!=( { return !(*this == _other); } - -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif -////////////////////////////////////////////////// -size_t AdvertiseServiceOptions::Pack(char *_buffer) const -{ - // null buffer. - if (!_buffer) - { - std::cerr << "AdvertiseServiceOptions::Pack() error: NULL output buffer" - << std::endl; - return 0; - } - - // Pack the common part of any Advertise object. - size_t len = AdvertiseOptions::Pack(_buffer); - if (len == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t AdvertiseServiceOptions::Unpack(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "AdvertiseServiceOptions::Unpack() error: NULL input buffer" - << std::endl; - return 0; - } - - // Unpack the common part of any Advertise object. - size_t len = AdvertiseOptions::Unpack(_buffer); - if (len == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t AdvertiseServiceOptions::MsgLength() const -{ - return AdvertiseOptions::MsgLength(); -} -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif diff --git a/src/AdvertiseOptions_TEST.cc b/src/AdvertiseOptions_TEST.cc index ec106c020..0b9ab7ed8 100644 --- a/src/AdvertiseOptions_TEST.cc +++ b/src/AdvertiseOptions_TEST.cc @@ -94,40 +94,6 @@ TEST(AdvertiseOptionsTest, accessors) EXPECT_EQ(opts.Scope(), Scope_t::HOST); } -////////////////////////////////////////////////// -/// \brief Check the serialization of an AdvertiseOptions object. -TEST(PacketTest, optionsIO) -{ -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - - AdvertiseOptions opts1; - opts1.SetScope(Scope_t::PROCESS); - std::vector buffer(opts1.MsgLength()); - - // Pack. - auto bytes = opts1.Pack(&buffer[0]); - EXPECT_EQ(bytes, opts1.MsgLength()); - - // Unpack . - AdvertiseOptions opts2; - opts2.Unpack(&buffer[0]); - - // Check that after Pack() and Unpack() the objects remain the same. - EXPECT_TRUE(opts1 == opts2); - - // Try to pack passing a NULL buffer. - EXPECT_EQ(opts2.Pack(nullptr), 0u); - - // Try to unpack passing a NULL buffer. - EXPECT_EQ(opts2.Unpack(nullptr), 0u); -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif -} - ////////////////////////////////////////////////// /// \brief Check the default constructor. TEST(AdvertiseOptionsTest, msgDefConstructor) @@ -220,41 +186,6 @@ TEST(AdvertiseOptionsTest, msgAccessors) EXPECT_TRUE(opts.Throttled()); } -////////////////////////////////////////////////// -/// \brief Check the serialization of an AdvertiseMessageOptions object. -TEST(PacketTest, msgOptionsIO) -{ -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - - AdvertiseMessageOptions opts1; - opts1.SetScope(Scope_t::PROCESS); - opts1.SetMsgsPerSec(10u); - std::vector buffer(opts1.MsgLength()); - - // Pack. - auto bytes = opts1.Pack(&buffer[0]); - EXPECT_EQ(bytes, opts1.MsgLength()); - - // Unpack . - AdvertiseMessageOptions opts2; - opts2.Unpack(&buffer[0]); - - // Check that after Pack() and Unpack() the objects remain the same. - EXPECT_TRUE(opts1 == opts2); - - // Try to pack passing a NULL buffer. - EXPECT_EQ(opts2.Pack(nullptr), 0u); - - // Try to unpack passing a NULL buffer. - EXPECT_EQ(opts2.Unpack(nullptr), 0u); -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif -} - ////////////////////////////////////////////////// /// \brief Check the default constructor. TEST(AdvertiseOptionsTest, srvDefConstructor) @@ -322,39 +253,6 @@ TEST(AdvertiseOptionsTest, srvAccessors) EXPECT_EQ(opts.Scope(), Scope_t::HOST); } -////////////////////////////////////////////////// -/// \brief Check the serialization of an AdvertiseServiceOptions object. -TEST(PacketTest, srvOptionsIO) -{ -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - AdvertiseServiceOptions opts1; - opts1.SetScope(Scope_t::PROCESS); - std::vector buffer(opts1.MsgLength()); - - // Pack. - auto bytes = opts1.Pack(&buffer[0]); - EXPECT_EQ(bytes, opts1.MsgLength()); - - // Unpack . - AdvertiseServiceOptions opts2; - opts2.Unpack(&buffer[0]); - - // Check that after Pack() and Unpack() the objects remain the same. - EXPECT_TRUE(opts1 == opts2); - - // Try to pack passing a NULL buffer. - EXPECT_EQ(opts2.Pack(nullptr), 0u); - - // Try to unpack passing a NULL buffer. - EXPECT_EQ(opts2.Unpack(nullptr), 0u); -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif -} - ////////////////////////////////////////////////// int main(int argc, char **argv) { diff --git a/src/NodeShared.cc b/src/NodeShared.cc index 3b63bd14f..543706ea4 100644 --- a/src/NodeShared.cc +++ b/src/NodeShared.cc @@ -473,20 +473,6 @@ NodeShared::SubscriberInfo NodeShared::CheckSubscriberInfo( return info; } -////////////////////////////////////////////////// -void NodeShared::TriggerSubscriberCallbacks( - const std::string &_topic, - const std::string &_msgData, - const std::string &_msgType, - const HandlerInfo &_handlerInfo) -{ - MessageInfo info; - info.SetTopicAndPartition(_topic); - info.SetType(_msgType); - - this->TriggerCallbacks(info, _msgData, _handlerInfo); -} - ////////////////////////////////////////////////// void NodeShared::TriggerCallbacks( const MessageInfo &_info, diff --git a/src/Packet.cc b/src/Packet.cc deleted file mode 100644 index 7ea5dbc86..000000000 --- a/src/Packet.cc +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (C) 2014 Open Source Robotics Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -// This whole file is deprecated in version 8 of Ignition Transport. Please -// remove this file in Version 9. -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -#include -#include -#include - -#include "ignition/transport/Packet.hh" - -using namespace ignition; -using namespace transport; - -////////////////////////////////////////////////// -Header::Header(const uint16_t _version, - const std::string &_pUuid, - const uint8_t _type, - const uint16_t _flags) -{ - this->SetVersion(_version); - this->SetPUuid(_pUuid); - this->SetType(_type); - this->SetFlags(_flags); -} - -////////////////////////////////////////////////// -uint16_t Header::Version() const -{ - return this->version; -} - -////////////////////////////////////////////////// -std::string Header::PUuid() const -{ - return this->pUuid; -} - -////////////////////////////////////////////////// -uint8_t Header::Type() const -{ - return this->type; -} - -////////////////////////////////////////////////// -uint16_t Header::Flags() const -{ - return this->flags; -} - -////////////////////////////////////////////////// -void Header::SetVersion(const uint16_t _version) -{ - this->version = _version; -} - -////////////////////////////////////////////////// -void Header::SetPUuid(const std::string &_pUuid) -{ - this->pUuid = _pUuid; -} - -////////////////////////////////////////////////// -void Header::SetType(const uint8_t _type) -{ - this->type = _type; -} - -////////////////////////////////////////////////// -void Header::SetFlags(const uint16_t _flags) -{ - this->flags = _flags; -} - -////////////////////////////////////////////////// -int Header::HeaderLength() const -{ - return static_cast(sizeof(this->version) + - sizeof(uint16_t) + this->pUuid.size() + - sizeof(this->type) + sizeof(this->flags)); -} - -////////////////////////////////////////////////// -size_t Header::Pack(char *_buffer) const -{ - // Uninitialized. - if ((this->version == 0) || (this->pUuid == "") || - (this->type == Uninitialized)) - { - std::cerr << "Header::Pack() error: You're trying to pack an incomplete " - << "header:" << std::endl << *this; - return 0; - } - - // null buffer. - if (!_buffer) - { - std::cerr << "Header::Pack() error: NULL output buffer" << std::endl; - return 0; - } - - // Pack the discovery protocol version, which is a uint16_t - memcpy(_buffer, &this->version, sizeof(this->version)); - _buffer += sizeof(this->version); - - // Pack the process UUID length. - uint16_t pUuidLength = static_cast(this->pUuid.size()); - memcpy(_buffer, &pUuidLength, sizeof(pUuidLength)); - _buffer += sizeof(pUuidLength); - - // Pack the process UUID. - memcpy(_buffer, this->pUuid.data(), static_cast(pUuidLength)); - _buffer += pUuidLength; - - // Pack the message type (ADVERTISE, SUBSCRIPTION, ...), which is uint8_t - memcpy(_buffer, &this->type, sizeof(this->type)); - _buffer += sizeof(this->type); - - // Pack the flags, which is uint16_t - memcpy(_buffer, &this->flags, sizeof(this->flags)); - - return this->HeaderLength(); -} - -////////////////////////////////////////////////// -size_t Header::Unpack(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "Header::Unpack() error: NULL input buffer" << std::endl; - return 0; - } - - // Unpack the version. - memcpy(&this->version, _buffer, sizeof(this->version)); - _buffer += sizeof(this->version); - - // Unpack the process UUID length. - uint16_t pUuidLength; - memcpy(&pUuidLength, _buffer, sizeof(pUuidLength)); - _buffer += sizeof(pUuidLength); - - // Unpack the process UUID. - this->pUuid = std::string(_buffer, _buffer + pUuidLength); - _buffer += pUuidLength; - - // Unpack the message type. - memcpy(&this->type, _buffer, sizeof(this->type)); - _buffer += sizeof(this->type); - - // Unpack the flags. - memcpy(&this->flags, _buffer, sizeof(this->flags)); - - return this->HeaderLength(); -} - -////////////////////////////////////////////////// -SubscriptionMsg::SubscriptionMsg(const transport::Header &_header, - const std::string &_topic) -{ - this->SetHeader(_header); - this->SetTopic(_topic); -} - -////////////////////////////////////////////////// -transport::Header SubscriptionMsg::Header() const -{ - return this->header; -} - -////////////////////////////////////////////////// -std::string SubscriptionMsg::Topic() const -{ - return this->topic; -} - -////////////////////////////////////////////////// -void SubscriptionMsg::SetHeader(const transport::Header &_header) -{ - this->header = _header; -} - -////////////////////////////////////////////////// -void SubscriptionMsg::SetTopic(const std::string &_topic) -{ - this->topic = _topic; -} - -////////////////////////////////////////////////// -size_t SubscriptionMsg::MsgLength() const -{ - return this->header.HeaderLength() + sizeof(uint16_t) + this->topic.size(); -} - -////////////////////////////////////////////////// -size_t SubscriptionMsg::Pack(char *_buffer) const -{ - // Pack the header. - size_t headerLen = this->Header().Pack(_buffer); - if (headerLen == 0) - return 0; - - if (this->topic == "") - { - std::cerr << "SubscriptionMsg::Pack() error: You're trying to pack a " - << "message with an empty topic" << std::endl; - return 0; - } - - _buffer += headerLen; - - // Pack the topic length. - uint16_t topicLength = static_cast(this->topic.size()); - memcpy(_buffer, &topicLength, sizeof(topicLength)); - _buffer += sizeof(topicLength); - - // Pack the topic. - memcpy(_buffer, this->topic.data(), static_cast(topicLength)); - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t SubscriptionMsg::Unpack(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "SubscriptionMsg::UnpackBody() error: NULL input buffer" - << std::endl; - return 0; - } - - // Unpack the topic length. - uint16_t topicLength; - memcpy(&topicLength, _buffer, sizeof(topicLength)); - _buffer += sizeof(topicLength); - - // Unpack the topic. - this->topic = std::string(_buffer, _buffer + topicLength); - - return sizeof(topicLength) + static_cast(topicLength); -} -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif diff --git a/src/Publisher.cc b/src/Publisher.cc index 9550bf20c..a742a2ac5 100644 --- a/src/Publisher.cc +++ b/src/Publisher.cc @@ -107,159 +107,6 @@ void Publisher::SetOptions(const AdvertiseOptions &_opts) { this->opts = _opts; } -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -////////////////////////////////////////////////// -size_t Publisher::Pack(char *_buffer) const -{ - size_t len = this->PackInternal(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Pack the options. - size_t optsLen = this->opts.Pack(_buffer); - if (optsLen == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t Publisher::PackInternal(char *_buffer) const -{ - if (this->topic.empty() || this->addr.empty() || - this->pUuid.empty() || this->nUuid.empty()) - { - std::cerr << "Publisher::Pack() error: You're trying to pack an " - << "incomplete Publisher:" << std::endl << *this; - return 0; - } - - // null buffer. - if (!_buffer) - { - std::cerr << "Publisher::Pack() error: NULL output buffer" << std::endl; - return 0; - } - - // Pack the topic length. - uint16_t topicLength = static_cast(this->topic.size()); - memcpy(_buffer, &topicLength, sizeof(topicLength)); - _buffer += sizeof(topicLength); - - // Pack the topic. - memcpy(_buffer, this->topic.data(), static_cast(topicLength)); - _buffer += topicLength; - - // Pack the zeromq address length. - uint16_t addrLength = static_cast(this->addr.size()); - memcpy(_buffer, &addrLength, sizeof(addrLength)); - _buffer += sizeof(addrLength); - - // Pack the zeromq address. - memcpy(_buffer, this->addr.data(), static_cast(addrLength)); - _buffer += addrLength; - - // Pack the process UUID length. - uint16_t pUuidLength = static_cast(this->pUuid.size()); - memcpy(_buffer, &pUuidLength, sizeof(pUuidLength)); - _buffer += sizeof(pUuidLength); - - // Pack the process UUID. - memcpy(_buffer, this->pUuid.data(), static_cast(pUuidLength)); - _buffer += pUuidLength; - - // Pack the node UUID length. - uint16_t nUuidLength = static_cast(this->nUuid.size()); - memcpy(_buffer, &nUuidLength, sizeof(nUuidLength)); - _buffer += sizeof(nUuidLength); - - // Pack the node UUID. - memcpy(_buffer, this->nUuid.data(), static_cast(nUuidLength)); - - return this->MsgLengthInternal(); -} - -////////////////////////////////////////////////// -size_t Publisher::Unpack(const char *_buffer) -{ - size_t len = this->UnpackInternal(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Unpack the options. - size_t optsLen = this->opts.Unpack(_buffer); - if (optsLen == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t Publisher::UnpackInternal(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "Publisher::Unpack() error: NULL input buffer" - << std::endl; - return 0; - } - - // Unpack the topic length. - uint16_t topicLength; - memcpy(&topicLength, _buffer, sizeof(topicLength)); - _buffer += sizeof(topicLength); - - // Unpack the topic. - this->topic = std::string(_buffer, _buffer + topicLength); - _buffer += topicLength; - - // Unpack the zeromq address length. - uint16_t addrLength; - memcpy(&addrLength, _buffer, sizeof(addrLength)); - _buffer += sizeof(addrLength); - - // Unpack the zeromq address. - this->addr = std::string(_buffer, _buffer + addrLength); - _buffer += addrLength; - - // Unpack the process UUID length. - uint16_t pUuidLength; - memcpy(&pUuidLength, _buffer, sizeof(pUuidLength)); - _buffer += sizeof(pUuidLength); - - // Unpack the process UUID. - this->pUuid = std::string(_buffer, _buffer + pUuidLength); - _buffer += pUuidLength; - - // Unpack the node UUID length. - uint16_t nUuidLength; - memcpy(&nUuidLength, _buffer, sizeof(nUuidLength)); - _buffer += sizeof(nUuidLength); - - // Unpack the node UUID. - this->nUuid = std::string(_buffer, _buffer + nUuidLength); - - return this->MsgLengthInternal(); -} - -////////////////////////////////////////////////// -size_t Publisher::MsgLength() const -{ - return this->MsgLengthInternal() + - this->opts.MsgLength(); -} -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif ////////////////////////////////////////////////// void Publisher::FillDiscovery(msgs::Discovery &_msg) const @@ -308,15 +155,6 @@ void Publisher::SetFromDiscovery(const msgs::Discovery &_msg) } } -////////////////////////////////////////////////// -size_t Publisher::MsgLengthInternal() const -{ - return sizeof(uint16_t) + this->topic.size() + - sizeof(uint16_t) + this->addr.size() + - sizeof(uint16_t) + this->pUuid.size() + - sizeof(uint16_t) + this->nUuid.size(); -} - ////////////////////////////////////////////////// bool Publisher::operator==(const Publisher &_pub) const { @@ -361,111 +199,6 @@ MessagePublisher::MessagePublisher(const MessagePublisher &_other) (*this) = _other; } -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif -////////////////////////////////////////////////// -size_t MessagePublisher::Pack(char *_buffer) const -{ - if (this->ctrl.empty() || this->msgTypeName.empty()) - { - std::cerr << "MessagePublisher::Pack() error: You're trying to pack an " - << "incomplete MessagePublisher:" << std::endl << *this; - return 0; - } - - // Pack the common part of any Publisher message except the options. - size_t len = Publisher::PackInternal(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Pack the zeromq control address length. - uint16_t ctrlLength = static_cast(this->ctrl.size()); - memcpy(_buffer, &ctrlLength, sizeof(ctrlLength)); - _buffer += sizeof(ctrlLength); - - // Pack the zeromq control address. - memcpy(_buffer, this->ctrl.data(), static_cast(ctrlLength)); - _buffer += ctrlLength; - - // Pack the type name length. - uint16_t typeNameLength = static_cast(this->msgTypeName.size()); - memcpy(_buffer, &typeNameLength, sizeof(typeNameLength)); - _buffer += sizeof(typeNameLength); - - // Pack the type name. - memcpy(_buffer, this->msgTypeName.data(), - static_cast(typeNameLength)); - _buffer += typeNameLength; - - // Pack the options. - size_t optsLen = this->msgOpts.Pack(_buffer); - if (optsLen == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t MessagePublisher::Unpack(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "MessagePublisher::UnpackBody() error: NULL input buffer" - << std::endl; - return 0; - } - - // Unpack the common part of any Publisher message except the options. - size_t len = Publisher::UnpackInternal(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Unpack the zeromq control address length. - uint16_t ctrlLength; - memcpy(&ctrlLength, _buffer, sizeof(ctrlLength)); - _buffer += sizeof(ctrlLength); - - // Unpack the zeromq control address. - this->ctrl = std::string(_buffer, _buffer + ctrlLength); - _buffer += ctrlLength; - - // Unpack the type name length. - uint16_t typeNameLength; - memcpy(&typeNameLength, _buffer, sizeof(typeNameLength)); - _buffer += sizeof(typeNameLength); - - // Unpack the type name. - this->msgTypeName = std::string(_buffer, _buffer + typeNameLength); - _buffer += typeNameLength; - - // Unpack the options. - size_t optsLen = this->msgOpts.Unpack(_buffer); - if (optsLen == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t MessagePublisher::MsgLength() const -{ - return Publisher::MsgLengthInternal() + - sizeof(uint16_t) + this->ctrl.size() + - sizeof(uint16_t) + this->msgTypeName.size() + - this->msgOpts.MsgLength(); -} -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif - - ////////////////////////////////////////////////// std::string MessagePublisher::Ctrl() const { @@ -573,129 +306,6 @@ ServicePublisher::ServicePublisher(const ServicePublisher &_other) (*this) = _other; } -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif -////////////////////////////////////////////////// -size_t ServicePublisher::Pack(char *_buffer) const -{ - if (this->socketId.empty() || this->reqTypeName.empty() || - this->repTypeName.empty()) - { - std::cerr << "ServicePublisher::Pack() error: You're trying to pack an " - << "incomplete ServicePublisher:" << std::endl << *this; - return 0; - } - - // Pack the common part of any Publisher message. - size_t len = Publisher::PackInternal(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Pack the socket ID length. - uint16_t socketIdLength = static_cast(this->socketId.size()); - memcpy(_buffer, &socketIdLength, sizeof(socketIdLength)); - _buffer += sizeof(socketIdLength); - - // Pack the socket ID. - memcpy(_buffer, this->socketId.data(), static_cast(socketIdLength)); - _buffer += socketIdLength; - - // Pack the request type length. - uint16_t reqTypeLength = static_cast(this->reqTypeName.size()); - memcpy(_buffer, &reqTypeLength, sizeof(reqTypeLength)); - _buffer += sizeof(reqTypeLength); - - // Pack the request type. - memcpy(_buffer, this->reqTypeName.data(), static_cast(reqTypeLength)); - _buffer += reqTypeLength; - - // Pack the response type length. - uint16_t repTypeLength = static_cast(this->repTypeName.size()); - memcpy(_buffer, &repTypeLength, sizeof(repTypeLength)); - _buffer += sizeof(repTypeLength); - - // Pack the response. - memcpy(_buffer, this->repTypeName.data(), static_cast(repTypeLength)); - _buffer += repTypeLength; - - // Pack the options. - size_t optsLen = this->srvOpts.Pack(_buffer); - if (optsLen == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t ServicePublisher::Unpack(const char *_buffer) -{ - // null buffer. - if (!_buffer) - { - std::cerr << "MessagePublisher::Unpack() error: NULL input buffer" - << std::endl; - return 0; - } - - // Unpack the common part of any Publisher message. - size_t len = Publisher::UnpackInternal(_buffer); - if (len == 0) - return 0; - - _buffer += len; - - // Unpack the socket ID length. - uint16_t socketIdLength; - memcpy(&socketIdLength, _buffer, sizeof(socketIdLength)); - _buffer += sizeof(socketIdLength); - - // Unpack the socket ID. - this->socketId = std::string(_buffer, _buffer + socketIdLength); - _buffer += socketIdLength; - - // Unpack the request type length. - uint16_t reqTypeLength; - memcpy(&reqTypeLength, _buffer, sizeof(reqTypeLength)); - _buffer += sizeof(reqTypeLength); - - // Unpack the request type. - this->reqTypeName = std::string(_buffer, _buffer + reqTypeLength); - _buffer += reqTypeLength; - - // Unpack the response type length. - uint16_t repTypeLength; - memcpy(&repTypeLength, _buffer, sizeof(repTypeLength)); - _buffer += sizeof(repTypeLength); - - // Unpack the response type. - this->repTypeName = std::string(_buffer, _buffer + repTypeLength); - _buffer += repTypeLength; - - // Unpack the options. - size_t optsLen = this->srvOpts.Unpack(_buffer); - if (optsLen == 0) - return 0; - - return this->MsgLength(); -} - -////////////////////////////////////////////////// -size_t ServicePublisher::MsgLength() const -{ - return Publisher::MsgLengthInternal() + - sizeof(uint16_t) + this->socketId.size() + - sizeof(uint16_t) + this->reqTypeName.size() + - sizeof(uint16_t) + this->repTypeName.size() + - this->srvOpts.MsgLength(); -} -#ifndef _WIN32 - #pragma GCC diagnostic pop -#endif - ////////////////////////////////////////////////// std::string ServicePublisher::SocketId() const {