Add card Inserted implementation and fix bug
[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 /* standard library header */
21
22 /* SLP library header */
23
24 /* local header */
25 #include "ByteArray.h"
26 #include "Synchronous.h"
27
28 namespace smartcard_service_api
29 {
30         /* LCOV_EXCL_START */
31         typedef void (*terminalNotificationCallback)(const void *terminal, int event, int error, void *user_param);
32
33         typedef void (*terminalTransmitCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
34         typedef void (*terminalGetATRCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
35
36         class Terminal : public Synchronous
37         {
38         protected:
39                 terminalNotificationCallback statusCallback;
40                 bool initialized;
41                 bool closed;
42                 char *name;
43
44         public:
45                 static const int NOTIFY_SE_AVAILABLE = 1;
46                 static const int NOTIFY_SE_NOT_AVAILABLE = -1;
47                 static const int NOTIFY_CARD_AVAILABLE = 2;
48                 static const int NOTIFY_CARD_NOT_AVAILABLE = -2;
49
50                 Terminal() : statusCallback(NULL), initialized(false),
51                         closed(true), name(NULL) {}
52
53                 virtual ~Terminal() {}
54
55                 virtual bool initialize() = 0;
56                 virtual void finalize() = 0;
57                 inline bool isInitialized() const { return initialized; }
58
59                 virtual bool open() = 0;
60                 virtual void close() = 0;
61                 inline bool isClosed() const { return closed; }
62
63                 inline const char *getName() const { return name; }
64                 inline void setStatusCallback(terminalNotificationCallback callback) { statusCallback = callback; }
65
66                 virtual bool isSecureElementPresence() const = 0;
67
68                 virtual int transmitSync(const ByteArray &command, ByteArray &result) = 0;
69                 virtual int getATRSync(ByteArray &atr) = 0;
70
71                 virtual int transmit(const ByteArray &command, terminalTransmitCallback callback, void *userData) = 0;
72                 virtual int getATR(terminalGetATRCallback callback, void *userData) = 0;
73         };
74
75         /* LCOV_EXCL_STOP */
76 } /* namespace smartcard_service_api */
77 #endif /* TERMINAL_H_ */