2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file SecuritySocketClient.h
18 * @author Zofia Abramowska (z.abramowska@samsung.com)
20 * @brief Header of socket client class.
23 #ifndef SECURITYSOCKETCLIENT_H_
24 #define SECURITYSOCKETCLIENT_H_
28 #include <dpl/log/log.h>
29 #include "SocketConnection.h"
32 * Methods connect(), call() and disconnected() should be called one by one.
33 * Between connect() and disconnect() you can use call() only once.
34 * It is because of timeout on call, e.g. to avoid waiting for corrupted data.
38 * Class should be used according to this scheme:
39 * SecuritySocketClient client("Interface Name");
42 * client.call("Method name", in_arg1, in_arg2, ..., in_argN,
43 * out_arg1, out_arg2, ..., out_argM);
44 * client.disconnect();
47 * input parameters of the call are passed with reference,
48 * output ones are passed as pointers - parameters MUST be passed this way.
50 * Currently client supports serialization and deserialization of simple types
51 * (int, char, float, unsigned), strings (std::string and char*) and
52 * some STL containers (std::vector, std::list, std::map, std::pair).
53 * Structures and classes are not (yet) supported.
56 class SecuritySocketClient {
61 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
62 DECLARE_EXCEPTION_TYPE(Base, SecuritySocketClientException)
65 SecuritySocketClient(const std::string &interfaceName);
69 void call(std::string methodName){
70 make_call(m_interfaceName);
71 make_call(methodName);
74 template<typename ...Args>
75 void call(std::string methodName, const Args&... args){
76 make_call(m_interfaceName);
77 make_call(methodName);
82 template<typename T, typename ...Args>
83 void make_call(const T& invalue, const Args&... args){
89 void make_call(const T& invalue){
91 m_socketConnector->write(invalue);
93 Catch (SocketConnection::Exception::SocketConnectionException){
94 LogError("Socket connection write error");
95 ReThrowMsg(Exception::SecuritySocketClientException,"Socket connection write error");
99 template<typename T, typename ...Args>
100 void make_call(const T* invalue, const Args&... args){
106 void make_call(const T* invalue){
108 m_socketConnector->write(invalue);
110 Catch (SocketConnection::Exception::SocketConnectionException){
111 LogError("Socket connection write error");
112 ReThrowMsg(Exception::SecuritySocketClientException,"Socket connection write error");
116 template<typename T, typename ...Args>
117 void make_call(T * outvalue, const Args&... args){
123 void make_call(T* outvalue){
125 m_socketConnector->read(outvalue);
127 Catch (SocketConnection::Exception::SocketConnectionException){
128 LogError("Socket connection read error");
129 ReThrowMsg(Exception::SecuritySocketClientException,"Socket connection read error");
135 void throwWithErrnoMessage(const std::string& specificInfo);
136 std::string m_serverAddress;
137 std::string m_interfaceName;
138 std::unique_ptr<SocketConnection> m_socketConnector;
142 #endif /* SECURITYSOCKETCLIENT_H_ */