Update User Agent String
[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/log.h>
29 #include <dpl/dbus/dispatcher.h>
30
31 namespace DPL {
32 namespace DBus {
33
34 class InterfaceDispatcher : public DBus::Dispatcher
35 {
36 public:
37     explicit InterfaceDispatcher(const std::string& interfaceName):
38         m_interfaceName(interfaceName)
39     {
40     }
41
42     virtual ~InterfaceDispatcher()
43     {}
44
45     // Implement it in specific interface with method handling
46     virtual void onMethodCall(const gchar* /*methodName*/,
47                               GVariant* /*parameters*/,
48                               GDBusMethodInvocation* /*invocation*/) = 0;
49
50     virtual std::string getName() const
51     {
52         return m_interfaceName;
53     }
54
55     virtual std::string getXmlSignature()  const
56     {
57         return m_xml;
58     }
59     virtual void setXmlSignature(const std::string& newSignature)
60     {
61         m_xml = newSignature;
62     }
63
64     virtual void onMethodCall(GDBusConnection* /*connection*/,
65                               const gchar* /*sender*/,
66                               const gchar* /*objectPath*/,
67                               const gchar* interfaceName,
68                               const gchar* methodName,
69                               GVariant* parameters,
70                               GDBusMethodInvocation* invocation)
71     {
72         if (g_strcmp0(interfaceName, m_interfaceName.c_str()) == 0){
73             onMethodCall(methodName, parameters, invocation);
74         } else {
75             LogPedantic("Called invalid interface: " << interfaceName <<
76                      " instead of: " << m_interfaceName);
77         }
78     }
79
80     virtual GVariant* onPropertyGet(GDBusConnection* /*connection*/,
81                                     const gchar* /*sender*/,
82                                     const gchar* /*objectPath*/,
83                                     const gchar* /*interfaceName*/,
84                                     const gchar* propertyName)
85     {
86         LogInfo("InterfaceDispatcher onPropertyGet: " << propertyName);
87         return NULL;
88     }
89
90     virtual gboolean onPropertySet(GDBusConnection* /*connection*/,
91                                    const gchar* /*sender*/,
92                                    const gchar* /*objectPath*/,
93                                    const gchar* /*interfaceName*/,
94                                    const gchar* propertyName,
95                                    GVariant* /*value*/)
96     {
97         LogInfo("InterfaceDispatcher onPropertySet: " << propertyName);
98         return false;
99     }
100 private:
101     std::string m_interfaceName,  m_xml;
102 };
103
104 } // namespace DBus
105 } // namespace DPL
106
107 #endif // DPL_DBUS_DBUS_INTERFACE_DISPATCHER_H_