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 security_daemon.cpp
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
20 * @brief This is implementation file of Security Daemon
23 #include "security_daemon.h"
25 #include <dpl/assert.h>
26 #include <dpl/foreach.h>
27 #include <dpl/log/log.h>
29 #include <dpl/framework_efl.h>
31 #include <dpl/singleton_impl.h>
32 IMPLEMENT_SINGLETON(SecurityDaemon::SecurityDaemon)
34 #include <ace-dao-rw/AceDAO.h>
36 namespace SecurityDaemon {
38 //This is declared not in SecurityDaemon class, so no Ecore.h is needed there.
39 static Ecore_Event_Handler *g_exitHandler;
40 static Eina_Bool exitHandler(void */*data*/, int /*type*/, void */*event*/)
42 auto& daemon = SecurityDaemonSingleton::Instance();
45 return ECORE_CALLBACK_CANCEL;
48 SecurityDaemon::SecurityDaemon() :
55 void SecurityDaemon::initialize(int& /*argc*/, char** /*argv*/)
57 DPL::Log::LogSystemSingleton::Instance().SetTag("SECURITY_DAEMON");
58 LogDebug("Initializing");
59 Assert(!m_initialized && "Already Initialized");
61 g_exitHandler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
65 DatabaseService::initialize();
66 FOREACH (service, m_servicesList) {
67 (*service)->initialize();
70 LogDebug("Initialized");
73 int SecurityDaemon::execute()
75 Assert(m_initialized && "Not Initialized");
76 LogDebug("Starting execute");
77 FOREACH (service, m_servicesList) {
80 ecore_main_loop_begin();
84 void SecurityDaemon::terminate(int returnValue)
86 Assert(m_initialized && "Not Initialized");
87 Assert(!m_terminating && "Already terminating");
88 LogDebug("Terminating");
90 ecore_event_handler_del(g_exitHandler);
92 m_returnValue = returnValue;
95 FOREACH (service, m_servicesList) {
99 ecore_main_loop_quit();
102 void SecurityDaemon::shutdown()
104 LogDebug("Shutdown");
105 Assert(m_initialized && "Not Initialized");
106 Assert(m_terminating && "Not terminated");
108 DatabaseService::deinitialize();
109 FOREACH (service, m_servicesList) {
110 (*service)->deinitialize();
113 m_initialized = false;
116 namespace DatabaseService {
118 void initialize(void)
120 LogDebug("Ace/Wrt database services initializing...");
121 AceDB::AceDAO::attachToThreadRW();
124 void deinitialize(void)
126 LogDebug("Ace/Wrt database services deinitializing...");
127 AceDB::AceDAO::detachFromThread();
130 } //namespace DatabaseService
132 } //namespace SecurityDaemon