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.
19 #ifndef _TIZEN_NFC_LISTENER_MANAGER_H_
20 #define _TIZEN_NFC_LISTENER_MANAGER_H_
23 #include <JavaScriptCore/JavaScript.h>
24 #include <dpl/log/log.h>
25 #include <dpl/shared_ptr.h>
26 #include <dpl/singleton.h>
27 #include <IListenerManager.h>
28 #include "JSNFCAdapter.h"
29 #include "JSNFCTarget.h"
34 enum NFCListenerWatchID {
35 ID_NFCADAPTER_TAG_LISTENER = 1,
36 ID_NFCADAPTER_PEER_LISTENER,
37 ID_NFCPEER_RECEIVENDEF_LISTENER,
38 ID_NFCADAPTER_CARDEMULATION_LISTENER
41 class NFCListenerManager : public DeviceAPI::Common::IListenerController
48 virtual ~NFCListenerManager()
53 typedef DPL::Singleton<NFCListenerManager> NFCListenerManagerSingleton;
55 class NFCListenerCanceller : public DeviceAPI::Common::IListenerItem
58 NFCListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
59 DeviceAPI::Common::IListenerItem(context, object, watchId)
63 virtual ~NFCListenerCanceller()
67 virtual void cancelListener()
69 LogDebug("context : " << m_context);
70 LogDebug("object : " << m_object);
72 case ID_NFCPEER_RECEIVENDEF_LISTENER:
74 NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(m_object));
75 if (NULL == privateObject) {
76 LogWarning("Object has no privateObject");
80 INFCTargetPtr nfcTarget(privateObject->getObject());
81 nfcTarget->unsetReceiveNDEFListener();
84 case ID_NFCADAPTER_TAG_LISTENER:
85 case ID_NFCADAPTER_PEER_LISTENER:
87 NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(m_object));
88 if (NULL == privateObject) {
89 LogError("Object has no privateObject");
93 INFCAdapterPtr nfcAdapter( privateObject->getObject());
94 if (ID_NFCADAPTER_TAG_LISTENER == m_watchId)
95 nfcAdapter->unsetTagListener();
97 nfcAdapter->unsetPeerListener();
98 } Catch(WrtDeviceApis::Commons::Exception) {
99 LogError("Error on platform : " << _rethrown_exception.GetMessage());
103 case ID_NFCADAPTER_CARDEMULATION_LISTENER:
105 NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(m_object));
106 if (NULL == privateObject) {
107 LogError("Object has no privateObject");
111 INFCAdapterPtr nfcAdapter( privateObject->getObject());
112 nfcAdapter->unsetCardEmulationChangeListener();
113 } Catch(WrtDeviceApis::Commons::Exception) {
114 LogError("Error on platform : " << _rethrown_exception.GetMessage());
119 LogError("Wrong ID");
123 typedef DPL::SharedPtr<NFCListenerCanceller> NFCListenerCancellerPtr;
128 #endif // _TIZEN_NFC_LISTENER_MANAGER_H_