2e0579f2973415b114c288ead7ee7f9902c8e58a
[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, unsigned int length,
34                 int error, void *userParam);
35         typedef void (*closeCallback)(int error, void *userParam);
36
37         class Channel : public Synchronous
38         {
39         protected :
40                 ByteArray selectResponse;
41                 SessionHelper *session;
42                 int channelNum;
43
44                 Channel() : Synchronous() { channelNum = -1; }
45                 Channel(SessionHelper *session) : Synchronous() { this->session = session; }
46
47                 inline void setSelectResponse(ByteArray &response) { selectResponse = response; }
48
49         public :
50                 virtual ~Channel() {};
51
52                 inline bool isBasicChannel() const throw() { return (channelNum == 0); }
53                 inline bool isClosed() const throw() { return (channelNum < 0); }
54
55                 inline ByteArray getSelectResponse() const throw() { return selectResponse; }
56                 inline SessionHelper *getSession() const throw() { return session; }
57
58                 virtual int close(closeCallback callback, void *userParam) = 0;
59                 virtual int transmit(ByteArray command, transmitCallback callback, void *userData) = 0;
60
61                 virtual void closeSync()
62                         throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
63                         ErrorIllegalState &, ErrorIllegalParameter &) = 0;
64
65                 virtual int transmitSync(ByteArray command, ByteArray &result)
66                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
67                                 ErrorIllegalParameter &, ErrorSecurity &) = 0;
68         };
69
70 } /* namespace smartcard_service_api */
71 #endif /* CHANNEL_H_ */