From 227cb69b807b7ec85eb4a4f048c11b924a8a2f24 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 5 Aug 2020 19:10:37 +0200 Subject: [PATCH] iox-#218 Renamed allocate -> loan. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../experimental/internal/popo/publisher.inl | 27 ++++++++------ .../experimental/popo/publisher.hpp | 36 +++++++++++-------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/experimental/internal/popo/publisher.inl b/iceoryx_posh/include/iceoryx_posh/experimental/internal/popo/publisher.inl index d87a05bf1f..acff2675ec 100644 --- a/iceoryx_posh/include/iceoryx_posh/experimental/internal/popo/publisher.inl +++ b/iceoryx_posh/include/iceoryx_posh/experimental/internal/popo/publisher.inl @@ -29,6 +29,13 @@ using SamplePtr = iox::cxx::unique_ptr; using uid_t = uint64_t; +//template +//Publisher::Publisher(const capro::ServiceDescription& service) +// : m_port(); +//{ + +//} + template inline uid_t Publisher::uid() const noexcept @@ -39,9 +46,9 @@ Publisher::uid() const noexcept template inline cxx::expected, AllocationError> -Publisher::allocate() const noexcept +Publisher::loan() const noexcept { - return m_sender.allocateChunk(sizeof(T)) + return m_port.allocateChunk(sizeof(T)) .and_then([&](mepoo::ChunkHeader* header){ auto ptr = iox::cxx::unique_ptr(header->payload(), [this](T* const p){ this->release(p); @@ -55,9 +62,9 @@ Publisher::allocate() const noexcept template cxx::expected -Publisher::allocate(cxx::function_ref f) const noexcept +Publisher::loan(cxx::function_ref f) const noexcept { - auto result = allocate() + auto result = loan() .and_then([&f](SamplePtr s){ f(s); return cxx::success<>(); @@ -73,7 +80,7 @@ inline void Publisher::release(SamplePtr&& sample) const noexcept { auto header = iox::mepoo::convertPayloadPointerToChunkHeader(sample.release()); - m_sender.freeChunk(header); + m_port.freeChunk(header); } template @@ -81,7 +88,7 @@ inline void Publisher::publish(SamplePtr&& sample) const noexcept { auto header = iox::mepoo::convertPayloadPointerToChunkHeader(const_cast(sample.release())); - m_sender.deliverChunk(header); + m_port.deliverChunk(header); } template @@ -103,28 +110,28 @@ template inline void Publisher::offer() noexcept { - m_sender.activate(); + m_port.offer(); } template inline void Publisher::stopOffer() noexcept { - m_sender.deactivate(); + m_port.stopOffer(); } template inline bool Publisher::isOffered() const noexcept { - return m_sender.isPortActive(); + return m_port.isOffered(); } template inline bool Publisher::hasSubscribers() const noexcept { - return m_sender.hasSubscribers(); + return m_port.hasSubscribers(); } } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/experimental/popo/publisher.hpp b/iceoryx_posh/include/iceoryx_posh/experimental/popo/publisher.hpp index 10baec81bd..724c867126 100644 --- a/iceoryx_posh/include/iceoryx_posh/experimental/popo/publisher.hpp +++ b/iceoryx_posh/include/iceoryx_posh/experimental/popo/publisher.hpp @@ -46,6 +46,12 @@ class Publisher // Temporary, to be replaced with service description / id based constructors Publisher() = default; + /// + /// @brief Publisher Create publisher for specified service [legacy]. + /// @param service Service to publish to. + /// + Publisher(const capro::ServiceDescription& service); + Publisher(const Publisher& other) = delete; Publisher& operator=(const Publisher&) = delete; Publisher(Publisher&& rhs) = default; @@ -59,17 +65,17 @@ class Publisher uid_t uid() const noexcept; /// - /// @brief allocate Allocates a chunk of shared memory. - /// @return Pointer to the successfully allocated memory, otherwise an allocation error. + /// @brief loan Loan an empty sample from the shared memory pool. + /// @return Pointer to the successfully loaned sample, otherwise an allocation error. /// - cxx::expected allocate() const noexcept; + cxx::expected loan() const noexcept; /// - /// @brief allocate Allocate a chunk then execute the provided callable using the allocated chunk. - /// @param f Callable to execute, taking the allocated chunk as its parameter. - /// @return Success if chunk was successfully allocated and the provided callable was successfully executed. + /// @brief loan Loan an empty sample from the shared memory pool and process it with the given callable. + /// @param f Function to execute, taking the allocated chunk as its parameter. + /// @return Success if the loaned sample /// - cxx::expected allocate(cxx::function_ref f) const noexcept; + cxx::expected loan(cxx::function_ref f) const noexcept; /// /// @brief release Releases ownership of an unused allocated chunk. @@ -80,24 +86,24 @@ class Publisher void release(SamplePtr&& chunk) const noexcept; /// - /// @brief send Publishes the chunk to the system. - /// @details Ownership of published chunks is automatically released. + /// @brief send Publishes the loaned sample to all subscribers. + /// @details The loanded sample is automatically released after publishing. /// @param chunk /// void publish(SamplePtr&& chunk) const noexcept; /// - /// @brief copyAndPublish Copy the given sample into a shared memory chunk and immediately publish. + /// @brief copyAndPublish Copy the given sample into a loaned sample and publish it to all subscribers. /// @details This method should not be used for larger data types as it includes a copy. For larger data types, it - /// is preferred to first allocate a chunk and then directly write the data into it (e.g. with a placement new), + /// is preferred to first laon an empty sample and then directly write the data into it (e.g. with a placement new) /// rather than to write it elsewhere then copy it in. - /// @param val The value to publish. + /// @param val The value to publish /// void publishCopyOf(const T& val) const noexcept; /// - /// @brief previous Reclaims ownership of a previously published chunk if it has not yet been accessed. - /// @return The previously published chunk if one exists and is unclaimed, otherwise an error. + /// @brief previous Reclaims ownership of a previously published sample if it has not yet been accessed by subscribers. + /// @return The previously published sample if one exists and is unclaimed, otherwise an error. /// cxx::expected previous() const noexcept; @@ -107,7 +113,7 @@ class Publisher bool hasSubscribers() const noexcept; protected: - port_t m_sender{nullptr}; + port_t m_port{nullptr}; bool m_useDynamicPayloadSize = true; private: