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 1867589..5805a85
@@ -15,8 +15,6 @@
 // limitations under the License.
 //
 
-#include <dpl/log/log.h>
-
 #include <string>
 #include <CommonsJavaScript/Validator.h>
 #include <Commons/Exception.h>
 #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 <PlatformException.h>
 
 #include "JSNFCManager.h"
 #include "JSNFCAdapter.h"
 #include "NFCFactory.h"
 #include "EventNFCChanged.h"
 #include "plugin_config.h"
+#include <Logger.h>
 
 using namespace std;
-using namespace DPL;
+
 using namespace DeviceAPI::Common;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
 #define TIZEN_NFCADAPTER_ATTRIBUTENAME "NFCAdapter"
 #define TIZEN_NFCADAPTER_POWERED "powered"
-#define TIZEN_NFCADAPTER_SETYPE "seType"
+
 namespace DeviceAPI {
 namespace NFC {
 
@@ -78,7 +80,6 @@ JSStaticValue JSNFCAdapter::m_property[] =
 {
     //NFCAdapterProperties
        {TIZEN_NFCADAPTER_POWERED,  getProperty, NULL, kJSPropertyAttributeReadOnly},
-       {TIZEN_NFCADAPTER_SETYPE,  getProperty, NULL, kJSPropertyAttributeReadOnly},
        { 0, 0, 0, 0 }
 };
 
@@ -89,9 +90,6 @@ JSStaticFunction JSNFCAdapter::m_function[] = {
        {"unsetPeerListener",       JSNFCAdapter::unsetPeerListener, kJSPropertyAttributeNone},
        {"getCachedMessage", JSNFCAdapter::getCachedMessage, kJSPropertyAttributeNone},
        {"setPowered",      JSNFCAdapter::setPowered, kJSPropertyAttributeNone },
-       {"setCardEmulation",      JSNFCAdapter::setCardEmulation, kJSPropertyAttributeNone },
-       {"setCardEmulationChangeListener",      JSNFCAdapter::setCardEmulationChangeListener, kJSPropertyAttributeNone },
-       {"unsetCardEmulationChangeListener",      JSNFCAdapter::unsetCardEmulationChangeListener, kJSPropertyAttributeNone },
        { 0, 0, 0}
 };
 
@@ -99,7 +97,7 @@ JSClassRef JSNFCAdapter::m_jsClassRef = JSClassCreate(JSNFCAdapter::getClassInfo
 
 void JSNFCAdapter::initialize(JSContextRef context, JSObjectRef object)
 {
-       LogDebug("entered. Nothing to do");
+       LoggerD("entered. Nothing to do");
 }
 
 void JSNFCAdapter::finalize(JSObjectRef object)
@@ -111,7 +109,7 @@ void JSNFCAdapter::finalize(JSObjectRef object)
 }
 
 JSObjectRef JSNFCAdapter::createJSObject(JSContextRef context) {
-       LogDebug("entered");
+       LoggerD("entered");
 
        INFCAdapterPtr nfcAdapter(NFCFactory::getInstance().createNFCAdapterObject());
        NFCAdapterPrivObject *priv = new NFCAdapterPrivObject(context, nfcAdapter);
@@ -139,7 +137,7 @@ const JSClassDefinition* JSNFCAdapter::getClassInfo()
 JSValueRef JSNFCAdapter::getProperty(JSContextRef context, JSObjectRef object,
         JSStringRef propertyName, JSValueRef* exception)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
 
        Try     {
                NFCConverter convert(context);
@@ -147,35 +145,24 @@ JSValueRef JSNFCAdapter::getProperty(JSContextRef context, JSObjectRef object,
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NFCADAPTER_POWERED)) {
                        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(object));
                        if (!privateObject) {
-                               LogError("private object is null");
+                               LoggerE("private object is null");
                                ThrowMsg(NullPointerException, "Private object not initialized");
                        }
-                       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
+                       INFCAdapterPtr nfcAdapter(privateObject->getObject());
                        return convert.toJSValueRef(nfcAdapter->getPowerState());
-               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NFCADAPTER_SETYPE)) {
-                       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_FUNCS);
-                       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-                       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(object));
-                       if (!privateObject) {
-                               LogError("private object is null");
-                               ThrowMsg(NullPointerException, "Private object not initialized");
-                       }
-                       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
-                       return convert.toJSValueRefSEType(nfcAdapter->getSEType());
                }
        } Catch (NullPointerException) {
-               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+               LoggerE("NullPointerException: " << _rethrown_exception.GetMessage());
        } Catch (ConversionException) {
-               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (UnsupportedException) {
-               LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
-       } Catch (UnknownException) {
-               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+               LoggerE("UnsupportedException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
+               LoggerE("UnknownExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
-               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+               LoggerE("PlatformExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+               LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
 
     return JSValueMakeUndefined(context);
@@ -184,137 +171,99 @@ JSValueRef JSNFCAdapter::getProperty(JSContextRef context, JSObjectRef object,
 JSValueRef JSNFCAdapter::setTagListener (JSContextRef context, JSObjectRef object,
                JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
                JSValueRef* exception) {
-       LogDebug("JSNFCAdapter::setTagListener Enter");
+       LoggerD("JSNFCAdapter::setTagListener Enter");
 
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_TAG_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       NFCConverter nfcConverter(context);
-       Validator validator(context, exception);
-
-       if (argumentCount == 0) {
-               LogError("JSNFCAdapter::setTagListener TypeMismatchException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) ) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("JSNFCAdapter::setTagListener TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       NFCChangedCallback callbacks;
-
-       if (JSValueIsObject(context, arguments[0]) &&
-            !validator.isCallback(arguments[0])) {
-            callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
-       } else {
-               LogError("DetectedCB must has onattach and ondetach");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSContextRef global_context = privateObject->getContext();
-
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
-       JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
-    
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
        Try {
-               INFCAdapterPtr nfcAdapter(privateObject->getObject());
-
-               //process the filter object
-               TagFilterPtr tagFilter;
-               if ((argumentCount > 1) &&  !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
-                       if (JSIsArrayValue(context, arguments[1])) {
-                                       tagFilter = nfcConverter.toNFCTagFilter(arguments[1]);
-
-                       } else
-                               Throw(ConversionException);
+               ArgumentValidator validator(context, argumentCount, arguments);
+               NFCChangedCallback callbacks;
+               NFCConverter nfcConverter(context);
+               if (validator.toObject(0))
+                       callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
+
+               std::vector<std::string> filterValue = validator.toStringVector(1, true);
+       
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
+               JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
+               TagFilterPtr tagFilter(new TagFilter());
+               for (unsigned int i=0; i<filterValue.size(); i++) {
+                       nfcTagType filter = nfcConverter.toNfcTagType(filterValue.at(i));
+
+                       tagFilter->addTagTypeValue(filter);
+                       LoggerD("tag_types.at(i): " << filterValue.at(i));
                }
-               else
-               {
-                       TagFilterPtr _filter (new TagFilter());
-                       tagFilter = _filter;
+
+               NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LoggerE("private object is null");
+                       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
                }
 
+               INFCAdapterPtr nfcAdapter(privateObject->getObject());
+
                EventNFCChangedPrivateDataPtr privateData(
                    new EventNFCChangedPrivateData(callbackManager,
                                                    detachedCallbackManager)
                    );
                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(UnknownException);
+                       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 JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
-               LogError("JSNFCAdapter::setTagListener : ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("JSNFCAdapter::setTagListener : ConversionException");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
     } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
-               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
+               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) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+               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,
                JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
                JSValueRef* exception) {
-       LogDebug("JSNFCAdapter::setPeerListener Enter");
+       LoggerD("JSNFCAdapter::setPeerListener Enter");
 
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       NFCConverter nfcConverter(context);
-       Validator validator(context, exception);
-
-
-       if (argumentCount == 0) {
-               LogError("JSNFCAdapter::setPeerListener TypeMismatchException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) ) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("JSNFCAdapter::setPeerListener TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       NFCChangedCallback callbacks;
-
-       if (JSValueIsObject(context, arguments[0]) &&
-            !validator.isCallback(arguments[0])) {
-            callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
-       } else {
-               LogError("DetectedCB must has onattach and ondetach");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
-       JSContextRef global_context = privateObject->getContext();
+       Try {
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
-       JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
+               NFCConverter nfcConverter(context);
+               NFCChangedCallback callbacks;
+
+               if (validator.toObject(0))
+                       callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
+       
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
+               JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
+
+               NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LoggerE("private object is null");
+                       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               }
 
-       Try {
                INFCAdapterPtr nfcAdapter(privateObject->getObject());
 
                EventNFCChangedPrivateDataPtr privateData(
@@ -324,74 +273,77 @@ 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(UnknownException);
+                       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 JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
-               LogError("JSNFCAdapter::setPeerListener : ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("JSNFCAdapter::setPeerListener : ConversionException");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
-               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
+               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) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+               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) {
-       LogDebug("JSNFCAdapter::unsetNFCTagListener Enter");
+       LoggerD("JSNFCAdapter::unsetNFCTagListener Enter");
 
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_TAG_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("private object is null");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
        Try     {
-               INFCAdapterPtr nfcAdapter( privateObject->getObject() );
+               INFCAdapterPtr nfcAdapter(privateObject->getObject());
 
                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) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+               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,
                size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
-       LogDebug("JSNFCAdapter::unsetPeerListener Enter");
+       LoggerD("JSNFCAdapter::unsetPeerListener Enter");
 
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("private object is null");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
        Try {
@@ -400,297 +352,118 @@ 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) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+               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,
                JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
                JSValueRef* exception) {
-       LogDebug("JSNFCAdapter::getCachedMessage Enter");
+       LoggerD("JSNFCAdapter::getCachedMessage Enter");
 
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_COMMON_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("private object is null");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
        Try {
                INFCAdapterPtr nfcAdapter(privateObject->getObject());
                void *cachedMessage = nfcAdapter->getCachedMessage();
                if (cachedMessage != NULL)
-                       return JSNdefMessage::createJSObject(context, nfcAdapter->getCachedMessage());
+                       return JSNdefMessage::createJSObject(global_context, cachedMessage);
                return JSValueMakeNull(context);
-       } Catch (UnknownException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
+               LoggerE("Exception: " << _rethrown_exception.GetMessage());
        } Catch (PlatformException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               LoggerE("Exception: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch(NullPointerException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("Exception: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+               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,
                JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
                JSValueRef* exception) {
-       LogDebug("Enter");
+       LoggerD("Enter");
 
        AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_ADMIN_FUNCS);
        TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       Validator validator(context, exception);
-    if(argumentCount == 0) {
-        /* 1st argument is mandatory. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-    }
-       if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]) && !validator.isCallback(arguments[1])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2]) && !validator.isCallback(arguments[2])) {
-               /* 2nd argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if ((argumentCount > 1) && validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
        NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
        if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("private object is null");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        }
 
-       JSContextRef global_context = privateObject->getContext();
-
-       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
+       INFCAdapterPtr nfcAdapter(privateObject->getObject());
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, NULL, NULL, true, true);
 
        Try {
-               NFCConverter nfcConverter(context);
-               bool state = false;
-               state = nfcConverter.toBool(arguments[0]);
-
-               EventNFCChangedSetPoweredPtr event(new EventNFCChangedSetPowered(state));
-               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
-               event->setForAsynchronousCall(&NFCStaticController::getInstance());
-               nfcAdapter->setPowered(event);
-               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
-               return JSValueMakeUndefined(context);
-       } Catch (ConversionException) {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
-               return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
-               LogError("UnknownException: " << _rethrown_exception.GetMessage());
-       } Catch(NullPointerException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       }
-       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
-       return JSValueMakeUndefined(context);
-}
-
-JSValueRef JSNFCAdapter::setCardEmulation (JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) {
-       LogDebug("Enter");
-
-       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_FUNCS);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               ArgumentValidator validator(context, argumentCount, arguments);
 
-       Validator validator(context, exception);
-       if(argumentCount == 0) {
-           /* 1st argument is mandatory. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]) && !validator.isCallback(arguments[1])) {
-               /* And 2st argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-       if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2]) && !validator.isCallback(arguments[2])) {
-               /* 3nd argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-       if ((argumentCount > 1) && validator.isCallback(arguments[1])) {
-               onSuccessForCbm = arguments[1];
-       }
-       if ((argumentCount > 2) && validator.isCallback(arguments[2])) {
-               onErrorForCbm = arguments[2];
-       }
+               // state
+        bool state = validator.toBool(0);
+               // successCallback
+               if (validator.toFunction(1, true))
+                       callbackManager->setOnSuccess(arguments[1]);
+               // errorCallback
+               if (validator.toFunction(2, true))
+                       callbackManager->setOnError(arguments[2]);
 
-       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSContextRef global_context = privateObject->getContext();
-
-       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
-
-       Try {
                NFCConverter nfcConverter(context);
-               EventNFCSEType seType = NFC_SE_INVALID;
-               seType = nfcConverter.toSEType(arguments[0]);
 
-               EventNFCSetCardEmulationPtr event(new EventNFCSetCardEmulation(seType));
-               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               EventNFCChangedSetPoweredPtr event(new EventNFCChangedSetPowered(state));
+               event->setPrivateData( DPL::StaticPointerCast<IEventPrivateData>(callbackManager) );
                event->setForAsynchronousCall(&NFCStaticController::getInstance());
-               nfcAdapter->setCardEmulation(event);
+               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 JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
        } Catch (ConversionException) {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("ConversionException");
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
+               callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available"));
                return JSValueMakeUndefined(context);
-       } Catch (UnknownException) {
-               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
+               LoggerE("UnknownException: " << _rethrown_exception.GetMessage());
        } Catch(NullPointerException) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               LoggerE("Exception: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
+               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);
 }
 
-JSValueRef JSNFCAdapter::setCardEmulationChangeListener (JSContextRef context, JSObjectRef object,
-               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
-               JSValueRef* exception) {
-       LogDebug("Entered ");
-
-       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_FUNCS);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       Validator validator(context, exception);
-
-       if ((argumentCount < 1) || JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !validator.isCallback(arguments[0])) {
-               /* 1st argument is mandatory. And 1st argument must be Callback. */
-               LogError("TypeMismatchException!");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSValueRef onSuccessForCbm = NULL;
-       if (validator.isCallback(arguments[0])) {
-               onSuccessForCbm = arguments[0];
-       }
-
-       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       JSContextRef global_context = privateObject->getContext();
-
-       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, NULL, true, true);
-
-       Try {
-               EventNFCChangedCardEmulationEmitterPtr emitter(new EventNFCChangedCardEmulationEmitter);
-               emitter->setListener(&NFCStaticController::getInstance());
-               emitter->setEventPrivateData(StaticPointerCast<EventNFCChangedCardEmulation::PrivateDataType>(callbackManager));
-               nfcAdapter->setCardEmulationChangeListener(emitter);
-
-               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_CARDEMULATION_LISTENER)));
-               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
-               NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
-
-               return JSValueMakeUndefined(context);
-       } Catch (ConversionException) {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (UnknownException) {
-               LogError("UnknownException: " << _rethrown_exception.GetMessage());
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       }
-
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
-JSValueRef JSNFCAdapter::unsetCardEmulationChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
-               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
-       LogDebug("JSNFCAdapter::unsetPeerListener Enter");
-
-       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_FUNCS);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               LogError("private object is null");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
-
-       Try {
-               INFCAdapterPtr nfcAdapter(privateObject->getObject());
-               nfcAdapter->unsetCardEmulationChangeListener();
-
-               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  ID_NFCADAPTER_CARDEMULATION_LISTENER));
-               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
-               NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
-
-               return JSValueMakeUndefined(context);
-       } Catch (ConversionException) {
-               LogError("ConversionException");
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (NullPointerException) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (PlatformException) {
-               LogError("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LogError("Exception: " << _rethrown_exception.GetMessage());
-       }
-       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
-}
-
 
 }
 }