summaryrefslogtreecommitdiff
path: root/src/CommonAPI/DBus/DBusMessage.h
blob: 66addf3e541293c59fd12aa7e6dc150223b0b586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Copyright (C) 2013 BMW Group
 * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
 * Author: Juergen Gehring (juergen.gehring@bmw.de)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#if !defined (COMMONAPI_INTERNAL_COMPILATION)
#error "Only <CommonAPI/CommonAPI.h> can be included directly, this file may disappear or change contents."
#endif

#ifndef COMMONAPI_DBUS_DBUS_MESSAGE_H_
#define COMMONAPI_DBUS_DBUS_MESSAGE_H_

#include <string>

#include <dbus/dbus.h>

namespace CommonAPI {
namespace DBus {

class DBusConnection;

class DBusMessage {
 public:
    DBusMessage();
    DBusMessage(::DBusMessage* libdbusMessage);
    DBusMessage(::DBusMessage* libdbusMessage, bool increaseReferenceCount);
    DBusMessage(const DBusMessage& src);
    DBusMessage(DBusMessage&& src);

    ~DBusMessage();

    DBusMessage& operator=(const DBusMessage& src);
    DBusMessage& operator=(DBusMessage&& rsrc);
    operator bool() const;

    static DBusMessage createOrgFreedesktopOrgMethodCall(const char* methodName,
                                                         const char* signature = NULL);

    static DBusMessage createOrgFreedesktopOrgMethodCall(const std::string& methodName,
                                                         const std::string& signature = "");

    static DBusMessage createMethodCall(const char* busName,
                                        const char* objectPath,
                                        const char* interfaceName,
                                        const char* methodName,
                                        const char* signature = NULL);

    static DBusMessage createMethodCall(const std::string& busName,
                                        const std::string& objectPath,
                                        const std::string& interfaceName,
                                        const std::string& methodName,
                                        const std::string& signature = "");

    DBusMessage createMethodReturn(const char* signature = NULL) const;

    DBusMessage createMethodReturn(const std::string& signature) const;

    DBusMessage createMethodError(const std::string& name, const std::string& reason = "") const;

    static DBusMessage createSignal(const char* objectPath,
                                    const char* interfaceName,
                                    const char* signalName,
                                    const char* signature = NULL);

    static DBusMessage createSignal(const std::string& objectPath,
                                    const std::string& interfaceName,
                                    const std::string& signalName,
                                    const std::string& signature = "");

    const char* getSenderName() const;
    const char* getObjectPath() const;
    const char* getInterfaceName() const;
    const char* getMemberName() const;
    const char* getSignatureString() const;
    const char* getErrorName() const;
    const char* getDestination() const;

    bool hasObjectPath(const std::string& objectPath) const;

    bool hasObjectPath(const char* objectPath) const;
    bool hasInterfaceName(const char* interfaceName) const;
    bool hasMemberName(const char* memberName) const;
    bool hasSignature(const char* signature) const;

    enum class Type: int {
        Invalid = DBUS_MESSAGE_TYPE_INVALID,
        MethodCall = DBUS_MESSAGE_TYPE_METHOD_CALL,
        MethodReturn = DBUS_MESSAGE_TYPE_METHOD_RETURN,
        Error = DBUS_MESSAGE_TYPE_ERROR,
        Signal = DBUS_MESSAGE_TYPE_SIGNAL
    };
    const Type getType() const;
    bool isInvalidType() const;
    bool isMethodCallType() const;
    bool isMethodReturnType() const;
    bool isErrorType() const;
    bool isSignalType() const;

    char* getBodyData() const;
    int getBodyLength() const;
    int getBodySize() const;

    bool setBodyLength(const int bodyLength);
    bool setDestination(const char* destination);

 private:
    ::DBusMessage* libdbusMessage_;

    friend class DBusConnection;
};

} // namespace DBus
} // namespace CommonAPI

#endif // COMMONAPI_DBUS_DBUS_MESSAGE_H_