bff7d3ace8bebfc796766c5942ee209acb852a90
[framework/web/wrt-plugins-tizen.git] / src / SecureElement / EventSEService.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18
19 #ifndef WRTPLUGINS_API_EVENT_SE_SERVICE_H_
20 #define WRTPLUGINS_API_EVENT_SE_SERVICE_H_
21
22 #include <vector>
23 #include <Commons/IEvent.h>
24 #include <Commons/ListenerEvent.h>
25 #include <Commons/ListenerEventEmitter.h>
26 #include <dpl/shared_ptr.h>
27
28 namespace DeviceAPI {
29 namespace SecureElement {
30
31 template <class templateClass>
32 class EventSETemplate : public WrtDeviceApis::Commons::IEvent<templateClass>
33 {
34 protected:
35         bool result;
36         std::string errorCode;
37 public:
38         void setResult(const bool value) {result = value;}
39         bool getResult() const {return result;}
40         void setError(const std::string &error) { errorCode= error;}
41         std::string getError() {return errorCode;}
42         EventSETemplate() :result(true) { }
43 };
44
45 template <class templateEventClass>
46 class EventSEPtrs
47 {
48 private:
49         DPL::SharedPtr<templateEventClass> eventPtr;
50         void * thisPtr;
51 public:
52         DPL::SharedPtr<templateEventClass> getEventPtrs() const {return eventPtr;}
53         void *getThisPtr() {return thisPtr;}
54         EventSEPtrs(const DPL::SharedPtr<templateEventClass> &event, void *myPtr) : eventPtr(event), thisPtr(myPtr) {}
55 };
56
57 enum SEState {
58         SE_INSERTED,
59         SE_REMOVED,
60         SE_NOCHANED
61 };
62 class EventSEStateChanged : public WrtDeviceApis::Commons::ListenerEvent<EventSEStateChanged>
63 {
64 private:
65         SEState state;
66         void *reader;
67 public:
68         void setSEState(SEState value) {state = value;}
69         SEState getSEState()  {return state;}
70         void setReader(void *changedReader) {reader = changedReader;}
71         void *getReader()  {return reader;}
72         EventSEStateChanged(): state(SE_NOCHANED){ }
73 };
74
75 class EventListSEs : public EventSETemplate<EventListSEs>
76 {
77 protected:
78         std::vector<void *> seList;
79 public:
80         EventListSEs() { }
81         std::vector<void *> getListSEs() {return seList;}
82         void addSEs(void *se) {seList.push_back(se);}
83 };
84
85 class EventSEOpenSession : public EventSETemplate<EventSEOpenSession>
86 {
87 protected:
88         void * m_session;
89 public:
90         EventSEOpenSession() {}
91         void setSession(void *session) {m_session = session;}
92         void *getSession() {return m_session;}
93 };
94
95 class EventSEOpenChannel : public EventSETemplate<EventSEOpenChannel>
96 {
97 protected:
98         std::vector<unsigned char> m_AID;
99         bool bBasicChannel;
100         void * m_channel;
101 public:
102         EventSEOpenChannel(std::vector<unsigned char> aid, bool isBasicChannel) {m_AID = aid; this->bBasicChannel = isBasicChannel;}
103         std::vector<unsigned char> getAID() {return m_AID;}
104         void setChannel(void *channel) {m_channel = channel;}
105         void *getChannel() {return m_channel;}
106         bool isBasicChannel() {return bBasicChannel;}
107 };
108
109 class EventSEChannelTransmit : public EventSETemplate<EventSEChannelTransmit>
110 {
111 protected:
112         std::vector<unsigned char> m_sendData;
113         std::vector<unsigned char> m_respData;
114 public:
115         EventSEChannelTransmit(std::vector<unsigned char> data) {m_sendData = data;}
116         std::vector<unsigned char> getSendData() {return m_sendData;}
117         void setResponse(std::vector<unsigned char> resp) {m_respData = resp;}
118         std::vector<unsigned char> getResponse() {return m_respData;}
119 };
120
121 typedef DPL::SharedPtr<EventSEStateChanged> EventSEStateChangedPtr;
122 typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventSEStateChanged> EventSEStateChangedEmitter;
123 typedef DPL::SharedPtr<EventSEStateChangedEmitter> EventSEStateChangedEmitterPtr;
124
125 typedef DPL::SharedPtr<EventListSEs> EventListSEsPtr;
126 typedef DPL::SharedPtr<EventSEOpenSession> EventSEOpenSessionPtr;
127 typedef DPL::SharedPtr<EventSEOpenChannel> EventSEOpenChannelPtr;
128 typedef DPL::SharedPtr<EventSEChannelTransmit> EventSEChannelTransmitPtr;
129 } // SecureElement
130 } // DeviceAPI
131
132 #endif //WRTPLUGINS_API_EVENT_SE_SERVICE_H_