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,
40 class NFCListenerManager : public DeviceAPI::Common::IListenerController
47 virtual ~NFCListenerManager()
52 typedef DPL::Singleton<NFCListenerManager> NFCListenerManagerSingleton;
54 class NFCListenerCanceller : public DeviceAPI::Common::IListenerItem
57 NFCListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
58 DeviceAPI::Common::IListenerItem(context, object, watchId)
62 virtual ~NFCListenerCanceller()
66 virtual void cancelListener()
68 LogDebug("context : " << m_context);
69 LogDebug("object : " << m_object);
71 case ID_NFCPEER_RECEIVENDEF_LISTENER:
73 NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(m_object));
74 if (NULL == privateObject) {
75 LogWarning("Object has no privateObject");
79 INFCTargetPtr nfcTarget(privateObject->getObject());
80 nfcTarget->unsetReceiveNDEFListener();
83 case ID_NFCADAPTER_TAG_LISTENER:
84 case ID_NFCADAPTER_PEER_LISTENER:
86 NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(m_object));
87 if (NULL == privateObject) {
88 LogError("Object has no privateObject");
92 INFCAdapterPtr nfcAdapter( privateObject->getObject());
93 if (ID_NFCADAPTER_TAG_LISTENER == m_watchId)
94 nfcAdapter->unsetTagListener();
96 nfcAdapter->unsetPeerListener();
97 } Catch(WrtDeviceApis::Commons::Exception) {
98 LogError("Error on platform : " << _rethrown_exception.GetMessage());
104 LogError("Wrong ID");
108 typedef DPL::SharedPtr<NFCListenerCanceller> NFCListenerCancellerPtr;
113 #endif // _TIZEN_NFC_LISTENER_MANAGER_H_