2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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.
20 /* standard library header */
22 /* SLP library header */
25 #include "Synchronous.h"
26 #include "ByteArray.h"
27 #include "Exception.h"
29 namespace smartcard_service_api
31 class SessionHelper; /* explicit declaration */
33 typedef void (*transmitCallback)(unsigned char *buffer,
34 unsigned int length, int error, void *userParam);
35 typedef void (*closeChannelCallback)(int error, void *userParam);
37 class Channel : public Synchronous
40 ByteArray selectResponse;
41 ByteArray transmitResponse;
42 SessionHelper *session;
45 Channel() : session(NULL), channelNum(-1) {}
46 Channel(SessionHelper *session) : session(session), channelNum(-1) {}
48 inline void setSelectResponse(const ByteArray &response) { selectResponse = response; }
51 virtual ~Channel() {};
53 inline bool isBasicChannel() const throw() { return (channelNum == 0); }
54 inline bool isClosed() const throw() { return (channelNum < 0); }
56 inline const ByteArray getSelectResponse() const throw() { return selectResponse; }
57 inline const ByteArray getTransmitResponse() const throw() { return transmitResponse; }
58 inline SessionHelper *getSession() const throw() { return session; }
60 virtual int close(closeChannelCallback callback, void *userParam) = 0;
61 virtual int transmit(const ByteArray &command, transmitCallback callback, void *userData) = 0;
63 virtual void closeSync()
64 throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
65 ErrorIllegalState &, ErrorIllegalParameter &) = 0;
67 virtual int transmitSync(const ByteArray &command, ByteArray &result)
68 throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
69 ErrorIllegalParameter &, ErrorSecurity &) = 0;
72 } /* namespace smartcard_service_api */
73 #endif /* CHANNEL_H_ */