Initial import to Git
[profile/ivi/common-api-dbus-runtime.git] / src / CommonAPI / DBus / DBusMessage.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #ifndef COMMONAPI_DBUS_DBUS_MESSAGE_H_
5 #define COMMONAPI_DBUS_DBUS_MESSAGE_H_
6
7 #include <string>
8
9 #include <dbus/dbus.h>
10
11 namespace CommonAPI {
12 namespace DBus {
13
14 class DBusConnection;
15
16 class DBusMessage {
17  public:
18         DBusMessage();
19         DBusMessage(::DBusMessage* libdbusMessage);
20         DBusMessage(::DBusMessage* libdbusMessage, bool increaseReferenceCount);
21         DBusMessage(const DBusMessage& src);
22         DBusMessage(DBusMessage&& src);
23
24         ~DBusMessage();
25
26         DBusMessage& operator=(const DBusMessage& src);
27         DBusMessage& operator=(DBusMessage&& rsrc);
28         operator bool() const;
29
30         static DBusMessage createOrgFreedesktopOrgMethodCall(const char* methodName,
31                                                                      const char* signature = NULL);
32
33         static DBusMessage createOrgFreedesktopOrgMethodCall(const std::string& methodName,
34                                                                                                                  const std::string& signature = "");
35
36         static DBusMessage createMethodCall(const char* busName,
37                                         const char* objectPath,
38                                         const char* interfaceName,
39                                         const char* methodName,
40                                         const char* signature = NULL);
41
42         static DBusMessage createMethodCall(const std::string& busName,
43                                                                                 const std::string& objectPath,
44                                                                                 const std::string& interfaceName,
45                                                                                 const std::string& methodName,
46                                                                                 const std::string& signature = "");
47
48         DBusMessage createMethodReturn(const char* signature = NULL) const;
49
50         DBusMessage createMethodReturn(const std::string& signature) const;
51
52         static DBusMessage createSignal(const char* objectPath,
53                                                 const char* interfaceName,
54                                                 const char* signalName,
55                                                 const char* signature = NULL);
56
57         static DBusMessage createSignal(const std::string& objectPath,
58                                                                         const std::string& interfaceName,
59                                                                         const std::string& signalName,
60                                                                         const std::string& signature = "");
61
62         const char* getSenderName() const;
63         const char* getObjectPath() const;
64         const char* getInterfaceName() const;
65         const char* getMemberName() const;
66         const char* getSignatureString() const;
67         const char* getErrorName() const;
68
69         bool hasMemberName(const char* memberName) const;
70         bool hasSignature(const char* signature) const;
71
72         enum class Type: int {
73                 Invalid = DBUS_MESSAGE_TYPE_INVALID,
74                 MethodCall = DBUS_MESSAGE_TYPE_METHOD_CALL,
75                 MethodReturn = DBUS_MESSAGE_TYPE_METHOD_RETURN,
76                 Error = DBUS_MESSAGE_TYPE_ERROR,
77                 Signal = DBUS_MESSAGE_TYPE_SIGNAL
78         };
79         const Type getType() const;
80         inline bool isInvalidType() const;
81         inline bool isMethodCallType() const;
82         inline bool isMethodReturnType() const;
83         inline bool isErrorType() const;
84         inline bool isSignalType() const;
85
86         char* getBodyData() const;
87         int getBodyLength() const;
88         int getBodySize() const;
89
90         bool setBodyLength(const int bodyLength);
91
92  private:
93         ::DBusMessage* libdbusMessage_;
94
95         friend class DBusConnection;
96 };
97
98 bool DBusMessage::isInvalidType() const {
99         return (getType() == Type::Invalid);
100 }
101
102 bool DBusMessage::isMethodCallType() const {
103         return (getType() == Type::MethodCall);
104 }
105
106 bool DBusMessage::isMethodReturnType() const {
107         return (getType() == Type::MethodReturn);
108 }
109
110 bool DBusMessage::isErrorType() const {
111         return (getType() == Type::Error);
112 }
113
114 bool DBusMessage::isSignalType() const {
115         return (getType() == Type::Signal);
116 }
117
118 } // namespace DBus
119 } // namespace CommonAPI
120
121 #endif // COMMONAPI_DBUS_DBUS_MESSAGE_H_