Tizen 2.1 base
[platform/framework/web/wrt-security.git] / src / services / ocsp / ocsp_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        ocsp_service.cpp
18  * @author      Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
19  * @version     1.0
20  * @brief       This is implementation file of Ocsp service
21  */
22
23
24 #include <string>
25 #include <list>
26 #include <memory>
27
28 #include <dpl/log/log.h>
29 #include <dpl/single_instance.h>
30 #include <dpl/event/controller.h>
31 #include <dpl/thread.h>
32 #include <vcore/VCore.h>
33 #include <dpl/wrt-dao-ro/WrtDatabase.h>
34 #include "security_daemon.h"
35 #include "security_dbus_service.h"
36 #include "ocsp_server_dbus_interface.h"
37 #include "ocsp_controller.h"
38
39
40 namespace {
41
42
43 class OCSPThread :
44     public DPL::Thread
45 {
46   protected:
47     virtual int ThreadEntry()
48     {
49         // Attach databases
50         ValidationCore::AttachToThread();
51         WrtDB::WrtDatabase::attachToThread();
52
53         int result = DPL::Thread::ThreadEntry();
54
55         // Detach databases
56         ValidationCore::DetachFromThread();
57         WrtDB::WrtDatabase::detachFromThread();
58
59         return result;
60     }
61 };
62
63 } //anonymous namespace
64
65 namespace OcspService {
66
67 class OcspService : public SecurityDaemon::DaemonService
68 {
69   private:
70     virtual void initialize()
71     {
72         //Init OCSP thread
73         m_threadOCSP.reset(new OCSPThread());
74         m_threadOCSP->Run();
75         OCSPControllerSingleton::Instance().Touch();
76         OCSPControllerSingleton::Instance().SwitchToThread(m_threadOCSP.get());
77     }
78
79     virtual void start()
80     {
81     }
82
83     virtual void stop()
84     {
85     }
86
87     virtual void deinitialize()
88     {
89         //Deinitialize OCSP thread
90         OCSPControllerSingleton::Instance().SwitchToThread(NULL);
91         m_threadOCSP->Quit();
92         m_threadOCSP.reset();
93     }
94
95     std::shared_ptr<OCSPThread> m_threadOCSP;
96
97 };
98
99 DAEMON_REGISTER_SERVICE_MODULE(OcspService)
100
101 }//namespace OcspService
102