Merging tizen into ckm. Stage 1.
[platform/core/test/security-tests.git] / tests / common / dbus_message_in.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd 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 /*
17  * @file        dbus_message_in.h
18  * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
19  * @version     1.0
20  * @brief       DBus incoming message wrapper class header
21  */
22
23 #ifndef COMMON_DBUS_MESSAGE_IN_H
24 #define COMMON_DBUS_MESSAGE_IN_H
25
26 #include <dbus/dbus.h>
27
28 #include <cstdint>
29 #include <string>
30
31 namespace DBus
32 {
33
34 class MessageIn
35 {
36 public:
37     MessageIn(DBusMessage *message, bool ref = false);
38     MessageIn(const MessageIn &other) = delete;
39     MessageIn(MessageIn &&other);
40     ~MessageIn();
41
42     MessageIn& operator=(const MessageIn &other) = delete;
43
44     int getType();
45     bool isMethodCall(const std::string &interface, const std::string &method);
46     bool isSignal(const std::string &interface, const std::string &signalName);
47     bool isError(const std::string &errorName);
48
49     class Iterator
50     {
51     public:
52         friend class MessageIn;
53
54         bool next();
55         void expectNext();
56         int getArgType();
57         void expectArgType(int argType);
58         void expectArgTypeValid();
59         char getArgChar();
60         bool getArgBool();
61         int16_t getArgInt16();
62         uint16_t getArgUint16();
63         int32_t getArgInt32();
64         uint32_t getArgUint32();
65         int64_t getArgInt64();
66         uint64_t getArgUint64();
67         double getArgDouble();
68         std::string getArgString();
69         Iterator recurse();
70
71     private:
72         template<class T>
73         T getArg() {
74             T value;
75             dbus_message_iter_get_basic(&m_iterator, &value);
76             return value;
77         }
78
79         // sub constructor
80         Iterator(DBusMessageIter *iteratorOver);
81         // message constructor
82         Iterator(DBusMessage *message);
83         DBusMessageIter m_iterator;
84     };
85
86     Iterator iterInit();
87
88 private:
89     DBusMessage *m_message;
90 };
91
92 } // namespace DBus
93
94 #endif // COMMON_DBUS_MESSAGE_IN_H