9ed30b6a600c6d9324fd3d6c8b4122c88c732570
[framework/web/wrt-plugins-common.git] / src / modules / tizen / DBus / Message.h
1 /*
2  * Copyright (c) 2011 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  * @author          Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
18  */
19
20 #ifndef WRTDEVICEAPIS_DBUS_MESSAGE_H_
21 #define WRTDEVICEAPIS_DBUS_MESSAGE_H_
22
23 #include <string>
24 #include <dbus/dbus.h>
25 #include <dpl/shared_ptr.h>
26 #include <dpl/optional.h>
27 #include <dpl/noncopyable.h>
28
29 namespace WrtDeviceApis {
30 namespace DBus {
31 class Message : private DPL::Noncopyable
32 {
33   private:
34     class ReadIterator_;
35
36   public:
37     typedef DPL::SharedPtr<ReadIterator_> ReadIterator;
38
39   public:
40     explicit Message(DBusMessage* message);
41     explicit Message(int type);
42     ~Message();
43
44     int getType() const;
45     std::string getInterface() const;
46     std::string getPath() const;
47     bool isSignal(const std::string& name) const;
48     ReadIterator getReadIterator() const;
49
50   private:
51     // It doesn't need to be non-copyable - DBusMessageIter doesn't require it.
52     class ReadIterator_
53     {
54       public:
55         explicit ReadIterator_(DBusMessage* message);
56
57         bool next();
58         bool isValid() const;
59
60         int getArgType() const;
61
62         int getInt() const;
63         std::string getString() const;
64
65       private:
66         template<typename T>
67         T getArgBasic(int type) const;
68
69       private:
70         mutable DBusMessageIter m_iterator;
71         bool m_valid;
72     };
73
74   private:
75     inline void addRef();
76     inline void unref();
77
78   private:
79     DBusMessage* m_message;
80 };
81
82 typedef DPL::SharedPtr<Message> MessagePtr;
83 } // DBus
84 } // WrtDeviceApis
85
86 #endif // WRTDEVICEAPIS_DBUS_MESSAGE_H_