iceoryx_doc  1.0.1
publisher_port_user.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 // SPDX-License-Identifier: Apache-2.0
17 #ifndef IOX_POSH_POPO_PORTS_PUBLISHER_PORT_USER_HPP
18 #define IOX_POSH_POPO_PORTS_PUBLISHER_PORT_USER_HPP
19 
20 #include "iceoryx_posh/internal/popo/building_blocks/chunk_distributor.hpp"
21 #include "iceoryx_posh/internal/popo/building_blocks/chunk_sender.hpp"
22 #include "iceoryx_posh/internal/popo/ports/base_port.hpp"
23 #include "iceoryx_posh/internal/popo/ports/publisher_port_data.hpp"
24 #include "iceoryx_posh/mepoo/chunk_header.hpp"
25 #include "iceoryx_utils/cxx/expected.hpp"
26 #include "iceoryx_utils/cxx/helplets.hpp"
27 #include "iceoryx_utils/cxx/optional.hpp"
28 #include "iceoryx_utils/error_handling/error_handling.hpp"
29 
30 namespace iox
31 {
32 namespace popo
33 {
39 {
40  public:
42 
43  explicit PublisherPortUser(cxx::not_null<MemberType_t* const> publisherPortDataPtr) noexcept;
44 
45  PublisherPortUser(const PublisherPortUser& other) = delete;
46  PublisherPortUser& operator=(const PublisherPortUser&) = delete;
47  PublisherPortUser(PublisherPortUser&& rhs) = default;
48  PublisherPortUser& operator=(PublisherPortUser&& rhs) = default;
49  ~PublisherPortUser() = default;
50 
60  cxx::expected<mepoo::ChunkHeader*, AllocationError>
61  tryAllocateChunk(const uint32_t userPayloadSize,
62  const uint32_t userPayloadAlignment,
63  const uint32_t userHeaderSize = 0U,
64  const uint32_t userHeaderAlignment = 1U) noexcept;
65 
68  void releaseChunk(mepoo::ChunkHeader* const chunkHeader) noexcept;
69 
72  void sendChunk(mepoo::ChunkHeader* const chunkHeader) noexcept;
73 
76  cxx::optional<const mepoo::ChunkHeader*> tryGetPreviousChunk() const noexcept;
77 
79  void offer() noexcept;
80 
82  void stopOffer() noexcept;
83 
86  bool isOffered() const noexcept;
87 
90  bool hasSubscribers() const noexcept;
91 
92  private:
93  const MemberType_t* getMembers() const noexcept;
94  MemberType_t* getMembers() noexcept;
95 
96  ChunkSender<PublisherPortData::ChunkSenderData_t> m_chunkSender;
97 };
98 
99 } // namespace popo
100 } // namespace iox
101 
102 #endif // IOX_POSH_POPO_PORTS_PUBLISHER_PORT_USER_HPP
this class is the base for all ports. it is constructed from a member pointer and is only movable....
Definition: base_port.hpp:43
The ChunkSender is a building block of the shared memory communication infrastructure....
Definition: chunk_sender.hpp:49
The PublisherPortUser provides the API for accessing a publisher port from the user side....
Definition: publisher_port_user.hpp:39
void stopOffer() noexcept
stop offering this publisher port, all subscribers will be removed from this publisher
bool hasSubscribers() const noexcept
Checks whether there are currently subscribers connected to this publisher.
bool isOffered() const noexcept
Checks whether the publisher port is currently offered.
void sendChunk(mepoo::ChunkHeader *const chunkHeader) noexcept
Send an allocated chunk to all connected subscriber ports.
cxx::optional< const mepoo::ChunkHeader * > tryGetPreviousChunk() const noexcept
Returns the last sent chunk if there is one.
void releaseChunk(mepoo::ChunkHeader *const chunkHeader) noexcept
Free an allocated chunk without sending it.
cxx::expected< mepoo::ChunkHeader *, AllocationError > tryAllocateChunk(const uint32_t userPayloadSize, const uint32_t userPayloadAlignment, const uint32_t userHeaderSize=0U, const uint32_t userHeaderAlignment=1U) noexcept
Allocate a chunk, the ownership of the SharedChunk remains in the PublisherPortUser for being able to...
void offer() noexcept
offer this publiher port in the system
Definition: service_description.hpp:29
Defines different base port data.
Definition: base_port_data.hpp:34
Definition: publisher_port_data.hpp:39