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)
22 #include <dpl/log/log.h>
23 #include <dpl/assert.h>
24 #include <dpl/exception.h>
25 #include <dpl/dbus/exception.h>
26 #include <dpl/dbus/interface.h>
31 const GDBusInterfaceVTable Interface::m_vTable =
33 Interface::onMethodCallFunc,
34 Interface::onPropertyGetFunc,
35 Interface::onPropertySetFunc,
36 {0, 0, 0, 0, 0, 0, 0, 0}
39 std::vector<InterfacePtr> Interface::fromXMLString(const std::string& xmlString)
43 GDBusNodeInfo* nodeInfo = g_dbus_node_info_new_for_xml(xmlString.c_str(),
50 message = error->message;
53 ThrowMsg(DPL::DBus::Exception,
54 "Error parsing node info <" << message << ">");
57 std::vector<InterfacePtr> result;
59 GDBusInterfaceInfo** interface = nodeInfo->interfaces;
60 while (NULL != *interface)
62 result.push_back(InterfacePtr(new Interface(*interface)));
66 g_dbus_node_info_unref(nodeInfo);
71 Interface::Interface(GDBusInterfaceInfo* info)
74 g_dbus_interface_info_ref(m_info);
77 Interface::~Interface()
79 g_dbus_interface_info_unref(m_info);
82 const GDBusInterfaceVTable* Interface::getVTable() const
87 GDBusInterfaceInfo* Interface::getInfo() const
92 void Interface::setDispatcher(Dispatcher* dispatcher)
94 m_dispatcher = dispatcher;
97 void Interface::onMethodCallFunc(GDBusConnection *connection,
99 const gchar *objectPath,
100 const gchar *interfaceName,
101 const gchar *methodName,
102 GVariant *parameters,
103 GDBusMethodInvocation *invocation,
106 Assert(NULL != data && "Interface cannot be NULL.");
107 Interface* self = static_cast<Interface*>(data);
109 // TODO Verify interface name.
111 if (NULL != self->m_dispatcher)
115 self->m_dispatcher->onMethodCall(connection,
123 catch (const DPL::Exception& /*ex*/)
125 // TODO Support for errors.
130 GVariant* Interface::onPropertyGetFunc(GDBusConnection *connection,
132 const gchar *objectPath,
133 const gchar *interfaceName,
134 const gchar *propertyName,
138 Assert(NULL != data && "Interface cannot be NULL.");
139 Interface* self = static_cast<Interface*>(data);
141 // TODO Verify interface name.
143 if (NULL != self->m_dispatcher)
147 // TODO Check if NULL is returned, if so set error variable.
148 return self->m_dispatcher->onPropertyGet(connection,
155 catch (const DPL::Exception& /*ex*/)
157 // TODO Support for errors.
166 gboolean Interface::onPropertySetFunc(GDBusConnection *connection,
168 const gchar *objectPath,
169 const gchar *interfaceName,
170 const gchar *propertyName,
175 Assert(NULL != data && "Interface cannot be NULL.");
176 Interface* self = static_cast<Interface*>(data);
178 // TODO Verify interface name.
180 if (NULL != self->m_dispatcher)
184 return self->m_dispatcher->onPropertySet(connection,
192 catch (const DPL::Exception& /*ex*/)
194 // TODO Support for errors.