iceoryx_doc  1.0.1
ipc_message.hpp
1 // Copyright (c) 2019 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_RUNTIME_IPC_MESSAGE_HPP
18 #define IOX_POSH_RUNTIME_IPC_MESSAGE_HPP
19 
20 #include "iceoryx_posh/internal/log/posh_logging.hpp"
21 
22 #include <cstdint>
23 #include <sstream>
24 #include <string>
25 
26 namespace iox
27 {
28 namespace runtime
29 {
43 {
44  public:
46  IpcMessage() noexcept = default;
47 
52  IpcMessage(const std::initializer_list<std::string>& msg) noexcept;
53 
58  IpcMessage(const std::string& msg) noexcept;
59 
63  template <typename T>
64  IpcMessage& operator<<(const T& entry) noexcept;
65 
69  uint32_t getNumberOfElements() const noexcept;
70 
77  // If the message is invalid the return value is undefined.
78  std::string getElementAtIndex(const uint32_t index) const noexcept;
79 
85  bool isValidEntry(const std::string& entry) const noexcept;
86 
89  bool isValid() const noexcept;
90 
95  std::string getMessage() const noexcept;
96 
103  void setMessage(const std::string& msg) noexcept;
104 
106  // message becomes valid again.
107  void clearMessage() noexcept;
108 
114  template <typename T>
115  void addEntry(const T& entry) noexcept;
116 
119  bool operator==(const IpcMessage& rhs) const noexcept;
120 
121  private:
122  static const char m_separator; // default value is ,
123  std::string m_msg;
124  bool m_isValid{true};
125  uint32_t m_numberOfElements{0};
126 };
127 
128 } // namespace runtime
129 } // namespace iox
130 
131 
132 #include "iceoryx_posh/internal/runtime/ipc_message.inl"
133 
134 #endif // IOX_POSH_RUNTIME_IPC_MESSAGE_HPP
Definition: ipc_message.hpp:43
void addEntry(const T &entry) noexcept
Adds a new entry to the IpcMessage, if the entry is invalid no entry is added and the IpcMessage beco...
Definition: ipc_message.inl:27
bool isValid() const noexcept
check if the message is valid
IpcMessage() noexcept=default
Creates an empty and valid IPC channel message.
void setMessage(const std::string &msg) noexcept
Takes a separator separated string and interprets it as a IpcMessage. In this case the IpcMessage can...
void clearMessage() noexcept
Clears the message. After a call to clearMessage() the.
std::string getElementAtIndex(const uint32_t index) const noexcept
Returns the entry at position f_index. If f_index is larger then the sum of the entries stored in Ipc...
std::string getMessage() const noexcept
The message is casted to the actual separator separated string If the message is invalid the return v...
bool isValidEntry(const std::string &entry) const noexcept
returns if an entry is valid. Non valid entries are containing at least one separator
uint32_t getNumberOfElements() const noexcept
Returns the number of entries stored in IpcMessage. If the message is invalid the return value is und...
Definition: service_description.hpp:29