13b137e6003a1fcbadf99f8caf65f4cc4429f07e
[framework/security/security-server.git] / communication_client / src / SecurityCommunicationClient.cpp
1 /*
2  * Copyright (c) 2012 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        SecurityCommunicationClient.h
18  * @author      Zofia Abramowska (z.abramowska@samsung.com)
19  * @version     1.0
20  * @brief       This is implementation of class used IPC client
21  */
22
23
24 #include "SecurityCommunicationClient.h"
25
26 #ifdef DBUS_CONNECTION
27 #include "security_daemon_dbus_config.h"
28 #endif
29
30 namespace WrtSecurity{
31 namespace Communication{
32
33   Client::Client(const std::string& interfaceName){
34     #if DBUS_CONNECTION
35       LogInfo("DBus create");
36     Try {
37       m_dbusClient.reset(new DPL::DBus::Client(WrtSecurity::SecurityDaemonConfig::OBJECT_PATH(),
38                          WrtSecurity::SecurityDaemonConfig::SERVICE_NAME(),
39                          interfaceName));
40     } Catch (DPL::DBus::Client::Exception::DBusClientException) {
41       LogError("Error getting connection");
42       ReThrowMsg(Exception::SecurityCommunicationClientException,
43                "Error getting connection");
44     }
45     if(NULL == m_dbusClient.get()){
46       LogError("Couldn't get client");
47       ThrowMsg(Exception::SecurityCommunicationClientException,
48                "Error getting client");
49     }
50     #endif //DBUS_CONNECTION
51
52     #ifdef SOCKET_CONNECTION
53     m_socketClient.reset(new SecuritySocketClient(interfaceName));
54     if(NULL == m_socketClient.get()){
55         LogError("Couldn't get client");
56         ThrowMsg(Exception::SecurityCommunicationClientException,
57                  "Error getting client");
58     }
59     #endif //SOCKET_CONNECTION
60     LogInfo("Created communication client");
61   }
62
63   void Client::connect(){
64     #ifdef SOCKET_CONNECTION
65       Try {
66           m_socketClient->connect();
67       } Catch(SecuritySocketClient::Exception::SecuritySocketClientException){
68           LogError("Couldn't connect");
69           ReThrowMsg(Exception::SecurityCommunicationClientException,
70                      "Error connecting");
71       }
72
73     #endif //SOCKET_CONNECTION
74       LogInfo("Connected");
75   }
76
77   void Client::disconnect(){
78
79     #ifdef SOCKET_CONNECTION
80       m_socketClient->disconnect();
81     #endif //SOCKET_CONNECTION
82     LogInfo("Disconnected");
83   }
84
85
86 } // namespace Communication
87
88 } // namespace WrtSecurity
89