Apply tizen 2.4 smartcard-service
[platform/core/connectivity/smartcard-service.git] / common / include / Channel.h
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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 #ifndef CHANNEL_H_
18 #define CHANNEL_H_
19
20 /* standard library header */
21
22 /* SLP library header */
23
24 /* local header */
25 #include "Synchronous.h"
26 #include "ByteArray.h"
27 #include "Exception.h"
28
29 namespace smartcard_service_api
30 {
31         class SessionHelper;    /* explicit declaration */
32
33         typedef void (*transmitCallback)(unsigned char *buffer,
34                 unsigned int length, int error, void *userParam);
35         typedef void (*closeChannelCallback)(int error, void *userParam);
36
37         class Channel : public Synchronous
38         {
39         protected :
40                 ByteArray selectResponse;
41                 ByteArray transmitResponse;
42                 SessionHelper *session;
43                 int channelNum;
44
45                 Channel() : session(NULL), channelNum(-1) {}
46                 Channel(SessionHelper *session) : session(session), channelNum(-1) {}
47
48                 inline void setSelectResponse(const ByteArray &response) { selectResponse = response; }
49
50         public :
51                 virtual ~Channel() {};
52
53                 inline bool isBasicChannel() const throw() { return (channelNum == 0); }
54                 inline bool isClosed() const throw() { return (channelNum < 0); }
55
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; }
59
60                 virtual int close(closeChannelCallback callback, void *userParam) = 0;
61                 virtual int transmit(const ByteArray &command, transmitCallback callback, void *userData) = 0;
62
63                 virtual void closeSync()
64                         throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
65                         ErrorIllegalState &, ErrorIllegalParameter &) = 0;
66
67                 virtual int transmitSync(const ByteArray &command, ByteArray &result)
68                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
69                                 ErrorIllegalParameter &, ErrorSecurity &) = 0;
70         };
71
72 } /* namespace smartcard_service_api */
73 #endif /* CHANNEL_H_ */