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