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