tizen 2.4 release
[framework/web/wrt-commons.git] / modules / dbus / include / dpl / dbus / dbus_interface_dispatcher.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        dbus_interface_dispatcher.h
18  * @author      Tomasz Swierczek (t.swierczek@samsung.com)
19  * @version     1.0
20  * @brief       This file contains definitions of DBus::InterfaceDispatcher
21  *              class.
22  */
23
24 #ifndef DPL_DBUS_DBUS_INTERFACE_DISPATCHER_H_
25 #define DPL_DBUS_DBUS_INTERFACE_DISPATCHER_H_
26
27 #include <string>
28 #include <dpl/log/wrt_log.h>
29 #include <dpl/dbus/dispatcher.h>
30
31 namespace DPL {
32 namespace DBus {
33 class InterfaceDispatcher : public DBus::Dispatcher
34 {
35   public:
36     explicit InterfaceDispatcher(const std::string& interfaceName) :
37         m_interfaceName(interfaceName)
38     {}
39
40     virtual ~InterfaceDispatcher()
41     {}
42
43     // Implement it in specific interface with method handling
44     virtual void onMethodCall(const gchar* /*methodName*/,
45                               GVariant* /*parameters*/,
46                               GDBusMethodInvocation* /*invocation*/) = 0;
47
48     virtual std::string getName() const
49     {
50         return m_interfaceName;
51     }
52
53     virtual std::string getXmlSignature()  const
54     {
55         return m_xml;
56     }
57     virtual void setXmlSignature(const std::string& newSignature)
58     {
59         m_xml = newSignature;
60     }
61
62     virtual void onMethodCall(GDBusConnection* /*connection*/,
63                               const gchar* /*sender*/,
64                               const gchar* /*objectPath*/,
65                               const gchar* interfaceName,
66                               const gchar* methodName,
67                               GVariant* parameters,
68                               GDBusMethodInvocation* invocation)
69     {
70         if (g_strcmp0(interfaceName, m_interfaceName.c_str()) == 0) {
71             onMethodCall(methodName, parameters, invocation);
72         } else {
73             WrtLogD("Called invalid interface: %s instead of: %s",
74                 interfaceName, m_interfaceName.c_str());
75         }
76     }
77
78     virtual GVariant* onPropertyGet(GDBusConnection* /*connection*/,
79                                     const gchar* /*sender*/,
80                                     const gchar* /*objectPath*/,
81                                     const gchar* /*interfaceName*/,
82                                     const gchar* propertyName)
83     {
84         WrtLogD("InterfaceDispatcher onPropertyGet: %s", propertyName);
85         return NULL;
86     }
87
88     virtual gboolean onPropertySet(GDBusConnection* /*connection*/,
89                                    const gchar* /*sender*/,
90                                    const gchar* /*objectPath*/,
91                                    const gchar* /*interfaceName*/,
92                                    const gchar* propertyName,
93                                    GVariant* /*value*/)
94     {
95         WrtLogD("InterfaceDispatcher onPropertySet: %s", propertyName);
96         return false;
97     }
98
99   private:
100     std::string m_interfaceName, m_xml;
101 };
102 } // namespace DBus
103 } // namespace DPL
104
105 #endif // DPL_DBUS_DBUS_INTERFACE_DISPATCHER_H_