16#ifndef IOX_HOOFS_POSIX_WRAPPER_NAMED_PIPE_HPP
17#define IOX_HOOFS_POSIX_WRAPPER_NAMED_PIPE_HPP
19#include "iceoryx_hoofs/concurrent/lockfree_queue.hpp"
20#include "iceoryx_hoofs/cxx/string.hpp"
21#include "iceoryx_hoofs/design_pattern/creation.hpp"
22#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
23#include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp"
24#include "iceoryx_hoofs/internal/units/duration.hpp"
25#include "iceoryx_hoofs/posix_wrapper/semaphore.hpp"
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;
This pattern can be used if you write an abstraction where you have to throw an exception in the cons...
Definition: creation.hpp:99
bool isInitialized() const noexcept
returns true if the object was constructed successfully, otherwise false
string implementation with some adjustments in the API, because we are not allowed to throw exception...
Definition: string.hpp:90
Definition: named_pipe.hpp:34
NamedPipe() noexcept
For compatibility with IpcChannel alias, default ctor which creates an uninitialized NamedPipe.
static cxx::expected< bool, IpcChannelError > unlinkIfExists(const IpcChannelName_t &name) noexcept
removes a named pipe artifact from the system
cxx::expected< IpcChannelError > timedSend(const std::string &message, const units::Duration &timeout) const noexcept
sends a message via the named pipe.
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...
cxx::expected< IpcChannelError > destroy() noexcept
destroys an initialized named pipe.
cxx::expected< std::string, IpcChannelError > timedReceive(const units::Duration &timeout) const noexcept
receives a message via the named pipe.
cxx::expected< IpcChannelError > trySend(const std::string &message) const noexcept
tries to send a message via the named pipe. if the pipe is full IpcChannelError::TIMEOUT is returned
cxx::expected< bool, IpcChannelError > isOutdated() noexcept
for compatibility with IpcChannelError
cxx::expected< IpcChannelError > send(const std::string &message) const noexcept
sends a message via the named pipe. if the pipe is full this call is blocking until the message could...
cxx::expected< std::string, IpcChannelError > tryReceive() const noexcept
tries to receive a message via the named pipe. if the pipe is empty IpcChannelError::TIMEOUT is retur...
Posix semaphore C++ Wrapping class.
Definition: semaphore.hpp:82
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29