swift
dbusmessage.h
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_SIM_XSWIFTBUS_DBUSMESSAGE_H
5 #define SWIFT_SIM_XSWIFTBUS_DBUSMESSAGE_H
6 
7 #include <string>
8 #include <string_view>
9 #include <vector>
10 
11 #include "dbus/dbus.h"
12 
13 namespace XSwiftBus
14 {
17  {
18  public:
21  CDBusMessage(DBusMessage *message);
22  CDBusMessage(const CDBusMessage &other);
24 
26  ~CDBusMessage();
27 
30 
32  bool isMethodCall() const;
33 
35  bool wantsReply() const;
36 
38  std::string getSender() const;
39 
41  dbus_uint32_t getSerial() const;
42 
44  std::string_view getInterfaceName() const;
45 
47  std::string_view getObjectPath() const;
48 
50  std::string_view getMethodName() const;
51 
53  void beginArgumentWrite();
54 
57  void appendArgument(bool value);
58  void appendArgument(const char *value);
59  void appendArgument(const std::string &value);
60  void appendArgument(int value);
61  void appendArgument(double value);
62  void appendArgument(const std::vector<bool> &array);
63  void appendArgument(const std::vector<double> &array);
64  void appendArgument(const std::vector<std::string> &array);
66 
68  void beginArgumentRead();
69 
72  void getArgument(int &value);
73  void getArgument(bool &value);
74  void getArgument(double &value);
75  void getArgument(std::string &value);
76  void getArgument(std::vector<int> &value);
77  void getArgument(std::vector<bool> &value);
78  void getArgument(std::vector<double> &value);
79  void getArgument(std::vector<std::string> &value);
81 
83  static CDBusMessage createSignal(const std::string &path, const std::string &interfaceName,
84  const std::string &signalName);
85 
87  static CDBusMessage createReply(const std::string &destination, dbus_uint32_t serial);
88 
89  private:
90  friend class CDBusConnection;
91 
92  DBusMessage *m_message = nullptr;
93  DBusMessageIter m_messageIterator;
94  CDBusMessage(DBusMessage *message, dbus_uint32_t serial);
95  dbus_uint32_t m_serial = 0;
96  };
97 
98 } // namespace XSwiftBus
99 
100 #endif // SWIFT_SIM_XSWIFTBUS_DBUSMESSAGE_H
CDBusMessage & operator=(CDBusMessage other)
Assignment operator.
Definition: dbusmessage.cpp:25
bool wantsReply() const
Does this message want a reply?
Definition: dbusmessage.cpp:37
bool isMethodCall() const
Is this message a method call?
Definition: dbusmessage.cpp:32
void appendArgument(bool value)
Append argument. Make sure to call.
Definition: dbusmessage.cpp:55
void getArgument(int &value)
Read single argument. Make sure to call.
std::string getSender() const
Get the message sender.
Definition: dbusmessage.cpp:39
std::string_view getObjectPath() const
Get the called object path.
Definition: dbusmessage.cpp:49
std::string_view getMethodName() const
Get the called method name.
Definition: dbusmessage.cpp:51
dbus_uint32_t getSerial() const
Get the message serial. This is usally required for reply message.
Definition: dbusmessage.cpp:45
std::string_view getInterfaceName() const
Get the called interface name.
Definition: dbusmessage.cpp:47
CDBusMessage(DBusMessage *message)
Constructor.
Definition: dbusmessage.cpp:9
void beginArgumentRead()
Begin reading arguments.
void beginArgumentWrite()
Begin writing argument.
Definition: dbusmessage.cpp:53
static CDBusMessage createReply(const std::string &destination, dbus_uint32_t serial)
Creates a DBus message containing a DBus reply.
static CDBusMessage createSignal(const std::string &path, const std::string &interfaceName, const std::string &signalName)
Creates a DBus message containing a DBus signal.
~CDBusMessage()
Destructor.
Definition: dbusmessage.cpp:23
Plugin loaded by X-Plane which publishes a DBus service.
Definition: command.h:14