38 static constexpr uint64_t MAX_MESSAGE_SIZE = 4U * 1024U;
39 static constexpr uint64_t MAX_NUMBER_OF_MESSAGES = 10U;
41 static constexpr uint64_t NULL_TERMINATOR_SIZE = 0U;
42 static constexpr units::Duration CYCLE_TIME = units::Duration::fromMilliseconds(10);
43 static constexpr const char NAMED_PIPE_PREFIX[] =
"iox_np_";
61 cxx::expected<IpcChannelError>
destroy() noexcept;
66 static cxx::expected<
bool, IpcChannelError>
unlinkIfExists(const IpcChannelName_t& name) noexcept;
70 cxx::expected<
bool, IpcChannelError>
isOutdated() noexcept;
74 cxx::expected<IpcChannelError>
trySend(const std::
string& message) const noexcept;
80 cxx::expected<IpcChannelError>
send(const std::
string& message) const noexcept;
86 cxx::expected<IpcChannelError>
timedSend(const std::
string& message, const units::Duration& timeout) const noexcept;
90 cxx::expected<std::
string, IpcChannelError>
tryReceive() const noexcept;
95 cxx::expected<std::
string, IpcChannelError>
receive() const noexcept;
100 cxx::expected<std::
string, IpcChannelError>
timedReceive(const units::Duration& timeout) const noexcept;
103 friend class DesignPattern::Creation<
NamedPipe, IpcChannelError>;
112 const IpcChannelSide channelSide,
113 const
size_t maxMsgSize = MAX_MESSAGE_SIZE,
114 const uint64_t maxMsgNumber = MAX_NUMBER_OF_MESSAGES) noexcept;
116 template <typename Prefix>
117 static IpcChannelName_t convertName(const Prefix& p, const IpcChannelName_t& name) noexcept;
120 cxx::optional<SharedMemoryObject> m_sharedMemory;
125 NamedPipeData(
bool&
isInitialized, IpcChannelError& error,
const uint64_t maxMsgNumber)
noexcept;
126 NamedPipeData(
const NamedPipeData&) =
delete;
127 NamedPipeData(NamedPipeData&& rhs) =
delete;
128 ~NamedPipeData()
noexcept;
130 NamedPipeData& operator=(
const NamedPipeData&) =
delete;
131 NamedPipeData& operator=(NamedPipeData&& rhs) =
delete;
136 bool waitForInitialization()
const noexcept;
137 bool hasValidState()
const noexcept;
142 static constexpr uint64_t SEND_SEMAPHORE = 0U;
143 static constexpr uint64_t RECEIVE_SEMAPHORE = 1U;
145 static constexpr uint64_t INVALID_DATA = 0xBAADF00DAFFEDEAD;
146 static constexpr uint64_t VALID_DATA = 0xBAD0FF1CEBEEFBEE;
147 static constexpr units::Duration WAIT_FOR_INIT_TIMEOUT = units::Duration::fromSeconds(1);
148 static constexpr units::Duration WAIT_FOR_INIT_SLEEP_TIME = units::Duration::fromMilliseconds(1);
150 std::atomic<uint64_t> initializationGuard{INVALID_DATA};
151 using semaphoreMemory_t = uint8_t[
sizeof(
Semaphore)];
152 alignas(
Semaphore) semaphoreMemory_t semaphores[2U];
156 NamedPipeData* m_data =
nullptr;
cxx::expected< std::string, IpcChannelError > receive() const noexcept
receives a message via the named pipe. if the pipe is empty this call is blocking until a message was...