RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
shmPublisher.hpp
Go to the documentation of this file.
1
12#ifndef RTCTK_TELSUB_SHMPUBLISHER_HPP
13#define RTCTK_TELSUB_SHMPUBLISHER_HPP
14#include <cstdint>
15#include <network/optional.hpp>
16#include <system_error>
17#include <vector>
18
19#include <ipcq/writer.hpp>
20
22
23namespace rtctk::telSub {
24
33template <class UserTopicType, class DataBlender, class ShmWriter = ipcq::Writer<UserTopicType>>
35public:
37
42 PublisherError Publish(const DataSamplesView& samples) noexcept override;
43
44 void CloseQueue() noexcept override;
45
46private:
50 UserTopicType m_topic;
51 DataBlender& m_blender;
52 ShmWriter m_shm;
53};
54
60template <class UserTopicType, class DataBlender, class ShmWriter>
62 -> std::unique_ptr<ShmPublisher<UserTopicType, DataBlender, ShmWriter>> {
63 return std::make_unique<ShmPublisher<UserTopicType, DataBlender, ShmWriter>>(
64 std::move(shm_writer), blender);
65}
66
67template <class UserTopicType, class DataBlender, class ShmWriter>
70 : m_topic(), m_blender(blender), m_shm(std::move(shm_writer)) {
71 static_assert(std::is_invocable_r<std::error_code,
74 UserTopicType&>::value,
75 "DataBlender must have the signature "
76 "`std::error_code(const rtctk::telSub::DataSamplesView&, "
77 "UserTopicType&)`");
78}
79
80template <class UserTopicType, class DataBlender, class ShmWriter>
82 const DataSamplesView& samples) noexcept {
83 // Invoke blender and write to SHM queue.
84 if (auto err = m_blender(samples, m_topic); !err) /*[[likely]]*/ {
85 auto shm_err = m_shm.Write(m_topic, ipcq::Notify::All);
86 if (shm_err) {
87 return ShmError{shm_err};
88 }
89 return {};
90 } else /*[[unlikely]]*/ {
91 return BlenderError{err};
92 }
93}
94
95template <class UserTopicType, class DataBlender, class ShmWriter>
99
100} // namespace rtctk::telSub
101
102#endif // RTCTK_TELSUB_SHMPUBLISHER_HPP
Simple interface to class that owns the shared memory queue.
Definition shmPublisherIf.hpp:31
std::variant< std::monostate, BlenderError, ShmError > PublisherError
Definition shmPublisherIf.hpp:45
Definition shmPublisher.hpp:34
PublisherError Publish(const DataSamplesView &samples) noexcept override
Publish correlated DDS samples to shared memory, transforming it first using DataBlender to a UserTop...
Definition shmPublisher.hpp:81
ShmPublisher(ShmWriter &&shm_writer, DataBlender &blender)
Definition shmPublisher.hpp:68
void CloseQueue() noexcept override
Close shared memory queue.
Definition shmPublisher.hpp:96
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Definition main.cpp:24
auto MakeShmPublisher(ShmWriter &&shm_writer, DataBlender &blender) -> std::unique_ptr< ShmPublisher< UserTopicType, DataBlender, ShmWriter > >
Helper that can deduce DataBlender class template argument.
Definition shmPublisher.hpp:61
Declares ShmPublisher.
A set of correlated agnostic non-owning data samples references.
Definition dataSampleView.hpp:52
Definition shmPublisherIf.hpp:33
Definition shmPublisherIf.hpp:39