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>
32 const GDBusInterfaceVTable Interface::m_vTable =
34 Interface::onMethodCallFunc,
35 Interface::onPropertyGetFunc,
36 Interface::onPropertySetFunc,
37 {0, 0, 0, 0, 0, 0, 0, 0}
40 std::vector<InterfacePtr> Interface::fromXMLString(const std::string& xmlString)
44 GDBusNodeInfo* nodeInfo = g_dbus_node_info_new_for_xml(xmlString.c_str(),
51 message = error->message;
54 ThrowMsg(DPL::DBus::Exception,
55 "Error parsing node info <" << message << ">");
58 std::vector<InterfacePtr> result;
60 GDBusInterfaceInfo** interface = nodeInfo->interfaces;
61 while (NULL != *interface)
63 result.push_back(InterfacePtr(new Interface(*interface)));
67 g_dbus_node_info_unref(nodeInfo);
72 Interface::Interface(GDBusInterfaceInfo* info)
75 g_dbus_interface_info_ref(m_info);
78 Interface::~Interface()
80 g_dbus_interface_info_unref(m_info);
83 const GDBusInterfaceVTable* Interface::getVTable() const
88 GDBusInterfaceInfo* Interface::getInfo() const
93 void Interface::setDispatcher(Dispatcher* dispatcher)
95 m_dispatcher = dispatcher;
98 void Interface::onMethodCallFunc(GDBusConnection *connection,
100 const gchar *objectPath,
101 const gchar *interfaceName,
102 const gchar *methodName,
103 GVariant *parameters,
104 GDBusMethodInvocation *invocation,
107 Assert(NULL != data && "Interface cannot be NULL.");
108 Interface* self = static_cast<Interface*>(data);
110 // TODO Verify interface name.
112 if (NULL != self->m_dispatcher)
116 self->m_dispatcher->onMethodCall(connection,
124 catch (const DPL::Exception& /*ex*/)
126 // TODO Support for errors.
131 GVariant* Interface::onPropertyGetFunc(GDBusConnection *connection,
133 const gchar *objectPath,
134 const gchar *interfaceName,
135 const gchar *propertyName,
139 Assert(NULL != data && "Interface cannot be NULL.");
140 Interface* self = static_cast<Interface*>(data);
142 // TODO Verify interface name.
144 if (NULL != self->m_dispatcher)
148 // TODO Check if NULL is returned, if so set error variable.
149 return self->m_dispatcher->onPropertyGet(connection,
156 catch (const DPL::Exception& /*ex*/)
158 // TODO Support for errors.
167 gboolean Interface::onPropertySetFunc(GDBusConnection *connection,
169 const gchar *objectPath,
170 const gchar *interfaceName,
171 const gchar *propertyName,
176 Assert(NULL != data && "Interface cannot be NULL.");
177 Interface* self = static_cast<Interface*>(data);
179 // TODO Verify interface name.
181 if (NULL != self->m_dispatcher)
185 return self->m_dispatcher->onPropertySet(connection,
193 catch (const DPL::Exception& /*ex*/)
195 // TODO Support for errors.