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 + "'>"
41 " <arg type='s' name='challenge' direction='in'/>"
42 " <arg type='s' name='response' direction='out'/>"
45 + methodNameQuit + "'>"
51 class TestServiceDispatcher : public DPL::DBus::Dispatcher
54 void onMethodCall(GDBusConnection* /*connection*/,
55 const gchar* /*sender*/,
56 const gchar* /*objectPath*/,
57 const gchar* /*interfaceName*/,
58 const gchar* methodName,
60 GDBusMethodInvocation* invocation)
62 if (methodNameEcho == methodName) {
64 g_dbus_method_invocation_return_value(invocation,
66 } else if (methodNameQuit == methodName) {
68 g_dbus_method_invocation_return_value(invocation, NULL);
69 LoopControl::wrt_end_loop();
74 int main(int argc, char* argv[])
76 LoopControl::init_loop(argc, argv);
77 TestServiceDispatcher dispatcher;
79 auto iface = DPL::DBus::Interface::fromXMLString(nodeInfo).at(0);
80 iface->setDispatcher(&dispatcher);
81 auto object = DPL::DBus::Object::create(objectPath, iface);
82 auto connection = DPL::DBus::Connection::sessionBus();
83 connection->registerObject(object);
84 connection->registerService(serviceName);
85 LoopControl::wrt_start_loop();