Change terminal interface
[platform/core/connectivity/smartcard-service.git] / common / include / Terminal.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 TERMINAL_H_
18 #define TERMINAL_H_
19
20 #include "Debug.h"
21 #include "ByteArray.h"
22 #include "Synchronous.h"
23
24 namespace smartcard_service_api
25 {
26         typedef void (*terminalNotificationCallback)(const void *terminal, int event, int error, void *user_param);
27
28         typedef void (*terminalTransmitCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
29         typedef void (*terminalGetATRCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
30
31         class EXPORT Terminal : public Synchronous
32         {
33         protected:
34                 terminalNotificationCallback statusCallback;
35                 bool initialized;
36                 bool closed;
37                 char *name;
38
39         public:
40                 static const int NOTIFY_SE_AVAILABLE = 1;
41                 static const int NOTIFY_SE_NOT_AVAILABLE = -1;
42
43                 Terminal() : statusCallback(NULL), initialized(false),
44                         closed(true), name(NULL) {}
45
46                 virtual ~Terminal() {}
47
48                 virtual bool initialize() = 0;
49                 virtual void finalize() = 0;
50                 inline bool isInitialized() const { return initialized; }
51
52                 virtual bool open() = 0;
53                 virtual void close() = 0;
54                 inline bool isClosed() const { return closed; }
55
56                 inline const char *getName() const { return name; }
57                 inline void setStatusCallback(terminalNotificationCallback callback) { statusCallback = callback; }
58
59                 virtual bool isSecureElementPresence() const = 0;
60
61                 virtual int transmitSync(const ByteArray &command, ByteArray &result) = 0;
62                 virtual int getATRSync(ByteArray &atr) = 0;
63
64                 virtual int transmit(const ByteArray &command, terminalTransmitCallback callback, void *userData) = 0;
65                 virtual int getATR(terminalGetATRCallback callback, void *userData) = 0;
66         };
67
68 } /* namespace smartcard_service_api */
69 #endif /* TERMINAL_H_ */