tizen 2.3 release
[framework/web/wearable/wrt-security.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 #include <dpl/log/log.h>
31
32 namespace WrtSecurity{
33 namespace Communication{
34
35   Client::Client(const std::string& interfaceName){
36     #if DBUS_CONNECTION
37       LogInfo("DBus create");
38     Try {
39       m_dbusClient.reset(new DPL::DBus::Client(WrtSecurity::SecurityDaemonConfig::OBJECT_PATH(),
40                          WrtSecurity::SecurityDaemonConfig::SERVICE_NAME(),
41                          interfaceName));
42     } Catch (DPL::DBus::Client::Exception::DBusClientException) {
43       LogError("Error getting connection");
44       ReThrowMsg(Exception::SecurityCommunicationClientException,
45                "Error getting connection");
46     }
47     if(NULL == m_dbusClient.get()){
48       LogError("Couldn't get client");
49       ThrowMsg(Exception::SecurityCommunicationClientException,
50                "Error getting client");
51     }
52     #endif //DBUS_CONNECTION
53
54     #ifdef SOCKET_CONNECTION
55     m_socketClient.reset(new SecuritySocketClient(interfaceName));
56     if(NULL == m_socketClient.get()){
57         LogError("Couldn't get client");
58         ThrowMsg(Exception::SecurityCommunicationClientException,
59                  "Error getting client");
60     }
61     #endif //SOCKET_CONNECTION
62     LogDebug("Created wrt-security communication client");
63   }
64
65   void Client::connect(){
66     #ifdef SOCKET_CONNECTION
67       Try {
68           m_socketClient->connect();
69       } Catch(SecuritySocketClient::Exception::SecuritySocketClientException){
70           LogError("Couldn't connect");
71           ReThrowMsg(Exception::SecurityCommunicationClientException,
72                      "Error connecting");
73       }
74
75     #endif //SOCKET_CONNECTION
76       LogDebug("Wrt-security client Connected");
77   }
78
79   void Client::disconnect(){
80
81     #ifdef SOCKET_CONNECTION
82       m_socketClient->disconnect();
83     #endif //SOCKET_CONNECTION
84       LogDebug("Wrt-security client Disconnected");
85   }
86
87
88 } // namespace Communication
89
90 } // namespace WrtSecurity
91