iceoryx_posh 2.0.3
publisher_impl.hpp
1// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2020 - 2022 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
18#ifndef IOX_POSH_POPO_TYPED_PUBLISHER_IMPL_HPP
19#define IOX_POSH_POPO_TYPED_PUBLISHER_IMPL_HPP
20
21#include "iceoryx_hoofs/cxx/type_traits.hpp"
22#include "iceoryx_posh/internal/popo/base_publisher.hpp"
23#include "iceoryx_posh/internal/popo/publisher_interface.hpp"
24#include "iceoryx_posh/internal/popo/typed_port_api_trait.hpp"
25#include "iceoryx_posh/popo/sample.hpp"
26
27namespace iox
28{
29namespace popo
30{
33template <typename T, typename H = mepoo::NoUserHeader, typename BasePublisherType = BasePublisher<>>
34class PublisherImpl : public BasePublisherType, private PublisherInterface<T, H>
35{
36 using DataTypeAssert = typename TypedPortApiTrait<T>::Assert;
37 using HeaderTypeAssert = typename TypedPortApiTrait<H>::Assert;
38
39 public:
40 explicit PublisherImpl(const capro::ServiceDescription& service,
41 const PublisherOptions& publisherOptions = PublisherOptions());
42 PublisherImpl(const PublisherImpl& other) = delete;
43 PublisherImpl& operator=(const PublisherImpl&) = delete;
44 PublisherImpl(PublisherImpl&& rhs) = delete;
45 PublisherImpl& operator=(PublisherImpl&& rhs) = delete;
46 virtual ~PublisherImpl() = default;
47
55 template <typename... Args>
56 cxx::expected<Sample<T, H>, AllocationError> loan(Args&&... args) noexcept;
57
62 void publish(Sample<T, H>&& sample) noexcept override;
63
69 cxx::expected<AllocationError> publishCopyOf(const T& val) noexcept;
76 template <typename Callable, typename... ArgTypes>
77 cxx::expected<AllocationError> publishResultOf(Callable c, ArgTypes... args) noexcept;
78
79 protected:
80 using BasePublisherType::port;
81
82 private:
83 Sample<T, H> convertChunkHeaderToSample(mepoo::ChunkHeader* const header) noexcept;
84
85 cxx::expected<Sample<T, H>, AllocationError> loanSample() noexcept;
86
87 using PublisherSampleDeleter = SampleDeleter<typename BasePublisherType::PortType>;
88 PublisherSampleDeleter m_sampleDeleter{port()};
89};
90
91} // namespace popo
92} // namespace iox
93
94#include "iceoryx_posh/internal/popo/publisher_impl.inl"
95
96#endif // IOX_POSH_POPO_TYPED_PUBLISHER_IMPL_HPP
class for the identification of a communication event including information on the service,...
Definition: service_description.hpp:81
const port_t & port() const noexcept
port
The PublisherImpl class implements the typed publisher API.
Definition: publisher_impl.hpp:35
cxx::expected< AllocationError > publishResultOf(Callable c, ArgTypes... args) noexcept
publishResultOf Loan a sample from memory, execute the provided callable to write to it,...
cxx::expected< AllocationError > publishCopyOf(const T &val) noexcept
publishCopyOf Copy the provided value into a loaned shared memory chunk and publish it.
void publish(Sample< T, H > &&sample) noexcept override
publish Publishes the given sample and then releases its loan.
cxx::expected< Sample< T, H >, AllocationError > loan(Args &&... args) noexcept
loan Get a sample from loaned shared memory and consctruct the data with the given arguments.
Definition: sample.hpp:32
The Sample class is a mutable abstraction over types which are written to loaned shared memory....
Definition: sample.hpp:38
Definition: chunk_header.hpp:42
This struct is used to configure the publisher.
Definition: publisher_options.hpp:33