tizen 2.3 release
[framework/web/wearable/wrt-security.git] / src / daemon / security_daemon.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_daemon.cpp
18  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @version     1.0
20  * @brief       This is implementation file of Security Daemon
21  */
22
23 #include "security_daemon.h"
24
25 #include <dpl/assert.h>
26 #include <dpl/foreach.h>
27 #include <dpl/log/log.h>
28 #ifdef DBUS_CONNECTION
29 #include <dpl/framework_efl.h>
30 #endif
31
32 #include <dpl/singleton_impl.h>
33 IMPLEMENT_SINGLETON(SecurityDaemon::SecurityDaemon)
34
35 #include <ace-dao-rw/AceDAO.h>
36
37 namespace SecurityDaemon {
38
39 SecurityDaemon::SecurityDaemon() :
40     m_initialized(false),
41     m_terminating(false),
42     m_returnValue(0)
43 {
44 }
45
46 void SecurityDaemon::initialize(int& /*argc*/, char** /*argv*/)
47 {
48     DPL::Log::LogSystemSingleton::Instance().SetTag("SECURITY_DAEMON");
49     LogDebug("Initializing");
50     Assert(!m_initialized && "Already Initialized");
51
52     DatabaseService::initialize();
53     FOREACH (service, m_servicesList) {
54         (*service)->initialize();
55     }
56     m_initialized = true;
57     LogDebug("Initialized");
58 }
59
60 int SecurityDaemon::execute()
61 {
62     Assert(m_initialized && "Not Initialized");
63     LogDebug("Starting execute");
64     FOREACH (service, m_servicesList) {
65         (*service)->start();
66     }
67
68     return m_returnValue;
69 }
70
71 void SecurityDaemon::terminate(int returnValue)
72 {
73     Assert(m_initialized && "Not Initialized");
74     Assert(!m_terminating && "Already terminating");
75     LogDebug("Terminating");
76
77     m_returnValue = returnValue;
78     m_terminating = true;
79
80     FOREACH (service, m_servicesList) {
81         (*service)->stop();
82     }
83 }
84
85 void SecurityDaemon::shutdown()
86 {
87     LogDebug("Shutdown");
88     Assert(m_initialized && "Not Initialized");
89
90     DatabaseService::deinitialize();
91     FOREACH (service, m_servicesList) {
92         (*service)->deinitialize();
93     }
94
95     m_initialized = false;
96 }
97
98 namespace DatabaseService {
99
100 void initialize(void)
101 {
102     LogDebug("Ace/Wrt database services initializing...");
103     AceDB::AceDAO::attachToThreadRW();
104 }
105
106 void deinitialize(void)
107 {
108     LogDebug("Ace/Wrt database services deinitializing...");
109     AceDB::AceDAO::detachFromThread();
110 }
111
112 } //namespace DatabaseService
113
114 } //namespace SecurityDaemon