Tizen 2.1 base
[framework/security/security-server.git] / src / daemon / dbus / security_dbus_service.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file        security_dbus_service.cpp
18  * @author      Tomasz Swierczek (t.swierczek@samsung.com)
19  * @author      Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20  * @version     1.0
21  * @brief       This file contains implementation of security DBus service.
22  */
23 #include <dpl/log/log.h>
24 #include <algorithm>
25 #include <gio/gio.h>
26 #include <dpl/exception.h>
27 #include <dpl/dbus/interface.h>
28 #include <dpl/dbus/connection.h>
29 #include "security_dbus_service.h"
30 #include "security_daemon_dbus_config.h"
31 #include <ace_server_dbus_interface.h>
32 #include <ocsp_server_dbus_interface.h>
33 #include <popup_response_dbus_interface.h>
34
35
36 void SecurityDBusService::start()
37 {
38     LogDebug("SecurityDBusService starting");
39     m_connection = DPL::DBus::Connection::systemBus();
40     std::for_each(m_objects.begin(),
41                   m_objects.end(),
42                   [&m_connection] (const DPL::DBus::ObjectPtr& object)
43                   {
44                       m_connection->registerObject(object);
45                   });
46     m_connection->registerService(
47             WrtSecurity::SecurityDaemonConfig::SERVICE_NAME());
48 }
49
50 void SecurityDBusService::stop()
51 {
52     LogDebug("SecurityDBusService stopping");
53     m_connection.reset();
54 }
55
56 void SecurityDBusService::initialize()
57 {
58     LogDebug("SecurityDBusService initializing");
59     g_type_init();
60
61     addInterface(WrtSecurity::SecurityDaemonConfig::OBJECT_PATH(),
62                  std::make_shared<RPC::AceServerDBusInterface>());
63     addInterface(WrtSecurity::SecurityDaemonConfig::OBJECT_PATH(),
64                  std::make_shared<RPC::OcspServerDBusInterface>());
65     addInterface(WrtSecurity::SecurityDaemonConfig::OBJECT_PATH(),
66                  std::make_shared<RPC::PopupResponseDBusInterface>());
67 }
68
69 void SecurityDBusService::addInterface(const std::string& objectPath,
70                                        const InterfaceDispatcherPtr& dispatcher)
71 {
72     auto ifaces =
73         DPL::DBus::Interface::fromXMLString(dispatcher->getXmlSignature());
74     if (ifaces.empty())
75     {
76         ThrowMsg(DPL::Exception, "No interface description.");
77     }
78
79     auto iface = ifaces.at(0);
80     iface->setDispatcher(dispatcher.get());
81
82     m_dispatchers.push_back(dispatcher);
83     m_objects.push_back(DPL::DBus::Object::create(objectPath, iface));
84 }
85
86 void SecurityDBusService::deinitialize()
87 {
88     LogDebug("SecurityDBusService deinitializing");
89     m_objects.clear();
90     m_dispatchers.clear();
91 }
92
93 #ifdef DBUS_CONNECTION
94 DAEMON_REGISTER_SERVICE_MODULE(SecurityDBusService)
95 #endif //DBUS_CONNECTION