2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
23 #include <dpl/log/log.h>
24 #include <dpl/assert.h>
25 #include <dpl/exception.h>
26 #include <dpl/dbus/exception.h>
27 #include <dpl/dbus/interface.h>
31 const GDBusInterfaceVTable Interface::m_vTable = {
32 Interface::onMethodCallFunc,
33 Interface::onPropertyGetFunc,
34 Interface::onPropertySetFunc,
35 { 0, 0, 0, 0, 0, 0, 0, 0 }
38 std::vector<InterfacePtr> Interface::fromXMLString(const std::string& xmlString)
42 GDBusNodeInfo* nodeInfo = g_dbus_node_info_new_for_xml(xmlString.c_str(),
44 if (NULL == nodeInfo) {
47 message = error->message;
50 ThrowMsg(DPL::DBus::Exception,
51 "Error parsing node info <" << message << ">");
54 std::vector<InterfacePtr> result;
56 GDBusInterfaceInfo** interface = nodeInfo->interfaces;
57 while (NULL != *interface) {
58 result.push_back(InterfacePtr(new Interface(*interface)));
62 g_dbus_node_info_unref(nodeInfo);
67 Interface::Interface(GDBusInterfaceInfo* info) :
70 g_dbus_interface_info_ref(m_info);
73 Interface::~Interface()
75 g_dbus_interface_info_unref(m_info);
78 const GDBusInterfaceVTable* Interface::getVTable() const
83 GDBusInterfaceInfo* Interface::getInfo() const
88 void Interface::setDispatcher(Dispatcher* dispatcher)
90 m_dispatcher = dispatcher;
93 void Interface::onMethodCallFunc(GDBusConnection *connection,
95 const gchar *objectPath,
96 const gchar *interfaceName,
97 const gchar *methodName,
99 GDBusMethodInvocation *invocation,
102 Assert(NULL != data && "Interface cannot be NULL.");
103 Interface* self = static_cast<Interface*>(data);
105 // TODO Verify interface name.
107 if (NULL != self->m_dispatcher) {
109 self->m_dispatcher->onMethodCall(connection,
116 } catch (const DPL::Exception& /*ex*/) {
117 // TODO Support for errors.
122 GVariant* Interface::onPropertyGetFunc(GDBusConnection *connection,
124 const gchar *objectPath,
125 const gchar *interfaceName,
126 const gchar *propertyName,
130 Assert(NULL != data && "Interface cannot be NULL.");
131 Interface* self = static_cast<Interface*>(data);
133 // TODO Verify interface name.
135 if (NULL != self->m_dispatcher) {
137 // TODO Check if NULL is returned, if so set error variable.
138 return self->m_dispatcher->onPropertyGet(connection,
144 } catch (const DPL::Exception& /*ex*/) {
145 // TODO Support for errors.
154 gboolean Interface::onPropertySetFunc(GDBusConnection *connection,
156 const gchar *objectPath,
157 const gchar *interfaceName,
158 const gchar *propertyName,
163 Assert(NULL != data && "Interface cannot be NULL.");
164 Interface* self = static_cast<Interface*>(data);
166 // TODO Verify interface name.
168 if (NULL != self->m_dispatcher) {
170 return self->m_dispatcher->onPropertySet(connection,
177 } catch (const DPL::Exception& /*ex*/) {
178 // TODO Support for errors.