Extract communication functions to common library
[platform/core/security/security-manager.git] / src / client / client-common.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        client-common.cpp
20  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21  * @version     1.0
22  * @brief       This file is implementation of client-common functions.
23  */
24
25 #include <fcntl.h>
26 #include <poll.h>
27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <sys/un.h>
30 #include <sys/smack.h>
31 #include <sys/xattr.h>
32 #include <linux/xattr.h>
33 #include <unistd.h>
34
35 #include <dpl/log/log.h>
36 #include <dpl/serialization.h>
37 #include <dpl/singleton.h>
38 #include <dpl/singleton_safe_impl.h>
39
40 #include <message-buffer.h>
41
42 #include <protocols.h>
43
44 IMPLEMENT_SAFE_SINGLETON(SecurityManager::Log::LogSystem);
45
46 namespace {
47
48 void securityClientEnableLogSystem(void) {
49     SecurityManager::Singleton<SecurityManager::Log::LogSystem>::Instance().SetTag("SECURITY_MANAGER_CLIENT");
50 }
51
52 } // namespace anonymous
53
54 namespace SecurityManager {
55
56 int try_catch(const std::function<int()>& func)
57 {
58     try {
59         return func();
60     } catch (MessageBuffer::Exception::Base &e) {
61         LogError("SecurityManager::MessageBuffer::Exception " << e.DumpToString());
62     } catch (std::exception &e) {
63         LogError("STD exception " << e.what());
64     } catch (...) {
65         LogError("Unknown exception occured");
66     }
67     return SECURITY_MANAGER_API_ERROR_UNKNOWN;
68 }
69
70 } // namespace SecurityMANAGER
71
72 static void init_lib(void) __attribute__ ((constructor));
73 static void init_lib(void)
74 {
75     securityClientEnableLogSystem();
76 }
77
78 static void fini_lib(void) __attribute__ ((destructor));
79 static void fini_lib(void)
80 {
81
82 }
83