Fix the Prevent problems
[platform/core/connectivity/smartcard-service.git] / common / include / SessionHelper.h
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 #ifndef SESSIONHELPER_H_
18 #define SESSIONHELPER_H_
19
20 /* standard library header */
21 #include <vector>
22
23 /* SLP library header */
24
25 /* local header */
26 #include "Synchronous.h"
27 #include "ByteArray.h"
28 #include "Channel.h"
29
30 using namespace std;
31
32 namespace smartcard_service_api
33 {
34         class ReaderHelper;
35
36         typedef void (*openChannelCallback)(Channel *channel, int error, void *userData);
37         typedef void (*getATRCallback)(unsigned char *atr, unsigned int length, int error, void *userData);
38         typedef void (*closeSessionCallback)(int error, void *userData);
39         typedef void (*getChannelCountCallback)(unsigned count, int error, void *userData);
40
41         class SessionHelper : public Synchronous
42         {
43         protected:
44                 ReaderHelper *reader;
45                 vector<Channel *> channels;
46                 ByteArray atr;
47                 bool closed;
48
49         public:
50                 SessionHelper(ReaderHelper *reader) :
51                         reader(reader), closed(true) {}
52                 virtual ~SessionHelper() {}
53
54                 ReaderHelper *getReader() const throw() { return reader; }
55                 bool isClosed() const throw() { return closed; }
56
57                 virtual void closeChannels()
58                         throw(ErrorIO &, ErrorIllegalState &) = 0;
59
60                 virtual int getATR(getATRCallback callback, void *userData) = 0;
61                 virtual int close(closeSessionCallback callback, void *userData) = 0;
62
63                 virtual int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData) = 0;
64                 virtual int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
65                 virtual int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData) = 0;
66                 virtual int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
67
68                 virtual const ByteArray getATRSync()
69                         throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
70                         ErrorIllegalState &, ErrorIllegalParameter &) = 0;
71
72                 virtual void closeSync()
73                         throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
74                         ErrorIllegalState &, ErrorIllegalParameter &) = 0;
75
76                 virtual Channel *openBasicChannelSync(const ByteArray &aid)
77                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
78                                 ErrorIllegalParameter &, ErrorSecurity &) = 0;
79
80                 virtual Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
81                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
82                                 ErrorIllegalParameter &, ErrorSecurity &) = 0;
83
84                 virtual Channel *openLogicalChannelSync(const ByteArray &aid)
85                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
86                                 ErrorIllegalParameter &, ErrorSecurity &) = 0;
87
88                 virtual Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
89                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
90                                 ErrorIllegalParameter &, ErrorSecurity &) = 0;
91         };
92
93 } /* namespace smartcard_service_api */
94 #endif /* SESSIONHELPER_H_ */