27 #ifndef SDBUS_CXX_MESSAGE_H_ 28 #define SDBUS_CXX_MESSAGE_H_ 40 #include <sys/types.h> 47 template <
typename... _ValueTypes>
class Struct;
79 Message& operator<<(int16_t item);
80 Message& operator<<(int32_t item);
81 Message& operator<<(int64_t item);
82 Message& operator<<(uint8_t item);
83 Message& operator<<(uint16_t item);
84 Message& operator<<(uint32_t item);
85 Message& operator<<(uint64_t item);
86 Message& operator<<(
double item);
87 Message& operator<<(
const char *item);
88 Message& operator<<(
const std::string &item);
94 Message& operator>>(
bool& item);
95 Message& operator>>(int16_t& item);
96 Message& operator>>(int32_t& item);
97 Message& operator>>(int64_t& item);
98 Message& operator>>(uint8_t& item);
99 Message& operator>>(uint16_t& item);
100 Message& operator>>(uint32_t& item);
101 Message& operator>>(uint64_t& item);
102 Message& operator>>(
double& item);
103 Message& operator>>(
char*& item);
104 Message& operator>>(std::string &item);
110 Message& openContainer(
const std::string& signature);
112 Message& openDictEntry(
const std::string& signature);
114 Message& openVariant(
const std::string& signature);
116 Message& openStruct(
const std::string& signature);
119 Message& enterContainer(
const std::string& signature);
121 Message& enterDictEntry(
const std::string& signature);
123 Message& enterVariant(
const std::string& signature);
125 Message& enterStruct(
const std::string& signature);
128 explicit operator bool()
const;
131 std::string getInterfaceName()
const;
132 std::string getMemberName()
const;
133 std::string getSender()
const;
134 std::string getPath()
const;
135 std::string getDestination()
const;
136 void peekType(std::string& type, std::string& contents)
const;
137 bool isValid()
const;
138 bool isEmpty()
const;
140 void copyTo(
Message& destination,
bool complete)
const;
142 void rewind(
bool complete);
144 pid_t getCredsPid()
const;
145 uid_t getCredsUid()
const;
146 uid_t getCredsEuid()
const;
147 gid_t getCredsGid()
const;
148 gid_t getCredsEgid()
const;
149 std::vector<gid_t> getCredsSupplementaryGids()
const;
150 std::string getSELinuxContext()
const;
171 internal::ISdBus* sdbus_{};
172 mutable bool ok_{
true};
180 using Message::Message;
184 using Slot = std::unique_ptr<void, std::function<void(void*)>>;
190 [[nodiscard]] Slot send(
void* callback,
void* userData, uint64_t timeout)
const;
195 void dontExpectReply();
196 bool doesntExpectReply()
const;
199 MethodReply sendWithReply(uint64_t timeout = 0)
const;
205 using Message::Message;
215 using Message::Message;
220 void setDestination(
const std::string& destination);
226 using Message::Message;
235 using Message::Message;
244 using Message::Message;
251 template <
typename _Element>
252 inline Message& operator<<(Message& msg, const std::vector<_Element>& items)
256 for (
const auto& item : items)
259 msg.closeContainer();
264 template <
typename _Key,
typename _Value>
265 inline Message& operator<<(Message& msg, const std::map<_Key, _Value>& items)
267 const std::string dictEntrySignature = signature_of<_Key>::str() + signature_of<_Value>::str();
268 const std::string arraySignature =
"{" + dictEntrySignature +
"}";
270 msg.openContainer(arraySignature);
272 for (
const auto& item : items)
274 msg.openDictEntry(dictEntrySignature);
277 msg.closeDictEntry();
280 msg.closeContainer();
287 template <
typename... _Args>
288 void serialize_pack(Message& msg, _Args&&... args)
290 (void)(msg << ... << args);
293 template <
class _Tuple, std::size_t... _Is>
294 void serialize_tuple( Message& msg
296 , std::index_sequence<_Is...>)
298 serialize_pack(msg, std::get<_Is>(t)...);
302 template <
typename... _ValueTypes>
303 inline Message& operator<<(Message& msg,
const Struct<_ValueTypes...>& item)
305 auto structSignature = signature_of<Struct<_ValueTypes...>>::str();
306 assert(structSignature.size() > 2);
308 auto structContentSignature = structSignature.substr(1, structSignature.size()-2);
310 msg.openStruct(structContentSignature);
311 detail::serialize_tuple(msg, item, std::index_sequence_for<_ValueTypes...>{});
317 template <
typename... _ValueTypes>
318 inline Message& operator<<(Message& msg,
const std::tuple<_ValueTypes...>& item)
320 detail::serialize_tuple(msg, item, std::index_sequence_for<_ValueTypes...>{});
325 template <
typename _Element>
326 inline Message& operator>>(Message& msg, std::vector<_Element>& items)
328 if(!msg.enterContainer(signature_of<_Element>::str()))
335 items.emplace_back(std::move(elem));
347 template <
typename _Key,
typename _Value>
348 inline Message& operator>>(Message& msg, std::map<_Key, _Value>& items)
350 const std::string dictEntrySignature = signature_of<_Key>::str() + signature_of<_Value>::str();
351 const std::string arraySignature =
"{" + dictEntrySignature +
"}";
353 if (!msg.enterContainer(arraySignature))
358 if (!msg.enterDictEntry(dictEntrySignature))
365 items.emplace(std::move(key), std::move(value));
379 template <
typename... _Args>
380 void deserialize_pack(Message& msg, _Args&... args)
382 (void)(msg >> ... >> args);
385 template <
class _Tuple, std::size_t... _Is>
386 void deserialize_tuple( Message& msg
388 , std::index_sequence<_Is...> )
390 deserialize_pack(msg, std::get<_Is>(t)...);
394 template <
typename... _ValueTypes>
395 inline Message& operator>>(Message& msg, Struct<_ValueTypes...>& item)
397 auto structSignature = signature_of<Struct<_ValueTypes...>>::str();
399 auto structContentSignature = structSignature.substr(1, structSignature.size()-2);
401 if (!msg.enterStruct(structContentSignature))
404 detail::deserialize_tuple(msg, item, std::index_sequence_for<_ValueTypes...>{});
411 template <
typename... _ValueTypes>
412 inline Message& operator>>(Message& msg, std::tuple<_ValueTypes...>& item)
414 detail::deserialize_tuple(msg, item, std::index_sequence_for<_ValueTypes...>{});
Definition: Message.h:203
Definition: TypeTraits.h:63
Definition: Message.h:175
Definition: Message.h:213
Definition: Message.h:233
Definition: Message.h:224
Definition: AdaptorInterfaces.h:36
Definition: Message.h:242
Definition: Message.h:178