Introduced Container Daemon
[platform/core/security/vasum.git] / container-daemon / runner.cpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Jan Olszak (j.olszak@samsung.com)
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19 /**
20  * @file
21  * @author  Jan Olszak (j.olszak@samsung.com)
22  * @brief   Definition of the Runner class, that manages daemon's lifetime
23  */
24
25 #include "runner.hpp"
26 #include "daemon.hpp"
27
28 #include "log/logger.hpp"
29 #include "utils/glib-loop.hpp"
30 #include "utils/latch.hpp"
31
32 #include <csignal>
33
34
35 namespace security_containers {
36 namespace container_daemon {
37
38
39 Runner::Runner()
40 {
41 }
42
43
44 Runner::~Runner()
45 {
46 }
47
48
49 namespace {
50 utils::Latch gSignalLatch;
51
52 void signalHandler(const int sig)
53 {
54     LOGI("Got signal " << sig);
55     gSignalLatch.set();
56 }
57 } // namespace
58
59
60 void Runner::run()
61 {
62     signal(SIGINT,  signalHandler);
63     signal(SIGTERM, signalHandler);
64
65     LOGI("Starting Container Daemon...");
66     {
67         utils::ScopedGlibLoop loop;
68         LOGI("Container Daemon started");
69
70         // Connects to dbus and registers API
71         container_daemon::Daemon daemon;
72
73         gSignalLatch.wait();
74
75         LOGI("Stopping Container Daemon...");
76
77     }
78     LOGI("Daemon stopped");
79 }
80
81 void Runner::terminate()
82 {
83     LOGI("Terminating Container Daemon");
84     gSignalLatch.set();
85 }
86
87 } // namespace container_daemon
88 } // namespace security_containers