Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_wearable / dbus / include / dpl / dbus / interface.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  * @file    interface.h
18  * @author  Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  * @version 1.0
20  * @brief
21  */
22
23 #ifndef DPL_DBUS_INTERFACE_H
24 #define DPL_DBUS_INTERFACE_H
25
26 #include <memory>
27 #include <vector>
28 #include <gio/gio.h>
29 #include <dpl/noncopyable.h>
30 #include <dpl/dbus/dispatcher.h>
31
32 namespace DPL {
33 namespace DBus {
34 class Interface;
35 typedef std::shared_ptr<Interface> InterfacePtr;
36
37 class Interface : private DPL::Noncopyable
38 {
39   public:
40     /**
41      * Parses supplied XML string to produce DBus interface descriptions.
42      *
43      * @param xmlString XML string to parse.
44      * @return Interfaces.
45      * @throw DPL::DBus::Exception If error while parsing occurs.
46      */
47     static std::vector<InterfacePtr> fromXMLString(
48         const std::string& xmlString);
49
50   public:
51     ~Interface();
52
53     /**
54      * Gets pointers to functions called on method call or property get/set
55      * request.
56      *
57      * @return Pointers to functions.
58      */
59     const GDBusInterfaceVTable* getVTable() const;
60
61     /**
62      * Gets interface description.
63      *
64      * @return Interface description.
65      */
66     GDBusInterfaceInfo* getInfo() const;
67
68     /**
69      * Sets method/property dispatcher for the interface.
70      *
71      * @param dispatcher Method call and property get/set dispatcher.
72      */
73     void setDispatcher(Dispatcher* dispatcher);
74
75   private:
76     static void onMethodCallFunc(GDBusConnection *connection,
77                                  const gchar *sender,
78                                  const gchar *objectPath,
79                                  const gchar *interfaceName,
80                                  const gchar *methodName,
81                                  GVariant *parameters,
82                                  GDBusMethodInvocation *invocation,
83                                  gpointer data);
84
85     static GVariant* onPropertyGetFunc(GDBusConnection *connection,
86                                        const gchar *sender,
87                                        const gchar *objectPath,
88                                        const gchar *interfaceName,
89                                        const gchar *propertyName,
90                                        GError **error,
91                                        gpointer data);
92
93     static gboolean onPropertySetFunc(GDBusConnection *connection,
94                                       const gchar *sender,
95                                       const gchar *objectPath,
96                                       const gchar *interfaceName,
97                                       const gchar *propertyName,
98                                       GVariant *value,
99                                       GError **error,
100                                       gpointer data);
101
102     explicit Interface(GDBusInterfaceInfo* info);
103
104     static const GDBusInterfaceVTable m_vTable;
105
106     GDBusInterfaceInfo* m_info;
107
108     Dispatcher* m_dispatcher;
109 };
110 }
111 }
112
113 #endif // DPL_DBUS_INTERFACE_H