2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <dpl/log/log.h>
22 #include <Commons/Exception.h>
28 using namespace WrtDeviceApis;
29 using namespace smartcard_service_api;
32 namespace SecureElement {
35 static void openSessionCallback(SessionHelper *session, int error, void *userData) {
36 LogDebug("Callback openSessionCallback.");
38 SEReader *sePtr = (SEReader *)((EventSEPtrs<EventSEOpenSession> *)userData)->getThisPtr();
40 EventSEOpenSessionPtr event = ((EventSEPtrs<EventSEOpenSession> *)userData)->getEventPtrs();
41 sePtr->openSessionManualAnswer((void *)session, error, event);
44 LogError("Callback private data is NULL.");
50 SEReader::SEReader(void *reader)
55 ThrowMsg(Commons::UnknownException, "SecureElement Handler is Null Pointer.");
57 m_reader = (Reader *)reader;
63 m_reader->closeSessions();
67 std::string SEReader::getName() {
68 LogDebug("Enter" << m_reader->getName());
69 return m_reader->getName();
72 bool SEReader::isPresent() {
73 LogDebug("Enter" << m_reader->isSecureElementPresent());
74 return m_reader->isSecureElementPresent();
77 void SEReader::openSession(const EventSEOpenSessionPtr& event) {
79 EventRequestReceiver<EventSEOpenSession>::PostRequest(event);
82 void SEReader::closeSessions() {
84 m_reader->closeSessions();
87 void SEReader::openSessionManualAnswer(void *session, int error, const EventSEOpenSessionPtr &event) {
88 if ((error != 0) || session == NULL) {
89 event->setResult(false);
91 event->setSession(session);
92 event->setResult(true);
94 EventRequestReceiver<EventSEOpenSession>::ManualAnswer(event);
96 std::vector<SEOpenSessionDataPtr>::iterator it;
97 for (it = EventSEOpenSessions.begin(); it != EventSEOpenSessions.end(); ++it) {
98 if ((*it)->getEventPtrs() == event) {
99 EventSEOpenSessions.erase(it);
100 LogDebug("event is removed. (" << EventSEOpenSessions.size() << ")");
106 void SEReader::OnRequestReceived(const EventSEOpenSessionPtr& event) {
110 event->switchToManualAnswer();
112 SEOpenSessionDataPtr data( new EventSEPtrs<EventSEOpenSession>(event, this));
113 EventSEOpenSessions.push_back(data);
115 m_reader->openSession(openSessionCallback, data.Get());
116 } catch (const WrtDeviceApis::Commons::Exception& ex) {
117 LogError("Exception: " << ex.GetMessage());
118 event->setResult(false);
120 EventRequestReceiver<EventSEOpenSession>::ManualAnswer(event);