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.
17 * @file test_service.cpp
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19 * @brief Implementation file for wrt-dbus-test-service.
23 #include <dpl/dbus/connection.h>
24 #include <dpl/dbus/object.h>
25 #include <dpl/dbus/interface.h>
26 #include <dpl/dbus/dispatcher.h>
27 #include "loop_control.h"
30 const std::string serviceName = "org.tizen.DBusTestService";
31 const std::string objectPath = "/org/tizen/DBusTestService";
32 const std::string interfaceName = "org.tizen.DBusTestService";
33 const std::string methodNameEcho = "echo";
34 const std::string methodNameQuit = "quit";
35 const std::string nodeInfo =
36 "<?xml version='1.0'?>"
38 " <interface name='" + interfaceName + "'>"
39 " <method name='" + methodNameEcho + "'>"
40 " <arg type='s' name='challenge' direction='in'/>"
41 " <arg type='s' name='response' direction='out'/>"
43 " <method name='" + methodNameQuit + "'>"
49 class TestServiceDispatcher : public DPL::DBus::Dispatcher
52 void onMethodCall(GDBusConnection* /*connection*/,
53 const gchar* /*sender*/,
54 const gchar* /*objectPath*/,
55 const gchar* /*interfaceName*/,
56 const gchar* methodName,
58 GDBusMethodInvocation* invocation)
60 if (methodNameEcho == methodName)
63 g_dbus_method_invocation_return_value(invocation,
66 else if (methodNameQuit == methodName)
69 g_dbus_method_invocation_return_value(invocation, NULL);
70 LoopControl::wrt_end_loop();
75 int main(int argc, char* argv[])
77 LoopControl::init_loop(argc, argv);
79 TestServiceDispatcher dispatcher;
81 auto iface = DPL::DBus::Interface::fromXMLString(nodeInfo).at(0);
82 iface->setDispatcher(&dispatcher);
84 auto object = DPL::DBus::Object::create(objectPath, iface);
86 auto connection = DPL::DBus::Connection::sessionBus();
87 connection->registerObject(object);
88 connection->registerService(serviceName);
90 LoopControl::wrt_start_loop();