Change some indent for Tizen 3.0 Coding rule
[platform/core/api/smartcard.git] / include / Session.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 SESSION_H_
18 #define SESSION_H_
19
20 /* standard library header */
21 #include <gio/gio.h>
22
23 /* SLP library header */
24
25 /* local header */
26 #include "smartcard-types.h"
27 #ifdef __cplusplus
28 #include "SessionHelper.h"
29 #endif /* __cplusplus */
30
31 #ifdef __cplusplus
32 namespace smartcard_service_api
33 {
34         class Reader;
35
36         class Session:public SessionHelper
37         {
38 private:
39                 void *context;
40                 void *handle;
41                 void *proxy;
42
43                 Session(void *context, Reader *reader, void *handle);
44                 ~Session();
45
46                 int openChannel(int id, const ByteArray &aid, openChannelCallback callback, void *userData);
47
48                 Channel *openChannelSync(int id, const ByteArray &aid)
49                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
50                                 ErrorIllegalParameter &, ErrorSecurity &);
51
52                 Channel *openChannelSync(int id, const ByteArray &aid, unsigned char P2)
53                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
54                                 ErrorIllegalParameter &, ErrorSecurity &);
55
56                 static void session_get_atr_cb(GObject *source_object,
57                         GAsyncResult *res, gpointer user_data);
58                 static void session_open_channel_cb(GObject *source_object,
59                         GAsyncResult *res, gpointer user_data);
60                 static void session_close_cb(GObject *source_object,
61                         GAsyncResult *res, gpointer user_data);
62
63 public:
64                 void closeChannels()
65                         throw(ErrorIO &, ErrorIllegalState &);
66
67                 int getATR(getATRCallback callback, void *userData);
68                 int close(closeSessionCallback callback, void *userData);
69
70                 int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData);
71                 int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
72                 int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData);
73                 int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
74
75                 const ByteArray getATRSync()
76                         throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
77                                 ErrorIllegalState &, ErrorIllegalParameter &);
78
79                 void closeSync()
80                         throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
81                                 ErrorIllegalState &, ErrorIllegalParameter &);
82
83                 Channel *openBasicChannelSync(const ByteArray &aid)
84                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
85                                 ErrorIllegalParameter &, ErrorSecurity &);
86
87                 Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
88                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
89                                 ErrorIllegalParameter &, ErrorSecurity &);
90
91                 Channel *openLogicalChannelSync(const ByteArray &aid)
92                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
93                                 ErrorIllegalParameter &, ErrorSecurity &);
94
95                 Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
96                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
97                                 ErrorIllegalParameter &, ErrorSecurity &);
98
99                 Channel *openBasicChannelSync(const ByteArray &aid, unsigned char P2)
100                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
101                                 ErrorIllegalParameter &, ErrorSecurity &);
102
103                 Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2)
104                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
105                                 ErrorIllegalParameter &, ErrorSecurity &);
106
107                 Channel *openLogicalChannelSync(const ByteArray &aid, unsigned char P2)
108                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
109                                 ErrorIllegalParameter &, ErrorSecurity &);
110
111                 Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2)
112                         throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
113                                 ErrorIllegalParameter &, ErrorSecurity &);
114
115                 size_t getChannelCount() const;
116                 void *getHandle() { return handle; }
117
118                 friend class Reader;
119         };
120 } /* namespace smartcard_service_api */
121 #endif /* __cplusplus */
122
123 /* export C API */
124 #ifdef __cplusplus
125 extern "C"
126 {
127 #endif /* __cplusplus */
128
129 int session_get_reader(session_h handle, int* reader_handle);
130 int session_is_closed(session_h handle, bool* is_closed);
131 int session_close_channels(session_h handle);
132 int session_get_atr_sync(session_h handle, unsigned char **buffer, unsigned int *length);
133 int session_close_sync(session_h handle);
134 int session_open_basic_channel_sync(session_h handle, unsigned char *aid,
135         unsigned int length, unsigned char P2, int* channel_handle);
136 int session_open_logical_channel_sync(session_h handle, unsigned char *aid,
137         unsigned int length, unsigned char P2, int* channel_handle);
138 ///
139
140 int session_get_atr(session_h handle, session_get_atr_cb callback,
141         void *userData);
142 int session_close(session_h handle, session_close_session_cb callback,
143         void *userData);
144 int session_open_basic_channel(session_h handle, unsigned char *aid,
145         unsigned int length, session_open_channel_cb callback, void *userData);
146 int session_open_logical_channel(session_h handle, unsigned char *aid,
147         unsigned int length, session_open_channel_cb callback, void *userData);
148 size_t session_get_channel_count(session_h handle);
149 __attribute__((deprecated)) void session_destroy_instance(session_h handle);
150
151
152
153 #ifdef __cplusplus
154 }
155 #endif /* __cplusplus */
156
157 #endif /* SESSION_H_ */