Update change log and spec for wrt-plugins-tizen_0.4.48-1
[platform/framework/web/wrt-plugins-tizen.git] / src / NFC / JSNFCAdapter.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 9765f38..5805a85
 #include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
 #include <CommonsJavaScript/Utils.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
+#include <JSWebAPIErrorFactory.h>
 #include <SecurityExceptions.h>
 #include <GlobalContextManager.h>
 #include <ArgumentValidator.h>
 #include <JSUtil.h>
-#include <JSWebAPIException.h>
 #include <PlatformException.h>
 
 #include "JSNFCManager.h"
@@ -46,7 +44,7 @@
 #include <Logger.h>
 
 using namespace std;
-using namespace DPL;
+
 using namespace DeviceAPI::Common;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
@@ -200,7 +198,7 @@ JSValueRef JSNFCAdapter::setTagListener (JSContextRef context, JSObjectRef objec
                NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
                if (!privateObject) {
                        LoggerE("private object is null");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+                       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
                }
 
                INFCAdapterPtr nfcAdapter(privateObject->getObject());
@@ -211,31 +209,31 @@ JSValueRef JSNFCAdapter::setTagListener (JSContextRef context, JSObjectRef objec
                    );
                EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
                emitter->setListener(&NFCStaticController::getInstance());
-               emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
+               emitter->setEventPrivateData(DPL::StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
 
                if (nfcAdapter->setTagListener(emitter, tagFilter) != 0)
                        Throw(WrtDeviceApis::Commons::UnknownException);
 
                NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_TAG_LISTENER)));
-               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
                NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
 
                return JSValueMakeUndefined(context);
     } Catch (BasePlatformException) {
         LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
-        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
+        return JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LoggerE("JSNFCAdapter::setTagListener : ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
     } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch (WrtDeviceApis::Commons::UnknownException) {
                LoggerE("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
 }
 
 JSValueRef JSNFCAdapter::setPeerListener (JSContextRef context, JSObjectRef object,
@@ -263,7 +261,7 @@ JSValueRef JSNFCAdapter::setPeerListener (JSContextRef context, JSObjectRef obje
                NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
                if (!privateObject) {
                        LoggerE("private object is null");
-                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+                       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
                }
 
                INFCAdapterPtr nfcAdapter(privateObject->getObject());
@@ -275,31 +273,31 @@ JSValueRef JSNFCAdapter::setPeerListener (JSContextRef context, JSObjectRef obje
 
                EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
                emitter->setListener(&NFCStaticController::getInstance());
-               emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
+               emitter->setEventPrivateData(DPL::StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
 
                if (nfcAdapter->setPeerListener(emitter) != 0)
                        Throw(WrtDeviceApis::Commons::UnknownException);
 
                NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_PEER_LISTENER)));
-               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
                NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
 
                return JSValueMakeUndefined(context);
     } Catch (BasePlatformException) {
         LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
-        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
+        return JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LoggerE("JSNFCAdapter::setPeerListener : ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch (WrtDeviceApis::Commons::UnknownException) {
                LoggerE("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
 }
 JSValueRef JSNFCAdapter::unsetTagListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
@@ -311,7 +309,7 @@ JSValueRef JSNFCAdapter::unsetTagListener(JSContextRef context, JSObjectRef obje
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
                LoggerE("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
        Try     {
@@ -320,19 +318,19 @@ JSValueRef JSNFCAdapter::unsetTagListener(JSContextRef context, JSObjectRef obje
                nfcAdapter->unsetTagListener();
 
                NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCADAPTER_TAG_LISTENER)));
-               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
                NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
 
                return JSValueMakeUndefined(context);
        } Catch (NullPointerException) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
 }
 
 JSValueRef JSNFCAdapter::unsetPeerListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
@@ -345,7 +343,7 @@ JSValueRef JSNFCAdapter::unsetPeerListener(JSContextRef context, JSObjectRef obj
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
                LoggerE("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
        Try {
@@ -354,19 +352,19 @@ JSValueRef JSNFCAdapter::unsetPeerListener(JSContextRef context, JSObjectRef obj
                nfcAdapter->unsetPeerListener();
 
                NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCADAPTER_PEER_LISTENER)));
-               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
                NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
 
                return JSValueMakeUndefined(context);
        } Catch (NullPointerException) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
 }
 
 JSValueRef JSNFCAdapter::getCachedMessage (JSContextRef context, JSObjectRef object,
@@ -380,7 +378,7 @@ JSValueRef JSNFCAdapter::getCachedMessage (JSContextRef context, JSObjectRef obj
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
                LoggerE("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
        JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
@@ -394,14 +392,14 @@ JSValueRef JSNFCAdapter::getCachedMessage (JSContextRef context, JSObjectRef obj
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch(NullPointerException) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
 }
 
 JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
@@ -417,7 +415,7 @@ JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
                LoggerE("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
        INFCAdapterPtr nfcAdapter(privateObject->getObject());
@@ -438,30 +436,31 @@ JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
                NFCConverter nfcConverter(context);
 
                EventNFCChangedSetPoweredPtr event(new EventNFCChangedSetPowered(state));
-               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setPrivateData( DPL::StaticPointerCast<IEventPrivateData>(callbackManager) );
                event->setForAsynchronousCall(&NFCStaticController::getInstance());
+               callbackManager->setObject(thisObject);
                nfcAdapter->setPowered(event);
                NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
                return JSValueMakeUndefined(context);
     } Catch (BasePlatformException) {
         LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
-        return JSWebAPIException::throwException(context, exception, _rethrown_exception);
+        return JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
                LoggerE("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available"));
                return JSValueMakeUndefined(context);
        } Catch (WrtDeviceApis::Commons::UnknownException) {
                LoggerE("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch(NullPointerException) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
-       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
+       callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR,"Unknown Error"));
        return JSValueMakeUndefined(context);
 }