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/assert.h>
24 #include <dpl/exception.h>
25 #include <dpl/dbus/exception.h>
26 #include <dpl/dbus/interface.h>
30 const GDBusInterfaceVTable Interface::m_vTable = {
31 Interface::onMethodCallFunc,
32 Interface::onPropertyGetFunc,
33 Interface::onPropertySetFunc,
34 { 0, 0, 0, 0, 0, 0, 0, 0 }
37 std::vector<InterfacePtr> Interface::fromXMLString(const std::string& xmlString)
41 GDBusNodeInfo* nodeInfo = g_dbus_node_info_new_for_xml(xmlString.c_str(),
43 if (NULL == nodeInfo) {
46 message = error->message;
49 ThrowMsg(DPL::DBus::Exception,
50 "Error parsing node info <" << message << ">");
53 std::vector<InterfacePtr> result;
55 GDBusInterfaceInfo** interface = nodeInfo->interfaces;
56 while (NULL != *interface) {
57 result.push_back(InterfacePtr(new Interface(*interface)));
61 g_dbus_node_info_unref(nodeInfo);
66 Interface::Interface(GDBusInterfaceInfo* info) :
69 g_dbus_interface_info_ref(m_info);
72 Interface::~Interface()
74 g_dbus_interface_info_unref(m_info);
77 const GDBusInterfaceVTable* Interface::getVTable() const
82 GDBusInterfaceInfo* Interface::getInfo() const
87 void Interface::setDispatcher(Dispatcher* dispatcher)
89 m_dispatcher = dispatcher;
92 void Interface::onMethodCallFunc(GDBusConnection *connection,
94 const gchar *objectPath,
95 const gchar *interfaceName,
96 const gchar *methodName,
98 GDBusMethodInvocation *invocation,
101 AssertMsg(NULL != data, "Interface cannot be NULL.");
102 Interface* self = static_cast<Interface*>(data);
104 // TODO Verify interface name.
106 if (NULL != self->m_dispatcher) {
108 self->m_dispatcher->onMethodCall(connection,
115 } catch (const DPL::Exception& /*ex*/) {
116 // TODO Support for errors.
121 GVariant* Interface::onPropertyGetFunc(GDBusConnection *connection,
123 const gchar *objectPath,
124 const gchar *interfaceName,
125 const gchar *propertyName,
129 AssertMsg(NULL != data, "Interface cannot be NULL.");
130 Interface* self = static_cast<Interface*>(data);
132 // TODO Verify interface name.
134 if (NULL != self->m_dispatcher) {
136 // TODO Check if NULL is returned, if so set error variable.
137 return self->m_dispatcher->onPropertyGet(connection,
143 } catch (const DPL::Exception& /*ex*/) {
144 // TODO Support for errors.
153 gboolean Interface::onPropertySetFunc(GDBusConnection *connection,
155 const gchar *objectPath,
156 const gchar *interfaceName,
157 const gchar *propertyName,
162 AssertMsg(NULL != data, "Interface cannot be NULL.");
163 Interface* self = static_cast<Interface*>(data);
165 // TODO Verify interface name.
167 if (NULL != self->m_dispatcher) {
169 return self->m_dispatcher->onPropertySet(connection,
176 } catch (const DPL::Exception& /*ex*/) {
177 // TODO Support for errors.