Skip to content

Commit

Permalink
iox-eclipse-iceoryx#218 Renamed allocate -> loan.
Browse files Browse the repository at this point in the history
Signed-off-by: Ithier Jeff (CC-AD/EYF1) <[email protected]>
  • Loading branch information
orecham committed Aug 5, 2020
1 parent ad90eab commit 227cb69
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ using SamplePtr = iox::cxx::unique_ptr<T>;

using uid_t = uint64_t;

//template<typename T, typename port_t>
//Publisher<T, port_t>::Publisher(const capro::ServiceDescription& service)
// : m_port();
//{

//}

template<typename T, typename port_t>
inline uid_t
Publisher<T, port_t>::uid() const noexcept
Expand All @@ -39,9 +46,9 @@ Publisher<T, port_t>::uid() const noexcept

template<typename T, typename port_t>
inline cxx::expected<SamplePtr<T>, AllocationError>
Publisher<T, port_t>::allocate() const noexcept
Publisher<T, port_t>::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<T>(header->payload(), [this](T* const p){
this->release(p);
Expand All @@ -55,9 +62,9 @@ Publisher<T, port_t>::allocate() const noexcept

template<typename T, typename port_t>
cxx::expected<AllocationError>
Publisher<T, port_t>::allocate(cxx::function_ref<void(SamplePtr&) noexcept> f) const noexcept
Publisher<T, port_t>::loan(cxx::function_ref<void(SamplePtr&) noexcept> f) const noexcept
{
auto result = allocate()
auto result = loan()
.and_then([&f](SamplePtr s){
f(s);
return cxx::success<>();
Expand All @@ -73,15 +80,15 @@ inline void
Publisher<T, port_t>::release(SamplePtr&& sample) const noexcept
{
auto header = iox::mepoo::convertPayloadPointerToChunkHeader(sample.release());
m_sender.freeChunk(header);
m_port.freeChunk(header);
}

template<typename T, typename port_t>
inline void
Publisher<T, port_t>::publish(SamplePtr&& sample) const noexcept
{
auto header = iox::mepoo::convertPayloadPointerToChunkHeader(const_cast<void* const>(sample.release()));
m_sender.deliverChunk(header);
m_port.deliverChunk(header);
}

template<typename T, typename port_t>
Expand All @@ -103,28 +110,28 @@ template<typename T, typename port_t>
inline void
Publisher<T, port_t>::offer() noexcept
{
m_sender.activate();
m_port.offer();
}

template<typename T, typename port_t>
inline void
Publisher<T, port_t>::stopOffer() noexcept
{
m_sender.deactivate();
m_port.stopOffer();
}

template<typename T, typename port_t>
inline bool
Publisher<T, port_t>::isOffered() const noexcept
{
return m_sender.isPortActive();
return m_port.isOffered();
}

template<typename T, typename port_t>
inline bool
Publisher<T, port_t>::hasSubscribers() const noexcept
{
return m_sender.hasSubscribers();
return m_port.hasSubscribers();
}

} // namespace popo
Expand Down
36 changes: 21 additions & 15 deletions iceoryx_posh/include/iceoryx_posh/experimental/popo/publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SamplePtr, AllocationError> allocate() const noexcept;
cxx::expected<SamplePtr, AllocationError> 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<AllocationError> allocate(cxx::function_ref<void(SamplePtr&) noexcept> f) const noexcept;
cxx::expected<AllocationError> loan(cxx::function_ref<void(SamplePtr&) noexcept> f) const noexcept;

///
/// @brief release Releases ownership of an unused allocated chunk.
Expand All @@ -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<ChunkRecallError> previous() const noexcept;

Expand All @@ -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:
Expand Down

0 comments on commit 227cb69

Please sign in to comment.