Make generateAppLabel() a static funcion of SmackRules class
[platform/core/security/security-manager.git] / src / server / main / server-main.cpp
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Rafal Krypa <r.krypa@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  * @file        server-main.cpp
20  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21  * @version     1.0
22  * @brief       Implementation of security-manager on basis of security-server
23  */
24 #include <stdlib.h>
25 #include <signal.h>
26
27 #include <dpl/log/log.h>
28 #include <dpl/singleton.h>
29 #include <dpl/singleton_safe_impl.h>
30
31 #include <socket-manager.h>
32
33 #include <installer.h>
34
35 IMPLEMENT_SAFE_SINGLETON(SecurityManager::Log::LogSystem);
36
37 #define REGISTER_SOCKET_SERVICE(manager, service) \
38     registerSocketService<service>(manager, #service)
39
40 template<typename T>
41 void registerSocketService(SecurityManager::SocketManager &manager, const std::string& serviceName)
42 {
43     T *service = NULL;
44     try {
45         service = new T();
46         service->Create();
47         manager.RegisterSocketService(service);
48         service = NULL;
49     } catch (const SecurityManager::Exception &exception) {
50         LogError("Error in creating service " << serviceName <<
51                  ", details:\n" << exception.DumpToString());
52     } catch (const std::exception& e) {
53         LogError("Error in creating service " << serviceName <<
54                  ", details:\n" << e.what());
55     } catch (...) {
56         LogError("Error in creating service " << serviceName <<
57                  ", unknown exception occured");
58     }
59     if (service)
60         delete service;
61 }
62
63 int main(void) {
64
65     UNHANDLED_EXCEPTION_HANDLER_BEGIN
66     {
67         SecurityManager::Singleton<SecurityManager::Log::LogSystem>::Instance().SetTag("SECURITY_MANAGER");
68
69         sigset_t mask;
70         sigemptyset(&mask);
71         sigaddset(&mask, SIGTERM);
72         sigaddset(&mask, SIGPIPE);
73         if (-1 == pthread_sigmask(SIG_BLOCK, &mask, NULL)) {
74             LogError("Error in pthread_sigmask");
75             return 1;
76         }
77
78         LogInfo("Start!");
79         SecurityManager::SocketManager manager;
80
81         REGISTER_SOCKET_SERVICE(manager, SecurityManager::InstallerService);
82
83         manager.MainLoop();
84     }
85     UNHANDLED_EXCEPTION_HANDLER_END
86     return 0;
87 }