Update change log and spec for wrt-plugins-tizen_0.4.61
authorDongjin Choi <milkelf.choi@samsung.com>
Tue, 20 Aug 2013 05:50:07 +0000 (14:50 +0900)
committerDongjin Choi <milkelf.choi@samsung.com>
Tue, 20 Aug 2013 06:53:53 +0000 (15:53 +0900)
[model] REDWOOD
[binary_type] PDA
[customer] OPEN

[Issue] N/A
[Problem] Intensive TC fail
[Cause] When constructing NDEFMessage ,NDEFRecord, NDEFRecordText, NDEFRecordURI or NDEFRecordMedia, it checks if arguments are valid or not. And if they are not valid, it sends an exception.
[Solution] It will not send exception in the cases. It will use default values instead of invalid arguments when setting attributes or constructing them with invalid ones or send exceptions when calling APIs that use them.

[Issue#] Docomo QA 3
[Problem] Even if User-Agent changed, it is not applied to download API
[Cause] Download API requires Header setting
[Solution] Set User-Agent to download API

[Issue] N/A
[Problem] TCT Fail
[Cause] It doesn't raise exception if the type of listener's argument is undefined. And if it doesn't have any valid argument, it raises exception.
[Solution] It will check arguments's types using ArgumentValidator.

[Issue] N/A
[Problem] can assign null value to title.
[Cause] don't use StaticValue.
[Solution] using StaticValue.

[Issue#] N/A
[Problem] getAppContext fails not on independent WebApp
[Cause] This function have got appID from platform API
[Solution] API must get appID from WRT

[Issue#] P130815-05559
[Problem] "undefined" value is returned when rrule is set to null.
[Cause] No clear spec description.
[Solution] Return null when rrule is set to null.

[team] WebAPI
[request] N/A
[horizontal_expansion] N/A

UnitTC passed.

53 files changed:
CMakeLists.txt
packaging/wrt-plugins-tizen.spec
src/Application/ApplicationManager.cpp
src/Calendar/JSCalendarEvent.cpp
src/Calendar/JSCalendarRecurrenceRule.cpp
src/Download/DownloadManager.cpp
src/Download/DownloadManager.h
src/Download/JSDownloadManager.cpp
src/NFC/CMakeLists.txt
src/NFC/EventTagAction.h
src/NFC/EventTargetAction.h
src/NFC/INdefMessage.h
src/NFC/INdefRecord.h
src/NFC/JSNFCTag.cpp
src/NFC/JSNFCTarget.cpp
src/NFC/JSNdefMessage.cpp [changed mode: 0644->0755]
src/NFC/JSNdefMessage.h
src/NFC/JSNdefRecord.cpp [changed mode: 0644->0755]
src/NFC/JSNdefRecord.h
src/NFC/JSNdefRecordMedia.cpp [changed mode: 0644->0755]
src/NFC/JSNdefRecordMedia.h
src/NFC/JSNdefRecordText.cpp [changed mode: 0644->0755]
src/NFC/JSNdefRecordText.h
src/NFC/JSNdefRecordURI.cpp [changed mode: 0644->0755]
src/NFC/JSNdefRecordURI.h
src/NFC/NFCAdapter.cpp [changed mode: 0644->0755]
src/NFC/NFCConverter.cpp [changed mode: 0644->0755]
src/NFC/NFCConverter.h
src/NFC/NFCFactory.cpp
src/NFC/NFCFactory.h
src/NFC/NFCStaticController.cpp [changed mode: 0644->0755]
src/NFC/NFCTag.cpp [changed mode: 0644->0755]
src/NFC/NFCTarget.cpp [changed mode: 0644->0755]
src/NFC/NFCUtil.cpp [changed mode: 0644->0755]
src/NFC/NFCUtil.h
src/NFC/NdefMessage.cpp
src/NFC/NdefMessage.h
src/NFC/NdefRecord.cpp
src/NFC/NdefRecord.h
src/NFC/NdefRecordMedia.cpp [new file with mode: 0755]
src/NFC/NdefRecordMedia.h [new file with mode: 0755]
src/NFC/NdefRecordProperties.h
src/NFC/NdefRecordText.cpp [new file with mode: 0755]
src/NFC/NdefRecordText.h [new file with mode: 0755]
src/NFC/NdefRecordURI.cpp [new file with mode: 0755]
src/NFC/NdefRecordURI.h [new file with mode: 0755]
src/NFC/ResponseDispatcher.cpp [changed mode: 0644->0755]
src/NetworkBearerSelection/NetworkBearerSelection.cpp
src/Notification/JSStatusNotification.cpp
src/SecureElement/JSSEService.cpp
src/SecureElement/SEConverter.cpp
src/SecureElement/SEConverter.h
src/Systeminfo/Systeminfo.cpp

index 38b193c..2eef951 100755 (executable)
@@ -95,12 +95,13 @@ ENDIF(ENABLE_OPTIONAL_SE)
 # -----------------------------------------------------------------------------
 # CFlags
 # -----------------------------------------------------------------------------
+SET(OPTIMIZATION_FLAGS         "-falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks -ftree-vect-loop-version")
 SET(CMAKE_C_FLAGS_PROFILING    "-O0 -g -pg")
 SET(CMAKE_CXX_FLAGS_PROFILING  "-O0 -std=c++0x -g -pg")
 SET(CMAKE_C_FLAGS_DEBUG        "-O0 -g")
 SET(CMAKE_CXX_FLAGS_DEBUG      "-O0 -std=c++0x -g")
-SET(CMAKE_C_FLAGS_RELEASE      "-O2 -g")
-SET(CMAKE_CXX_FLAGS_RELEASE    "-O2 -std=c++0x -g")
+SET(CMAKE_C_FLAGS_RELEASE      "-Os -g ${OPTIMIZATION_FLAGS}")
+SET(CMAKE_CXX_FLAGS_RELEASE    "-Os -std=c++0x -g ${OPTIMIZATION_FLAGS}")
 ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")
 ADD_DEFINITIONS("-DEXPORT_API=")
 ADD_DEFINITIONS("-Wall")
index cdec69c..e928e2f 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       wrt-plugins-tizen
 Summary:    JavaScript plugins for WebRuntime
-Version:    0.4.60
+Version:    0.4.61
 Release:    0
 Group:      Development/Libraries
 License:    Apache License, Version 2.0
@@ -90,6 +90,12 @@ Wrt-plugin-tizen development headers
 
 export LDFLAGS+="-Wl,--rpath=%{PREFIX} -Wl,--as-needed"
 
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+%endif
+
 cmake \
 -DENABLE_OPTIONAL_BT=YES \
 -DENABLE_OPTIONAL_CALL_HISTORY=YES \
index d9a3b06..f13f930 100644 (file)
@@ -696,56 +696,73 @@ ApplicationContextPtr ApplicationManager::getAppContext(const std::string id)
        int ret = 0;
 
        std::string contextId = id;
-       int pid;
+       std::string appId;
 
-       if (contextId.empty())
-       {
-               //pid = getpid();
-               pid = getppid();
+       int selfpid = getppid();
 
+       if(contextId.empty())
+       {
                std::stringstream sstr;
-               sstr << pid;
+               sstr << selfpid;
                contextId = sstr.str();
+
+               appId = get_current_app_id();
        }
        else
        {
+               int pid = 0;
                std::stringstream(contextId) >> pid;
                if (pid <= 0)
                {
                        LoggerE("Given contextId is wrong");
                        ThrowMsg(NotFoundException, "Given contextId is wrong");
                }
-       }
 
-       char *app_id = NULL;
-
-       TIME_TRACER_ITEM_BEGIN("(getAppContext)app_manager_get_app_id", 0);
-       ret = app_manager_get_app_id(pid, &app_id);
-       TIME_TRACER_ITEM_END("(getAppContext)app_manager_get_app_id", 0);
-       if(ret != APP_MANAGER_ERROR_NONE)
-       {
-               if(app_id)
-                       free(app_id);
+               if(pid == selfpid)
+               {
+                       std::stringstream sstr;
+                       sstr << selfpid;
+                       contextId = sstr.str();
 
-               switch(ret)
+                       appId = get_current_app_id();
+               }
+               else
                {
-               case APP_MANAGER_ERROR_NO_SUCH_APP:
-               case APP_MANAGER_ERROR_INVALID_PARAMETER:
-                       LoggerE("app_manager_get_app_id error : no such app");
-                       ThrowMsg(NotFoundException, "app_manager_get_app_id error : no such app");
-               default:
-                       LoggerE("app_manager_get_app_id error (" << ret << ")");
-                       ThrowMsg(UnknownException, "app_manager_get_app_id error : unknown error");
+                       char *app_id = NULL;
+
+                       TIME_TRACER_ITEM_BEGIN("(getAppContext)app_manager_get_app_id", 0);
+                       ret = app_manager_get_app_id(pid, &app_id);
+                       TIME_TRACER_ITEM_END("(getAppContext)app_manager_get_app_id", 0);
+                       if(ret != APP_MANAGER_ERROR_NONE)
+                       {
+                               if(app_id)
+                                       free(app_id);
+
+                               switch(ret)
+                               {
+                               case APP_MANAGER_ERROR_NO_SUCH_APP:
+                               case APP_MANAGER_ERROR_INVALID_PARAMETER:
+                                       LoggerE("app_manager_get_app_id error : no such app");
+                                       ThrowMsg(NotFoundException, "app_manager_get_app_id error : no such app");
+                                       break;
+                               default:
+                                       LoggerE("app_manager_get_app_id error (" << ret << ")");
+                                       ThrowMsg(UnknownException, "app_manager_get_app_id error : unknown error");
+                                       break;
+                               }
+                       }
+
+                       appId = app_id;
+
+                       if(app_id)
+                               free(app_id);
                }
        }
 
        ApplicationContextPtr appContext(new ApplicationContext());
-       appContext->setAppId(app_id);
+       appContext->setAppId(appId);
        appContext->setContextId(contextId);
 
-       if(app_id)
-               free(app_id);   
-
        return appContext;
 }
 
index c5691b8..0969560 100755 (executable)
@@ -471,9 +471,10 @@ JSValueRef JSCalendarEvent::getPropertyRecurrenceRule(JSContextRef context,
         }
 
                if (NULL==rrule) {
+                       LogInfo("Null rrule.");
                        return JSValueMakeNull(context);
                } else if (EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
-            return JSValueMakeUndefined(context);
+            return JSValueMakeNull(context);
         } else {
             return JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(priv->getContext(), rrule);
         }
@@ -501,8 +502,7 @@ bool JSCalendarEvent::setPropertyRecurrenceRule(JSContextRef context,
         }
 
                if (JSValueIsNull(context, value)) {
-                       EventRecurrenceRulePtr rrule( new EventRecurrenceRule() );
-                       event->setRecurrenceRule(rrule);
+                       event->getRecurrenceRule()->setFrequency(EventRecurrenceRule::NO_RECURRENCE);
         } else if (!JSValueIsObjectOfClass(context, value, JSCalendarRecurrenceRule::getClassRef())) {
             ThrowMsg(ConversionException, "Wrong parameter type.");
                } else {
index 592691c..61e5a48 100755 (executable)
@@ -310,7 +310,7 @@ bool JSCalendarRecurrenceRule::setProperty(JSContextRef context,
             rrule->setFrequency(converter.toRecurrenceFrequency(frequency));
             return true;
         } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_INTERVAL)) {
-            unsigned short interval = (unsigned short)(converter.toULong(value));
+            unsigned short interval = (unsigned short)(converter.toLong(value));
             rrule->setInterval(interval);
             return true;
         } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_UNTIL_DATE)) {
index 414b2ee..376dfda 100644 (file)
@@ -317,7 +317,7 @@ void DownloadManager::removeCallbackFromMap(long downloadId) {
        }
 }
 
-long DownloadManager::start(DownloadRequest *request, DownloadCallback *downloadCallback)
+long DownloadManager::start(DownloadRequest *request, DownloadCallback *downloadCallback, std::string& userAgent)
 {
        int ret;
        int downloadId = 0;
@@ -332,6 +332,14 @@ long DownloadManager::start(DownloadRequest *request, DownloadCallback *download
        std::string networkType = request->getNetworkType();
        std::map<std::string, std::string> httpHeader = request->getHttpHeader();
 
+       std::map<std::string, std::string> webAppHttpHeader = getWebAppHttpHeader();
+
+       // initialize webAppHttpHeader
+       if (!userAgent.empty()) {
+               std::pair<std::string, std::string> userAgentPair("User-Agent", userAgent);
+               webAppHttpHeader.insert(userAgentPair);
+       }
+
        if (url.empty()) {
                throw InvalidValuesException("Invalid DownloadRequest.url.");
        }
@@ -389,6 +397,15 @@ long DownloadManager::start(DownloadRequest *request, DownloadCallback *download
                }
        }
 
+       // set httpHeaders with wrt's HTTPHeaders.
+       // Values given by user prior to the wrt's.
+       for(std::map<std::string, std::string>::const_iterator iter = webAppHttpHeader.begin(); iter != webAppHttpHeader.end(); ++iter) {
+               if(httpHeader.find(iter->first) == httpHeader.end()) {
+                       std::pair<std::string, std::string> headerPair(iter->first, iter->second);
+                       httpHeader.insert(headerPair);
+               }
+       }
+
        // set httpHeaders
        std::map<std::string, std::string>::const_iterator iter;
        for (iter = httpHeader.begin(); iter != httpHeader.end(); ++iter) {
@@ -683,5 +700,14 @@ void DownloadManager::setListener(long downloadId, DownloadCallback *downloadCal
        setCallbackToMap(downloadId, downloadCallback);
 }
 
+std::map<std::string, std::string> DownloadManager::getWebAppHttpHeader()
+{
+       std::map<std::string, std::string> webAppHttpHeader;
+
+       // TODO get HTTPHeaders from WRT
+
+       return webAppHttpHeader;
+}
+
 } // Download
 } // DeviceAPI
index 5fd77d3..6df2774 100644 (file)
@@ -33,7 +33,7 @@ public:
        DownloadManager();
        virtual ~DownloadManager();
 
-       long start(DownloadRequest *request, DownloadCallback *downloadCallback);
+       long start(DownloadRequest *request, DownloadCallback *downloadCallback, std::string& userAgent);
        void cancel(long downloadId);
        void pause(long downloadId);
        void resume(long downloadId);
@@ -50,6 +50,8 @@ public:
 private:
        typedef std::map<long, DownloadCallback*> DownloadCallbackMapT;
        DownloadCallbackMapT mDownloadCallbacks;
+
+       std::map<std::string, std::string> getWebAppHttpHeader();
 };
 
 }
index 85fba3e..c1e8022 100644 (file)
@@ -20,6 +20,7 @@
 #include <JSUtil.h>
 #include <ArgumentValidator.h>
 #include <GlobalContextManager.h>
+#include <JSStringRefWrapper.h>
 
 #include "plugin_config.h"
 
@@ -38,6 +39,49 @@ using namespace DeviceAPI::Common;
 namespace DeviceAPI {
 namespace Download {
 
+namespace {
+       std::string getUserAgent(JSContextRef context)
+       {
+               std::string userAgent;
+
+               JSValueRef jsException = NULL;
+               JSObjectRef jsObjWindow = JSContextGetGlobalObject(context);
+               JSStringRefWrapper jsStrWrpNavigator("navigator");
+               JSValueRef jsValNavigator = JSObjectGetProperty(context, jsObjWindow, jsStrWrpNavigator.get(), &jsException);
+               if(jsException != NULL) {
+                       LoggerW("Fail to get userAgent while getting navigator value.");
+                       return userAgent;
+               }
+
+               JSObjectRef jsObjNavigator = JSValueToObject(context, jsValNavigator, &jsException);
+               if(jsException != NULL) {
+                       LoggerW("Fail to get userAgent while getting navigator object.");
+                       return userAgent;
+               }
+
+               JSStringRefWrapper jsStrWrtUserAgent("userAgent");
+               JSValueRef jsValUserAgent = JSObjectGetProperty(context, jsObjNavigator, jsStrWrtUserAgent.get(), &jsException);
+               if(jsException != NULL) {
+                       LoggerW("Fail to get userAgent while getting userAgent value.");
+                       return userAgent;
+               }
+
+               JSStringRef jsStrUserAgent = JSValueToStringCopy(context, jsValUserAgent, &jsException);
+               if(jsException != NULL) {
+                       LoggerW("Fail to get userAgent while getting userAgent string.");
+                       return userAgent;
+               }
+
+               size_t size = JSStringGetLength(jsStrUserAgent);
+               char cstrUserAgent[size*3];
+               JSStringGetUTF8CString(jsStrUserAgent, cstrUserAgent, size*3);
+
+               userAgent = cstrUserAgent;
+
+               return userAgent;
+       }
+}
+
 JSClassDefinition JSDownloadManager::m_classInfo = {
     0,
     kJSClassAttributeNone,
@@ -143,8 +187,10 @@ JSValueRef JSDownloadManager::startDownload(JSContextRef context,
             downloadCallback = new DownloadCallback(GlobalContextManager::getInstance()->getGlobalContext(context), downloadCallbackObj);
         }
 
-        // perform
-        long downloadId = downloadManager->start(downloadRequest, downloadCallback);
+        // getting userAgent from navigator.userAgent (to be replaced by other method)
+        std::string userAgent = getUserAgent(context);
+
+        long downloadId = downloadManager->start(downloadRequest, downloadCallback, userAgent);
                TIME_TRACER_ITEM_END(__FUNCTION__, 0);
         return JSUtil::toJSValueRef(context, downloadId);
     } catch (const BasePlatformException &err) {
index eea7f19..64c3a72 100755 (executable)
@@ -41,6 +41,9 @@ SET(SRCS_IMPL
        NFCTag.cpp
        NdefMessage.cpp
        NdefRecord.cpp
+       NdefRecordText.cpp
+       NdefRecordURI.cpp
+       NdefRecordMedia.cpp
        NFCTarget.cpp
        NFCUtil.cpp
 )
index 97295e5..bab0153 100755 (executable)
@@ -22,6 +22,7 @@
 #include <vector>
 #include "EventNFC.h"
 #include <dpl/shared_ptr.h>
+#include <nfc.h>
 
 namespace DeviceAPI {
 namespace NFC {
@@ -34,7 +35,7 @@ protected:
        void setNdefMessageHandle(void *handle) { messageHandle = handle; }
        void *getNdefMessageHandle()  { return messageHandle; }
 public:
-       EventTagAction() { }
+       EventTagAction() : messageHandle(NULL) { }
 };
 
 class EventTagActionRead : public EventNFCTemplate<EventTagActionRead>
@@ -51,6 +52,10 @@ private:
 class EventTagActionWrite : public EventTagAction<EventTagActionWrite>
 {
 public:
+       ~EventTagActionWrite() {
+               if (messageHandle)
+                       nfc_ndef_message_destroy((nfc_ndef_message_h)messageHandle);
+       }
        void writeNdef(void *handle) {setNdefMessageHandle(handle);}
        void *getNdefForWriting()  {return getNdefMessageHandle();}
        EventTagActionWrite(){ }
index b5d0b34..38dfed5 100755 (executable)
@@ -24,6 +24,7 @@
 #include <Commons/ListenerEvent.h>
 #include <Commons/ListenerEventEmitter.h>
 #include "EventNFC.h"
+#include <nfc.h>
 
 namespace DeviceAPI {
 namespace NFC {
@@ -43,6 +44,10 @@ private:
 class EventTargetActionSend : public EventNFCTemplate<EventTargetActionSend>
 {
 public:
+       ~EventTargetActionSend() {
+               if (message)
+                       nfc_ndef_message_destroy((nfc_ndef_message_h)message);
+       }
        void *getMessageForSending()  {return message;}
        EventTargetActionSend(void *handle) :message(handle){ }
 private:
index 1563c25..e607e01 100755 (executable)
@@ -22,6 +22,7 @@
 
 #include <dpl/shared_ptr.h>
 #include <vector>
+#include <PropertyBag.h>
 #include "NdefRecordProperties.h"
 
 namespace DeviceAPI {
@@ -33,13 +34,12 @@ class INdefMessage
 
                                       INdefMessage() {}
         virtual                     ~INdefMessage() {}
-       virtual std::vector<unsigned char> toByte()= 0;
-       virtual long getRecordCount() = 0;
-       virtual NdefRecordData getNDEFRecord(const long index) = 0;
-       virtual void *makeMessage(std::vector<void *> &ndefRcords) = 0;
-       virtual void *makeMessage(const std::vector<unsigned char> &rawdata) = 0;
-       virtual void setRecordesPtr(void *records) = 0;
-       virtual void* getRecordesPtr() = 0;
+       virtual std::vector<unsigned char> toByte(std::vector<void *> &ndefRcords)= 0;
+       virtual void *makeNdefMessageHandle(std::vector<void *> &ndefRcords) = 0;
+       virtual std::vector<NdefRecordData> toNDEFRecords(const std::vector<unsigned char> &rawdata) = 0;
+       virtual std::vector<NdefRecordData> toNDEFRecords(void *message) = 0;
+
+       Common::PropertyBag mLocalProperty;
 };
 
 typedef DPL::SharedPtr<INdefMessage> INdefMessagePtr;
index 5d93e39..4c93269 100755 (executable)
 #ifndef _ABSTRACT_LAYER_INDEFRECORD_H_
 #define _ABSTRACT_LAYER_INDEFRECORD_H_
 
-#include <vector>
 #include <dpl/shared_ptr.h>
+#include <Commons/Exception.h>
 #include "NdefRecordProperties.h"
 
 
 namespace DeviceAPI {
 namespace NFC {
+using namespace WrtDeviceApis::Commons;
 
 class INdefRecord
 {
     public:
                                       INdefRecord() {}
        virtual                     ~INdefRecord() {}
-       virtual void *getHandle() = 0;
-       virtual NdefRecordProperties getNDEFRecordProperties() = 0;
-       virtual nfcTNF getTNF() = 0;
-       virtual std::vector<unsigned char> getTypeName() = 0;
-       virtual std::vector<unsigned char> getID() = 0;
-       virtual std::vector<unsigned char> getPayload() = 0;
-       virtual bool getText(char **text) = 0;
-       virtual bool getLangCode(char **langCode) = 0;
-       virtual bool getEncodeType(nfcTextEncodeUTF *encodeType) = 0;
-       virtual bool getUri(char **uri) = 0;
-       virtual bool getMimeType(char **mimeType) = 0;
-    protected:
+          virtual NdefRecordData getNDEFRecordData() = 0;
+          virtual void *getHandle() = 0;
+          virtual std::string getText() {ThrowMsg(NotFoundException, "Not Found text attribute");}
+          virtual std::string getLanguageCode() {ThrowMsg(NotFoundException, "Not Found languageCode attribute");}
+          virtual nfcTextEncodeUTF getEncoding() {ThrowMsg(NotFoundException, "Not Found encoding attribute");}
+          virtual std::string getUri( ) {ThrowMsg(NotFoundException, "Not Found uri attribute");}
+          virtual std::string getMimeType() {ThrowMsg(NotFoundException, "Not Found mimeType attribute");}
 
 };
 
index c96c8e4..62dc324 100755 (executable)
@@ -292,8 +292,26 @@ JSValueRef JSNFCTag::writeNDEF(JSContextRef context,
                        callbackManager->setOnError(arguments[2]);
 
                EventTagActionWritePtr event(new EventTagActionWrite());
-               NFCConverter convert(context);
-               void *messageHandle = convert.copiedMessage(ndefMessageObj);
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
+               NFCConverter convert(global_context);
+               void *messageHandle = NULL;
+               try {
+                       NdefMessagePrivObject* ndefMessagePrivateObj = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(ndefMessageObj));
+                       if (!ndefMessagePrivateObj) {
+                               LogError("NDEF Message Private object is not set.");
+                               ThrowMsg(ConversionException, "Private object is not set");
+                       }
+                       INdefMessagePtr ndefMessage(ndefMessagePrivateObj->getObject());
+                       JSValueRef recordsValue = (ndefMessage->mLocalProperty).getProperty(global_context, TIZEN_NDEFMESSAGE_RECORDS);
+                       std::vector<void *> records = convert.toVectorOfRecordHandles(recordsValue);
+                       messageHandle = ndefMessage->makeNdefMessageHandle(records);
+               } catch (WrtDeviceApis::Commons::Exception& err) {
+                       LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+                       ThrowMsg(InvalidArgumentException, "Invalid NDEF Message");
+               }
+               if (messageHandle == NULL)
+                       ThrowMsg(InvalidArgumentException, "Invalid NDEF Message");
+       
                event->writeNdef(messageHandle);
                event->setPrivateData( DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
                event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
@@ -312,7 +330,7 @@ JSValueRef JSNFCTag::writeNDEF(JSContextRef context,
                return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, "Not Support NDEF");
        } Catch (InvalidArgumentException) {
                LoggerE("writeNDEF InvalidArgumentException");
-               callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Invalid Values"));
+               callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()));
                return JSValueMakeUndefined(context);
        } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
@@ -364,10 +382,10 @@ JSValueRef JSNFCTag::transceive(JSContextRef context,
                        callbackManager->setOnError(arguments[2]);
 
                EventTagActionTransceivePtr event(new EventTagActionTransceive());
-               Converter convert(context);
+               NFCConverter convert(context);
                std::vector<unsigned char> data;
                if (dataObj)
-                       data= convert.toVectorOfUChars(arguments[0]);
+                       data= convert.toVectorOfOctets(arguments[0]);
                event->transceive(data);
                event->setPrivateData( DPL::StaticPointerCast<IEventPrivateData>(callbackManager) );
                event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
index 01ba2a7..c1eaa88 100755 (executable)
@@ -308,7 +308,26 @@ JSValueRef JSNFCTarget::sendNDEF(JSContextRef context,
                if (validator.toFunction(2, true))
                        callbackManager->setOnError(arguments[2]);
 
-               void *messageHandle = convert.copiedMessage(ndefMessageObj);
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
+               NFCConverter convert(global_context);
+               void *messageHandle = NULL;
+               try {
+                       NdefMessagePrivObject* ndefMessagePrivateObj = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(ndefMessageObj));
+                       if (!ndefMessagePrivateObj) {
+                               LogError("NDEF Message Private object is not set.");
+                               ThrowMsg(ConversionException, "Private object is not set");
+                       }
+                       INdefMessagePtr ndefMessage(ndefMessagePrivateObj->getObject());
+                       JSValueRef recordsValue = (ndefMessage->mLocalProperty).getProperty(global_context, TIZEN_NDEFMESSAGE_RECORDS);
+                       std::vector<void *> records = convert.toVectorOfRecordHandles(recordsValue);
+                       messageHandle = ndefMessage->makeNdefMessageHandle(records);
+               } catch (WrtDeviceApis::Commons::Exception& err) {
+                       LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+                       ThrowMsg(InvalidArgumentException, "Invalid NDEF Message");
+               }
+               if (messageHandle == NULL)
+                       ThrowMsg(InvalidArgumentException, "Invalid NDEF Message");
+       
                EventTargetActionSendPtr event(new EventTargetActionSend(messageHandle));
                callbackManager->setObject(thisObject);
                event->setPrivateData( DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
@@ -324,7 +343,7 @@ JSValueRef JSNFCTarget::sendNDEF(JSContextRef context,
                return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (InvalidArgumentException) {
                LoggerE("sendNDEF InvalidArgumentException");
-               callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Invalid Values"));
+               callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR,  _rethrown_exception.GetMessage()));
                return JSValueMakeUndefined(context);
        } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
old mode 100644 (file)
new mode 100755 (executable)
index a5e978e..4553d9e
@@ -38,10 +38,6 @@ using namespace DeviceAPI::Common;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
-#define TIZEN_NDEFMESSAGE_ATTRIBUTENAME "NDEFMessage"
-#define TIZEN_NDEFMESSAGE_RECORDCOUNT "recordCount"
-#define TIZEN_NDEFMESSAGE_RECORDS "records"
-
 namespace DeviceAPI {
 namespace NFC {
 
@@ -57,7 +53,7 @@ namespace NFC {
     finalize,
     NULL, //hasProperty,
     NULL,
-    setProperty, //setProperty,
+    NULL, //setProperty,
     NULL, //DeleteProperty,
     NULL, //GetPropertyNames,
     NULL, //CallAsFunction,
@@ -86,46 +82,57 @@ JSClassRef JSNdefMessage::m_jsClassRef = JSClassCreate(JSNdefMessage::getClassIn
 JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, void *messageHandle) {
        LoggerD("entered");
 
-       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(messageHandle);
-       return createJSObject(context, ndefMessage);
+       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject();
+       std::vector<NdefRecordData> records = ndefMessage->toNDEFRecords(messageHandle);
+       JSValueRef recordArray = NULL;
+       if (records.size() > 0) {
+               JSValueRef valueArray[records.size()];
+               NFCConverter convert(context);
+               for (std::size_t i = 0; i < records.size(); ++i) {
+                       valueArray[i] = convert.toJSValueRef(records[i]);
+               }
+               recordArray = JSCreateArrayObject(context, records.size(), valueArray);
+       } else
+               recordArray = JSCreateArrayObject(context, 0, NULL);
+       return createJSObject(context, ndefMessage, recordArray);
 }
 
-JSObjectRef JSNdefMessage::createJSObject(JSContextRef context) {
+/*
+JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, std::vector<void *> ndefRcords) {
        LoggerD("entered");
 
-       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject();
+       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(ndefRcords);
        return createJSObject(context, ndefMessage);
-}
+}*/
 
-JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, INdefMessagePtr message) {
+JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, std::vector<unsigned char> rawdata) {
        LoggerD("entered");
 
+       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject();
        NFCConverter convert(context);
-       JSValueRef records = convert.toJSNdefRecordArray(message);
-       JSValueProtect(context, records);
-       message->setRecordesPtr((void*)records);
-       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, message);
-
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefMessage object");
-       }
-
-       JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
-       return obj;
+       std::vector<NdefRecordData> records = ndefMessage->toNDEFRecords(rawdata);
+       JSValueRef recordArray = NULL;
+       if (records.size() > 0) {
+               JSValueRef valueArray[records.size()];
+               NFCConverter convert(context);
+               for (std::size_t i = 0; i < records.size(); ++i) {
+                       valueArray[i] = convert.toJSValueRef(records[i]);
+               }
+               recordArray = JSCreateArrayObject(context, records.size(), valueArray);
+       } else
+               recordArray = JSCreateArrayObject(context, 0, NULL);
+       return createJSObject(context, ndefMessage, recordArray);
 }
 
-JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, std::vector<void *> ndefRcords) {
+JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, INdefMessagePtr message, JSValueRef recordArray) {
        LoggerD("entered");
 
-       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(ndefRcords);
-       return createJSObject(context, ndefMessage);
-}
-
-JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, std::vector<unsigned char> rawdata) {
-       LoggerD("entered");
+       if ((message->mLocalProperty).setArrayProperty(context, TIZEN_NDEFMESSAGE_RECORDS, recordArray) == false)
+               LoggerE("Can't set property");
 
-       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject(rawdata);
-       return createJSObject(context, ndefMessage);
+       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, message);
+       JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
+       return obj;
 }
 void JSNdefMessage::initialize(JSContextRef context, JSObjectRef object)
 {
@@ -138,8 +145,6 @@ void JSNdefMessage::finalize(JSObjectRef object)
        NdefMessagePrivObject *priv = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
        if (priv) {
                INdefMessagePtr ndefMessage(priv->getObject());
-               LoggerD("getRecordesPtr:"<<ndefMessage->getRecordesPtr());
-               JSValueUnprotect(priv->getContext(), (JSValueRef)(ndefMessage->getRecordesPtr()));
                JSObjectSetPrivate(object, NULL);
                LoggerD("Deleting NdefMessage object");
                delete priv;
@@ -164,23 +169,29 @@ JSObjectRef JSNdefMessage::constructor(JSContextRef ctx, JSObjectRef constructor
 {
        LoggerD("entered");
 
-       Try {
-               ArgumentValidator validator(ctx, argumentCount, arguments);
-        JSObjectRef objArg = validator.toArrayObject(0, true);
-               JSObjectRef result = NULL;
-               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
-
-               if (objArg == NULL)
-                       result = createJSObject(global_context);
-               else {
-                       NFCConverter convert(ctx);
+       ArgumentValidator validator(ctx, argumentCount, arguments);
+    JSObjectRef objArg = NULL;
+       try {
+               if (argumentCount > 0)
+                       objArg = validator.toArrayObject(0);
+       } catch(...) {
+               LoggerE("First parameter is not an array");
+       }
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
 
-                       if (JSGetArrayLength(ctx, objArg) > 0) {
+       JSObjectRef result = NULL;
+       Try {
+               if (objArg != NULL) {
+                       NFCConverter convert(global_context);
+                       unsigned int arrayLen = JSGetArrayLength(ctx, objArg);
+                       if (arrayLen > 0) {
                                bool isRecordArray = false;
                                bool isByteArray = false;
-                               for (std::size_t i = 0; i < JSGetArrayLength(ctx, objArg); ++i) {
-                                       JSValueRef element = JSGetArrayElement(ctx, objArg, i);
-                                       bool bNdefRecord = convert.isNdefRecord(element);
+                               JSValueRef valueArray[arrayLen];
+                               
+                               for (unsigned int i = 0; i < arrayLen; ++i) {
+                                       valueArray[i] = JSGetArrayElement(ctx, objArg, i);
+                                       bool bNdefRecord = convert.isNdefRecord(valueArray[i]);
                                        LoggerD("isNdefRecord : " << bNdefRecord);
                                        if (bNdefRecord)
                                                isRecordArray = true;
@@ -189,38 +200,32 @@ JSObjectRef JSNdefMessage::constructor(JSContextRef ctx, JSObjectRef constructor
                                        if (isRecordArray && isByteArray)
                                                break;
                                }
-                               if (isRecordArray && isByteArray)
-                                       ThrowMsg(ConversionException, "Parameter's type is not matched");
-                               else if (isRecordArray)
-                                       result = createJSObject(global_context, convert.toVectorOfRecordHandles(objArg));
-                               else
-                                       result = createJSObject(global_context, convert.toVectorOfUChars(arguments[0]));
-                               
-                       } else
-                               result = createJSObject(global_context);
+                               if (!isRecordArray && isByteArray) {
+                                       result = createJSObject(global_context, convert.toVectorOfOctets(arguments[0]));
+                               } else {
+                                       INdefMessagePtr ndefMessage = NFCFactory::getInstance().createNDEFMessageObject();
+                                       JSValueRef recordArray = JSCreateArrayObject(global_context, arrayLen, valueArray);
+                                       result = createJSObject(global_context, ndefMessage, recordArray);
+                               }
+                       }
                }
-               if (result) {
-                       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
-                   JSObjectSetProperty(global_context, result, ctorName, constructor,
-                       kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
-               JSStringRelease(ctorName);
-                       return result;
-               } else
-                       throw TypeMismatchException("Parameter Type Mismatch");
-       } Catch(BasePlatformException){
-               return JSWebAPIErrorFactory::postException(ctx, exception, _rethrown_exception);
-       } Catch(ConversionException) {
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (PlatformException) {
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
-       } Catch (WrtDeviceApis::Commons::UnknownException) {
-               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LoggerE("Exception: " << _rethrown_exception.GetMessage());
+       } Catch(WrtDeviceApis::Commons::Exception) {
+               LoggerE(_rethrown_exception.GetClassName() << ": " << _rethrown_exception.GetMessage());
+       } Catch(BasePlatformException) {
+               LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
        }
-       return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
+
+       if (result == NULL)
+               result = createJSObject(global_context);
+
+       if (result) {
+               JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+           JSObjectSetProperty(global_context, result, ctorName, constructor,
+               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+       JSStringRelease(ctorName);
+       }
+       return result;
+
 }
 
 JSValueRef JSNdefMessage::getProperty(JSContextRef context, JSObjectRef object,
@@ -236,14 +241,37 @@ JSValueRef JSNdefMessage::getProperty(JSContextRef context, JSObjectRef object,
                }
 
                INdefMessagePtr ndefMessage(privateObject->getObject());
-               NFCConverter convert(context);
 
+               NFCConverter convert(context);
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
+               JSValueRef recordsValue = (ndefMessage->mLocalProperty).getProperty(global_context, TIZEN_NDEFMESSAGE_RECORDS);
+       
                LoggerD("propertyName : " << convert.toString(propertyName));
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFMESSAGE_RECORDCOUNT)) {
-                       std::vector<void *> records = convert.toVectorOfRecordHandles(static_cast<JSValueRef>(ndefMessage->getRecordesPtr()));
-                       return convert.toJSValueRefLong(records.size());
+               if (JSValueIsNull(global_context, recordsValue) || JSValueIsUndefined(global_context, recordsValue)) {
+                               ThrowMsg(ConversionException,
+                                        "NdefRecordArray is JS null or JS undefined.");
+                   }
+
+                   if (!JSIsArrayValue(global_context, recordsValue)) {
+                       ThrowMsg(ConversionException, "Argument is not an JS array.");
+                   }
+
+                       JSObjectRef obj = convert.toJSObjectRef(recordsValue);
+                       
+                       if (!obj) {
+                               LoggerE("Object is null");
+                               ThrowMsg(ConversionException, "Object is null");
+                       }
+                       long count = 0;
+                       for (std::size_t i = 0; i < JSGetArrayLength(global_context, obj); ++i) {
+                               JSValueRef element = JSGetArrayElement(global_context, obj, i);
+                               if (convert.isNdefRecord(element))
+                                       count++;
+                       }
+                       return convert.toJSValueRefLong(count);
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFMESSAGE_RECORDS)) {
-                       return static_cast<JSValueRef>(ndefMessage->getRecordesPtr());
+                       return recordsValue;
                }
        } Catch (ConversionException) {
                LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
@@ -274,17 +302,27 @@ bool JSNdefMessage::setProperty(JSContextRef context, JSObjectRef object,
 
                        NFCConverter convert(context);
 
-
                        if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value) || !JSIsArrayValue(context, value)) {
                                LoggerE("value is invald.");
                                ThrowMsg(ConversionException, "value is invald.");
                        }
                        INdefMessagePtr ndefMessage(privateObject->getObject());
-                       JSValueUnprotect(privateObject->getContext(), (JSValueRef)ndefMessage->getRecordesPtr());
-                       JSValueProtect(privateObject->getContext(), value);
-                       ndefMessage->setRecordesPtr((void *)value);
+                       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
 
-                       return true;
+                       JSObjectRef obj = convert.toJSObjectRef(value);
+                       
+                       if (!obj) {
+                               LoggerE("Object is null");
+                               ThrowMsg(ConversionException, "Object is null");
+                       }
+                       unsigned int arrayLen = JSGetArrayLength(global_context, obj);
+                       JSValueRef valueArray[arrayLen];
+                       for (std::size_t i = 0; i < arrayLen; ++i) {
+                               JSValueRef element = JSGetArrayElement(global_context, obj, i);
+                               valueArray[i] = element;
+                       }
+                       JSValueRef recordsArray = JSCreateArrayObject(global_context, arrayLen, valueArray);            
+                       return (ndefMessage->mLocalProperty).setArrayProperty(global_context, TIZEN_NDEFMESSAGE_RECORDS, recordsArray);
                 }
        } Catch (NullPointerException) {
                LoggerE("NullPointerException: " << _rethrown_exception.GetMessage());
@@ -321,22 +359,31 @@ JSValueRef JSNdefMessage::toByte(JSContextRef context,
                INdefMessagePtr ndefMessage(privateObject->getObject());
                NFCConverter convert(context);
 
-               std::vector<void *> records = convert.toVectorOfRecordHandles(static_cast<JSValueRef>(ndefMessage->getRecordesPtr()));
-               INdefMessagePtr newMessage = NFCFactory::getInstance().createNDEFMessageObject(records);
-               return convert.toJSValueRef(newMessage->toByte());
+               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
+               std::vector<void *> records;
+               try {
+                       JSValueRef recordsValue = (ndefMessage->mLocalProperty).getProperty(global_context, TIZEN_NDEFMESSAGE_RECORDS);
+                       records = convert.toVectorOfRecordHandles(recordsValue);
+               } catch (WrtDeviceApis::Commons::Exception& err) {
+                       LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+                       ThrowMsg(InvalidArgumentException, "Invalid NDEF Message");
+               }
+               return convert.toJSValueRef(ndefMessage->toByte(records));
        } Catch (ConversionException) {
                LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
                return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (WrtDeviceApis::Commons::UnknownException) {
-               LoggerE("Exception: " << _rethrown_exception.GetMessage());
-       } Catch (PlatformException) {
-               LoggerE("Exception: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch(NullPointerException) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
                return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(InvalidArgumentException) {
+               LoggerE("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::UnknownException) {
+               LoggerE("Exception: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
+               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
        }
 
        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
index 6080af1..5062d60 100755 (executable)
 #include <CommonsJavaScript/PrivateObject.h>
 #include "INdefMessage.h"
 
+#define TIZEN_NDEFMESSAGE_ATTRIBUTENAME "NDEFMessage"
+#define TIZEN_NDEFMESSAGE_RECORDCOUNT "recordCount"
+#define TIZEN_NDEFMESSAGE_RECORDS "records"
+
 namespace DeviceAPI {
 namespace NFC {
 
@@ -37,10 +41,8 @@ public:
 
     static const JSClassRef getClassRef();
 
-    static JSObjectRef createJSObject(JSContextRef context);
-    static JSObjectRef createJSObject(JSContextRef context, void *messageHandle);
-    static JSObjectRef createJSObject(JSContextRef context, INdefMessagePtr message);
-    static JSObjectRef createJSObject(JSContextRef context, std::vector<void *> ndefRcords);
+    static JSObjectRef createJSObject(JSContextRef context, void *messageHandle = NULL);
+    static JSObjectRef createJSObject(JSContextRef context, INdefMessagePtr message, JSValueRef recordArray);
     static JSObjectRef createJSObject(JSContextRef context, std::vector<unsigned char> rawdata);
 
     static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
old mode 100644 (file)
new mode 100755 (executable)
index df1f4fd..2608aea
@@ -87,13 +87,15 @@ const JSClassDefinition* JSNdefRecord::getClassInfo() {
 
 JSClassRef JSNdefRecord::m_jsClassRef = JSClassCreate(JSNdefRecord::getClassInfo());
 
-JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, const NdefRecordData &ndefRecordData) {
+
+JSObjectRef JSNdefRecord::createJSObject(JSContextRef context) {
        LoggerD("Entered");
-       return createJSObject(context, ndefRecordData.properties, ndefRecordData.payload);
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject());
+       
 }
 
-JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
+JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload, bool isValid) {
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload, isValid));
 }
 
 JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, std::vector<unsigned char> rawdata) {
@@ -131,52 +133,57 @@ JSObjectRef JSNdefRecord::constructor(JSContextRef ctx, JSObjectRef constructor,
 {
        LoggerD("entered");
 
+       JSObjectRef result = NULL;
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
     Try {
                ArgumentValidator validator(ctx, argumentCount, arguments);
                NFCConverter convert(ctx);
-               JSObjectRef result = NULL;
-               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
 
-               if (argumentCount < 3) {
-                       if (validator.toArrayObject(0))
-                               result = createJSObject(global_context, convert.toVectorOfUChars(arguments[0]));
+               if (argumentCount == 0) {
+                       throw TypeMismatchException("Argument count is 0.");
+               } else if (argumentCount < 3) {
+                       if (!JSIsArrayValue(ctx, arguments[0]))
+                               throw TypeMismatchException("Raw data is not array.");
+                       else
+                               result = createJSObject(global_context, convert.toVectorOfOctets(arguments[0]));
                } else {
                        NdefRecordProperties prop;
-                       prop.tnf = static_cast<nfcTNF>(validator.toNumber(0));
-                       if (validator.toArrayObject(1)) 
-                               prop.typeName = convert.toVectorOfUChars(arguments[1]);
+                       bool isValid = true;
+                       prop.tnf = static_cast<short>(validator.toNumber(0));
+                       if (!JSIsArrayValue(ctx, arguments[1]))
+                               isValid = false;
+                       else
+                               prop.typeName = convert.toVectorOfOctets(arguments[1]);
                        std::vector<unsigned char> payload;
-                       if (validator.toArrayObject(2))
-                               payload = convert.toVectorOfUChars(arguments[2]);
-                       if (validator.toArrayObject(3, true))
-                               prop.id = convert.toVectorOfUChars(arguments[3]);
-                       result = createJSObject(global_context, prop, payload);
+                       if (!JSIsArrayValue(ctx, arguments[2]))
+                               isValid = false;
+                       else
+                               payload = convert.toVectorOfOctets(arguments[2]);
+                       if ((argumentCount > 3) && JSIsArrayValue(ctx, arguments[3]))
+                               prop.id = convert.toVectorOfOctets(arguments[3]);
+                       result = createJSObject(global_context, prop, payload, isValid);
                }
-               if (result) {
-                       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
-                   JSObjectSetProperty(global_context, result, ctorName, constructor,
-                       kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
-                   JSStringRelease(ctorName);
-                       return result;
-               } else
-                       throw TypeMismatchException("Parameter Type Mismatch");
     } Catch (BasePlatformException) {
-       return JSWebAPIErrorFactory::postException(ctx, exception, _rethrown_exception);
+               LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
        } Catch(ConversionException) {
                LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
        } Catch (InvalidArgumentException) {
                LoggerE("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Invalid Values");
        } Catch (PlatformException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
        } Catch (WrtDeviceApis::Commons::UnknownException) {
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
-       return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
+       if (result == NULL)
+               result = createJSObject(global_context);
+
+       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+    JSObjectSetProperty(global_context, result, ctorName, constructor,
+        kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+    JSStringRelease(ctorName);
+       return result;
 }
 
 JSValueRef JSNdefRecord::getProperty(JSContextRef context, JSObjectRef object,
@@ -190,16 +197,16 @@ JSValueRef JSNdefRecord::getProperty(JSContextRef context, JSObjectRef object,
                        ThrowMsg(NullPointerException, "Private object not set.");
                }
                INdefRecordPtr ndefRecord = priv->getObject();
-
+               NdefRecordData recordData = ndefRecord->getNDEFRecordData();
                LoggerD("propertyName : " << convert.toString(propertyName));
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFRECORD_TNF))
-                       return convert.toJSValueRef(ndefRecord->getTNF());
+                       return convert.toJSValueRef(recordData.properties.tnf);
                else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFRECORD_TYPE))
-                       return convert.toJSValueRef(ndefRecord->getTypeName());
+                       return convert.toJSValueRef(recordData.properties.typeName);
                else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFRECORD_ID))
-                       return convert.toJSValueRef(ndefRecord->getID());
+                       return convert.toJSValueRef(recordData.properties.id);
                else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFRECORD_PAYLOAD))
-                       return convert.toJSValueRef(ndefRecord->getPayload());
+                       return convert.toJSValueRef(recordData.payload);
        } Catch (ConversionException) {
                LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::UnknownException) {
index 1397366..a78a47b 100755 (executable)
@@ -36,10 +36,9 @@ public:
 
        static const JSClassRef getClassRef();
 
+       static JSObjectRef createJSObject(JSContextRef context);
        static JSObjectRef createJSObject(JSContextRef context, 
-               const NdefRecordData &ndefRecordData);
-       static JSObjectRef createJSObject(JSContextRef context, 
-               const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+               const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload, bool isValid = true);
        static JSObjectRef createJSObject(JSContextRef context, 
                std::vector<unsigned char> rawdata);
        static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
old mode 100644 (file)
new mode 100755 (executable)
index 01a2241..6bfcc5b
@@ -80,20 +80,16 @@ const JSClassDefinition* JSNdefRecordMedia::getClassInfo() {
 JSClassRef JSNdefRecordMedia::m_jsClassRef = JSClassCreate(JSNdefRecordMedia::getClassInfo());
 
 JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordMediaObject(ndefRecordProperties, payload));
 }
 
-JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, const std::string &mimeType, std::vector<unsigned char> data) {
-       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(mimeType, data));
+JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, const std::string &mimeType, std::vector<unsigned char> data, bool isValid) {
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordMediaObject(mimeType, data, isValid));
 }
 
 JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, INdefRecordPtr ndefRecord) {
        NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
 
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
-       }
-
        JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
        return obj;
 }
@@ -110,40 +106,37 @@ JSObjectRef JSNdefRecordMedia::constructor(JSContextRef ctx, JSObjectRef constru
 {
        LoggerD("entered");
 
-       Try {
-               ArgumentValidator validator(ctx, argumentCount, arguments);
-               std::string mimeType = validator.toString(0);
-               std::vector<unsigned char> data;
-               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
+       std::vector<unsigned char> data;
+       std::string mimeType = "";
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
+       bool isValid = true;
+
+       ArgumentValidator validator(ctx, argumentCount, arguments);
+       try {
+               mimeType = validator.toString(0);
+       } catch (...) {
+               isValid = false;
+               LoggerE("Can't convert mimeType");
+       }
 
-               Converter convert(ctx);
+       try {
+               NFCConverter convert(ctx);
                if (validator.toArrayObject(1))
-                       data = convert.toVectorOfUChars(arguments[1]);
-
-               JSObjectRef result = createJSObject(global_context, mimeType, data);
-
-               JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
-           JSObjectSetProperty(global_context, result, ctorName, constructor,
-               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
-           JSStringRelease(ctorName);
-               return result;
-    } Catch (BasePlatformException) {
-       return JSWebAPIErrorFactory::postException(ctx, exception, _rethrown_exception);
-       } Catch(ConversionException) {
-               LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               LoggerE("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (PlatformException) {
-               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
-       } Catch (WrtDeviceApis::Commons::UnknownException) {
-               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LoggerE("Exception: " << _rethrown_exception.GetMessage());
+                       data = convert.toVectorOfOctets(arguments[1]);
+       } catch (...) {
+               isValid = false;
+               LoggerE("Can't convert data");
        }
-       return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
+
+
+       JSObjectRef result = createJSObject(global_context, mimeType, data, isValid);
+
+       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+    JSObjectSetProperty(global_context, result, ctorName, constructor,
+        kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+    JSStringRelease(ctorName);
+       return result;
+
 }
 
 JSValueRef JSNdefRecordMedia::getProperty(JSContextRef context, JSObjectRef object,
@@ -158,14 +151,7 @@ JSValueRef JSNdefRecordMedia::getProperty(JSContextRef context, JSObjectRef obje
                                ThrowMsg(NullPointerException, "Private object not set.");
                        }
                        INdefRecordPtr ndefRecord = priv->getObject();
-                       char * mimeType = NULL;
-                       if (ndefRecord->getMimeType(&mimeType)) {
-                               std::string result(mimeType);
-                               free(mimeType);
-                               LoggerD("mimeType : " << result);
-                               return convert.toJSValueRef(result);
-                       }
-                       LoggerD("This record is not MEDIA Type");
+                       return convert.toJSValueRef(ndefRecord->getMimeType());
                }
 
        } Catch (ConversionException) {
index c1f4b95..070be2c 100755 (executable)
@@ -36,7 +36,7 @@ public:
                const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
 
        static JSObjectRef createJSObject(JSContextRef context, 
-               const std::string &mimeType, std::vector<unsigned char> data);
+               const std::string &mimeType, std::vector<unsigned char> data, bool isValid = true);
        static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
 
     static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
old mode 100644 (file)
new mode 100755 (executable)
index eb920c7..bd78ed8
@@ -85,20 +85,16 @@ const JSClassDefinition* JSNdefRecordText::getClassInfo() {
 JSClassRef JSNdefRecordText::m_jsClassRef = JSClassCreate(JSNdefRecordText::getClassInfo());
 
 JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordTextObject(ndefRecordProperties, payload));
 }
 
-JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, const std::string &text, const std::string &langCode, const short encodeType) {
-       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(text, langCode, encodeType));
+JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, const std::string &text, const std::string &langCode, const nfcTextEncodeUTF encodeType, bool isValid) {
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordTextObject(text, langCode, encodeType, isValid));
 }
 
 JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, INdefRecordPtr ndefRecord) {
        NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
 
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
-       }
-
        JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
        return obj;
 }
@@ -115,43 +111,49 @@ JSObjectRef JSNdefRecordText::constructor(JSContextRef ctx, JSObjectRef construc
 {
        LoggerD("entered");
 
-       Try {
-               ArgumentValidator validator(ctx, argumentCount, arguments);
-               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
-
-               NFCConverter convert(ctx);
-               short encodeType = NFC_TEXT_ENCODE_UTF_8;
-
-               std::string text = validator.toString(0);
-               std::string languageCode = validator.toString(1);
-               std::string encoding = validator.toString(2, true);
-               if (encoding != "")
-                       encodeType = convert.toNfcTextEncodeUTF(encoding);
-
-               JSObjectRef result = createJSObject(global_context, text, languageCode, encodeType);
-               JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
-           JSObjectSetProperty(global_context, result, ctorName, constructor,
-               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
-           JSStringRelease(ctorName);
-
-               return result;
-    } Catch (BasePlatformException) {
-       return JSWebAPIErrorFactory::postException(ctx, exception, _rethrown_exception);
-       } Catch(ConversionException) {
-               LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               LoggerE("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (PlatformException) {
-               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
-       } Catch (WrtDeviceApis::Commons::UnknownException) {
-               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LoggerE("Exception: " << _rethrown_exception.GetMessage());
+       ArgumentValidator validator(ctx, argumentCount, arguments);
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
+
+       bool isValid = true;
+
+       NFCConverter convert(ctx);
+       nfcTextEncodeUTF encodeType = NFC_TEXT_ENCODE_UTF_8;
+
+       std::string text = "";
+       std::string languageCode = "";
+       std::string encoding = "";
+
+       try {
+               text = validator.toString(0);
+       } catch (...) {
+               isValid = false;
+               LoggerE("Can't convert text");
+       }
+
+       try {
+               languageCode = validator.toString(1);
+       } catch (...) {
+               isValid = false;
+               LoggerE("Can't convert languageCode");
+       }
+
+       try {
+               encoding = validator.toString(2, true);
+       } catch (...) {
+               encoding = "";
+               LoggerE("Can't convert encoding");
        }
-       return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
+
+       if (encoding != "")
+               encodeType = convert.toNfcTextEncodeUTF(encoding);
+
+       JSObjectRef result = createJSObject(global_context, text, languageCode, encodeType, isValid);
+       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+    JSObjectSetProperty(global_context, result, ctorName, constructor,
+        kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+    JSStringRelease(ctorName);
+
+       return result;
 }
 JSValueRef JSNdefRecordText::getProperty(JSContextRef context, JSObjectRef object,
        JSStringRef propertyName, JSValueRef* exception) {
@@ -166,32 +168,13 @@ JSValueRef JSNdefRecordText::getProperty(JSContextRef context, JSObjectRef objec
                INdefRecordPtr ndefRecord = priv->getObject();
 
                if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFRECORD_TEXT_TEXT)) {
-                       char * text = NULL;
-                       if (ndefRecord->getText(&text)) {
-                               std::string result(text);
-                               free(text);
-                               LoggerD("text : " << result);
-                               return convert.toJSValueRef(result);
-                       }
-                       LoggerD("This record is not Text Type");
+                       return convert.toJSValueRef(ndefRecord->getText());
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFRECORD_TEXT_LANGCODE)) {
-                       char * langCode = NULL;
-                       if (ndefRecord->getLangCode(&langCode)) {
-                               std::string result(langCode);
-                               free(langCode);
-                               LoggerD("langCode : " << result);
-                               return convert.toJSValueRef(result);
-                       }
-                       LoggerD("This record is not Text Type");
+                       return convert.toJSValueRef(ndefRecord->getLanguageCode());
                } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NDEFRECORD_TEXT_ENCODING)) {
-                       nfcTextEncodeUTF encodeType = NFC_TEXT_ENCODE_UTF_16;
-                       if (ndefRecord->getEncodeType(&encodeType)) {
-                               LoggerD("encodeType : " << encodeType);
-                               return convert.toJSValueRef(convert.toNfcTextEncodeUTFString(encodeType));
-                       }
-                       LoggerD("This record is not Text Type");
+                       nfcTextEncodeUTF encodeType = ndefRecord->getEncoding();
+                       return convert.toJSValueRef(convert.toNfcTextEncodeUTFString(encodeType));
                }
-
        } Catch (ConversionException) {
                LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::UnknownException) {
@@ -200,6 +183,8 @@ JSValueRef JSNdefRecordText::getProperty(JSContextRef context, JSObjectRef objec
                LoggerE("PlatformExceptionException: " << _rethrown_exception.GetMessage());
        } Catch (NullPointerException) {
                LoggerE("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::NotFoundException) {
+               LoggerE("NotFoundException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
index 87e9181..09fdb8a 100755 (executable)
@@ -36,7 +36,7 @@ public:
                const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
 
        static JSObjectRef createJSObject(JSContextRef context, const std::string &text, 
-               const std::string &langCode, const short encodeType);
+               const std::string &langCode, const nfcTextEncodeUTF encodeType, bool isValid = true);
        static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
 
     static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
old mode 100644 (file)
new mode 100755 (executable)
index 285f025..052a342
 
 #include <JSWebAPIErrorFactory.h>
 #include <SecurityExceptions.h>
-#include <CommonsJavaScript/Converter.h>
 #include <ArgumentValidator.h>
 #include <GlobalContextManager.h>
 #include <PlatformException.h>
 
 #include "NFCFactory.h"
+#include "NFCConverter.h"
 #include "JSNdefRecordURI.h"
 #include <Logger.h>
 
@@ -89,20 +89,16 @@ void JSNdefRecordURI::finalize(JSObjectRef object) {
 }
 
 JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(ndefRecordProperties, payload));
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordUriObject(ndefRecordProperties, payload));
 }
 
-JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, const std::string &uri) {
-       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordObject(uri));
+JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, const std::string &uri, bool isValid) {
+       return createJSObject(context, NFCFactory::getInstance().createNDEFRecordUriObject(uri, isValid));
 }
 
 JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, INdefRecordPtr ndefRecord) {
        NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
 
-       if (!priv) {
-               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
-       }
-
        JSObjectRef obj = JSObjectMake(context, getClassRef(), priv);
        return obj;
 }
@@ -111,34 +107,24 @@ JSObjectRef JSNdefRecordURI::constructor(JSContextRef ctx, JSObjectRef construct
 {
        LoggerD("entered");
 
-       Try {
-               ArgumentValidator validator(ctx, argumentCount, arguments);
-               JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
+       ArgumentValidator validator(ctx, argumentCount, arguments);
+       JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(ctx);
+       bool isValid = true;
+       std::string uri = "";
 
-               JSObjectRef result = createJSObject(global_context, validator.toString(0));
+       try {
+               uri = validator.toString(0);
+       } catch (...) {
+               isValid = false;
+               LoggerE("Can't convert text");
+       }
+       JSObjectRef result = createJSObject(global_context, uri, isValid);
 
-               JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
-           JSObjectSetProperty(global_context, result, ctorName, constructor,
-               kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
-           JSStringRelease(ctorName);
+       JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+    JSObjectSetProperty(global_context, result, ctorName, constructor,
+        kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+    JSStringRelease(ctorName);
                return result;
-    } Catch (BasePlatformException) {
-       return JSWebAPIErrorFactory::postException(ctx, exception, _rethrown_exception);
-       } Catch(ConversionException) {
-               LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       } Catch (InvalidArgumentException) {
-               LoggerE("InvalidArgumentException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "Invalid Values");
-       } Catch (PlatformException) {
-               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-               return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
-       } Catch (WrtDeviceApis::Commons::UnknownException) {
-               LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
-       } Catch (WrtDeviceApis::Commons::Exception) {
-               LoggerE("Exception: " << _rethrown_exception.GetMessage());
-       }
-       return JSWebAPIErrorFactory::postException(ctx, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
 }
 JSValueRef JSNdefRecordURI::getProperty(JSContextRef context, JSObjectRef object,
        JSStringRef propertyName, JSValueRef* exception) {
@@ -151,14 +137,8 @@ JSValueRef JSNdefRecordURI::getProperty(JSContextRef context, JSObjectRef object
                                ThrowMsg(NullPointerException, "Private object not set.");
                        }
                        INdefRecordPtr ndefRecord = priv->getObject();
-                       char * uri = NULL;
-                       if (ndefRecord->getUri(&uri)) {
-                               Converter convert(context);
-                               std::string result(uri);
-                               free(uri);
-                               return convert.toJSValueRef(result);
-                       }
-                       LoggerD("This record is not URI Type");
+                       NFCConverter convert(context);
+                       return convert.toJSValueRef(ndefRecord->getUri());
                }
        } Catch (ConversionException) {
                LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
@@ -168,6 +148,8 @@ JSValueRef JSNdefRecordURI::getProperty(JSContextRef context, JSObjectRef object
                LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
        } Catch (NullPointerException) {
                LoggerE("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::NotFoundException) {
+               LoggerE("NotFoundException: " << _rethrown_exception.GetMessage());
        } Catch (WrtDeviceApis::Commons::Exception) {
                LoggerE("Exception: " << _rethrown_exception.GetMessage());
        }
index c446607..6d233da 100755 (executable)
@@ -35,7 +35,7 @@ public:
        static JSObjectRef createJSObject(JSContextRef context, 
                const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
 
-       static JSObjectRef createJSObject(JSContextRef context, const std::string &uri);
+       static JSObjectRef createJSObject(JSContextRef context, const std::string &uri, bool isValid = true);
 
        static JSObjectRef createJSObject(JSContextRef context, INdefRecordPtr ndefRecord);
 
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 3df45e4..7d93350
@@ -18,6 +18,7 @@
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
 #include <CommonsJavaScript/JSUtils.h>
+#include <JSUtil.h>
 #include "NFCFactory.h"
 #include "NFCConverter.h"
 #include "JSNdefRecord.h"
@@ -172,36 +173,23 @@ std::string NFCConverter::toNfcTagTypeString(nfcTagType type) {
 }
 
 nfcTextEncodeUTF NFCConverter::toNfcTextEncodeUTF(std::string encodeString) {
-       if (encodeString == "UTF8")
-               return NFC_TEXT_ENCODE_UTF_8;
-       else if (encodeString == "UTF16")
+       if (encodeString == "UTF16")
                return NFC_TEXT_ENCODE_UTF_16;
        else
-               Throw(ConversionException);
+               return NFC_TEXT_ENCODE_UTF_8;
+
 }
 
 std::string NFCConverter::toNfcTextEncodeUTFString(nfcTextEncodeUTF encode) {
        switch(encode) {
-               case NFC_TEXT_ENCODE_UTF_8:
-                       return "UTF8";
-                       break;
                case NFC_TEXT_ENCODE_UTF_16:
                        return "UTF16";
                        break;
+               case NFC_TEXT_ENCODE_UTF_8:
                default:
-                       Throw(ConversionException);
-       }
-}
-
-nfcTNF NFCConverter::toNfcTNF(const JSValueRef& arg) {
-       long value = toLong(arg);
-       LoggerD("toNfcTNF,  value == " << value);
-
-       if ((value < NFC_TNF_EMPTY) || (value > NFC_TNF_UNCHANGED)) {
-               ThrowMsg(InvalidArgumentException, "It is not a correct tnf value");
+                       return "UTF8";
+                       break;
        }
-
-       return static_cast<nfcTNF>(value);
 }
 
 bool NFCConverter::initializeAllowedProperties()
@@ -260,15 +248,8 @@ JSValueRef NFCConverter::toJSValueRef(std::vector<NFCTagProperties> props) {
        return jsResult;
 }
 
-JSValueRef NFCConverter::toJSNdefRecordArray(INdefMessagePtr ndefMessage) {
-       long recordCount = ndefMessage->getRecordCount();
-       std::vector<JSValueRef> jsResult;
-
-       for (long i = 0; i < recordCount; i++) {
-               JSValueRef ndefRecord = toJSValueRef(ndefMessage->getNDEFRecord(i));
-               jsResult.push_back(ndefRecord);
-       }
-       return toJSValueRef(jsResult);
+std::vector<unsigned char> NFCConverter::toVectorOfOctets(const JSValueRef& arg) {
+       return Common::JSUtil::JSArrayToType_<unsigned char>(m_context, arg, Common::JSUtil::JSValueToOctet);
 }
 
 bool NFCConverter::isNdefRecord(const JSValueRef& arg) {
@@ -308,13 +289,21 @@ std::vector<void *> NFCConverter::toVectorOfRecordHandles(const JSValueRef& arg)
 
 std::vector<void *> NFCConverter::toVectorOfRecordHandles(const JSObjectRef& obj) {
     std::vector<void *> result;
-
     for (std::size_t i = 0; i < JSGetArrayLength(m_context, obj); ++i) {
         JSValueRef element = JSGetArrayElement(m_context, obj, i);
-       if (isNdefRecord(element))
-               result.push_back(getRecordHandle(element));
-       else
-               ThrowMsg(Commons::ConversionException, "JS array has items those are not NDEFRecord.");
+               try {
+                       if (isNdefRecord(element))
+                               result.push_back(getRecordHandle(element));
+                       else
+                               ThrowMsg(Commons::ConversionException, "JS array has items those are not NDEFRecord.");
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+                       for (std::size_t j = 0; j < result.size(); ++j) {
+                               if (result[j])
+                                       nfc_ndef_record_destroy((nfc_ndef_record_h)result[j]);
+                       }
+                       ThrowMsg(Commons::ConversionException, "JS array has items those are not NDEFRecords or invalid records.");
+       }
     }
     return result;
 }
@@ -337,7 +326,7 @@ void *NFCConverter::getRecordHandle(const JSValueRef& arg) {
        LoggerD("Entered");
        if (!isNdefRecord(arg)) {
                ThrowMsg(Commons::ConversionException,
-                        "Message is JS null or JS undefined.");
+                        "Not record value");
        }
        JSObjectRef obj = toJSObjectRef(arg);
        
@@ -352,35 +341,10 @@ void *NFCConverter::getRecordHandle(const JSValueRef& arg) {
        }
 
        INdefRecordPtr record = privateObject->getObject();
-
-       return record->getHandle();
-}
-
-void *NFCConverter::copiedMessage(const JSValueRef& arg) {
-       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg) ||
-               (!JSValueIsObjectOfClass(m_context, arg, JSNdefMessage::getClassRef()))) {
-               ThrowMsg(Commons::ConversionException,
-                        "Message is JS null or JS undefined.");
-       }
-       JSObjectRef obj = toJSObjectRef(arg);
-       
-       if (!obj) {
-               LoggerE("Object is null");
-               ThrowMsg(Commons::ConversionException, "Object is null");
-       }
-       return copiedMessage(obj);
-}
-
-void *NFCConverter::copiedMessage(const JSObjectRef& obj) {
-       NdefMessagePrivObject* privateObject = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(obj));
-       if (!privateObject) {
-               LoggerE("Private object is not set.");
-               ThrowMsg(Commons::ConversionException, "Private object is not set");
-       }
-
-       INdefMessagePtr message = privateObject->getObject();
-       std::vector<void *> records = toVectorOfRecordHandles(static_cast<JSValueRef>(message->getRecordesPtr()));
-       return message->makeMessage(records);
+       void *handle = record->getHandle();
+       if (handle == NULL)
+               ThrowMsg(Commons::ConversionException, "Invalid Handle");
+       return handle;
 }
 
 NFCChangedCallback NFCConverter::toNFCChangedCallback(const JSValueRef& arg) {
index 15c9e27..15d68f2 100755 (executable)
@@ -48,18 +48,15 @@ class NFCConverter : public WrtDeviceApis::CommonsJavaScript::Converter
        std::string toNfcTagTypeString(nfcTagType type);
        nfcTextEncodeUTF toNfcTextEncodeUTF(std::string encodeString);
        std::string toNfcTextEncodeUTFString(nfcTextEncodeUTF encode);
-       nfcTNF toNfcTNF(const JSValueRef& arg);
        JSValueRef toJSValueRef(const std::vector<unsigned char>& arg);
        JSValueRef toJSValueRef(std::vector<NFCTagProperties> props);
        JSValueRef toJSValueRef(NdefRecordData arg);
        bool isNdefRecord(const JSValueRef& arg);
+       std::vector<unsigned char> toVectorOfOctets(const JSValueRef& arg);
        std::vector<void *> toVectorOfRecordHandles(const JSValueRef& arg);
        std::vector<void *> toVectorOfRecordHandles(const JSObjectRef& obj);
        std::string toRecordClassName(NdefRecordData arg);
        void *getRecordHandle(const JSValueRef& arg);
-       void *copiedMessage(const JSValueRef& arg);
-       void *copiedMessage(const JSObjectRef& obj);
-       JSValueRef toJSNdefRecordArray(INdefMessagePtr ndefMessage);
        NFCChangedCallback toNFCChangedCallback(const JSValueRef& arg);
   private:
     bool initializeAllowedProperties();
index 4c73f28..cc85435 100755 (executable)
@@ -21,6 +21,9 @@
 #include "NFCAdapter.h"
 #include "NdefMessage.h"
 #include "NdefRecord.h"
+#include "NdefRecordMedia.h"
+#include "NdefRecordText.h"
+#include "NdefRecordURI.h"
 #include "NFCTag.h"
 #include "NFCTarget.h"
 
@@ -35,40 +38,40 @@ INdefMessagePtr NFCFactory::createNDEFMessageObject() {
        return INdefMessagePtr( new NdefMessage() );
 }
 
-INdefMessagePtr NFCFactory::createNDEFMessageObject(void *messageHandle) {
-       return INdefMessagePtr( new NdefMessage(messageHandle) );
+INdefRecordPtr NFCFactory::createNDEFRecordObject() {
+       return INdefRecordPtr( new NdefRecord() );
 }
 
-INdefMessagePtr NFCFactory::createNDEFMessageObject(std::vector<void *> ndefRcords) {
-       return INdefMessagePtr( new NdefMessage(ndefRcords) );
+INdefRecordPtr NFCFactory::createNDEFRecordObject(std::vector<unsigned char> data) {
+       return INdefRecordPtr( new NdefRecord(data) );
 }
 
-INdefMessagePtr NFCFactory::createNDEFMessageObject(std::vector<unsigned char> rawdata) {
-       return INdefMessagePtr( new NdefMessage(rawdata) );
+INdefRecordPtr NFCFactory::createNDEFRecordObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload, bool isValid) {
+       return INdefRecordPtr( new NdefRecord(ndefRecordProperties, payload, isValid) );
 }
 
-INdefRecordPtr NFCFactory::createNDEFRecordObject() {
-       return INdefRecordPtr( new NdefRecord() );
+INdefRecordPtr NFCFactory::createNDEFRecordTextObject(const std::string &text, const std::string &langCode, const nfcTextEncodeUTF encodeType, bool isValid) {
+       return INdefRecordPtr( new NdefRecordText(text, langCode, encodeType, isValid) );
 }
 
-INdefRecordPtr NFCFactory::createNDEFRecordObject(std::vector<unsigned char> data) {
-       return INdefRecordPtr( new NdefRecord(data) );
+INdefRecordPtr NFCFactory::createNDEFRecordTextObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
+       return INdefRecordPtr( new NdefRecordText(ndefRecordProperties, payload) );
 }
 
-INdefRecordPtr NFCFactory::createNDEFRecordObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
-       return INdefRecordPtr( new NdefRecord(ndefRecordProperties, payload) );
+INdefRecordPtr NFCFactory::createNDEFRecordUriObject(const std::string &uri, bool isValid) {
+       return INdefRecordPtr( new NdefRecordUri(uri, isValid) );
 }
 
-INdefRecordPtr NFCFactory::createNDEFRecordObject(const std::string &text, const std::string &langCode, const short encodeType) {
-       return INdefRecordPtr( new NdefRecord(text, langCode, encodeType) );
+INdefRecordPtr NFCFactory::createNDEFRecordUriObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
+       return INdefRecordPtr( new NdefRecordUri(ndefRecordProperties, payload) );
 }
 
-INdefRecordPtr NFCFactory::createNDEFRecordObject(const std::string &uri) {
-       return INdefRecordPtr( new NdefRecord(uri) );
+INdefRecordPtr NFCFactory::createNDEFRecordMediaObject(const std::string &mimeType, const std::vector<unsigned char> data, bool isValid) {
+       return INdefRecordPtr( new NdefRecordMedia(mimeType, data, isValid) );
 }
 
-INdefRecordPtr NFCFactory::createNDEFRecordObject(const std::string &mimeType, const std::vector<unsigned char> data) {
-       return INdefRecordPtr( new NdefRecord(mimeType, data) );
+INdefRecordPtr NFCFactory::createNDEFRecordMediaObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
+       return INdefRecordPtr( new NdefRecordMedia(ndefRecordProperties, payload) );
 }
 
 INFCTagPtr NFCFactory::createNFCTagObject(void *tagHandle) {
index 6d1bc66..b536ff4 100755 (executable)
@@ -39,15 +39,15 @@ private:
 public:
        INFCAdapterPtr createNFCAdapterObject();
        INdefMessagePtr createNDEFMessageObject();
-       INdefMessagePtr createNDEFMessageObject(void *messageHandle);
-       INdefMessagePtr createNDEFMessageObject(std::vector<void *> ndefRcords);
-       INdefMessagePtr createNDEFMessageObject(std::vector<unsigned char> rawdata);
        INdefRecordPtr createNDEFRecordObject();
        INdefRecordPtr createNDEFRecordObject(std::vector<unsigned char> data);
-       INdefRecordPtr createNDEFRecordObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
-       INdefRecordPtr createNDEFRecordObject(const std::string &text, const std::string &langCode, const short encodeType);
-       INdefRecordPtr createNDEFRecordObject(const std::string &uri);
-       INdefRecordPtr createNDEFRecordObject(const std::string &mimeType, const std::vector<unsigned char> data);
+       INdefRecordPtr createNDEFRecordObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload, bool isValid = true);
+       INdefRecordPtr createNDEFRecordTextObject(const std::string &text, const std::string &langCode, const nfcTextEncodeUTF encodeType, bool isValid = true);
+       INdefRecordPtr createNDEFRecordTextObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+       INdefRecordPtr createNDEFRecordUriObject(const std::string &uri, bool isValid = true);
+       INdefRecordPtr createNDEFRecordUriObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+       INdefRecordPtr createNDEFRecordMediaObject(const std::string &mimeType, const std::vector<unsigned char> data, bool isValid = true);
+       INdefRecordPtr createNDEFRecordMediaObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
        INFCTagPtr createNFCTagObject(void *tagHandle);
        INFCTargetPtr createNFCTargetObject(void *targetHandle);
 
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 573a81c..befb109
@@ -243,9 +243,6 @@ void NFCTag::writeNdefManualAnswer(int result)
 {
        LoggerD("Enter");
        if (m_EventTagActionWritePtr.Get() != NULL) {
-               if (nfc_ndef_message_destroy(static_cast<nfc_ndef_message_h>(m_EventTagActionWritePtr->getNdefForWriting())) != NFC_ERROR_NONE)
-                       LoggerE("Can't destroy NdefMessage");
-
                if ((nfc_error_e)result == NFC_ERROR_NONE) {
                        m_EventTagActionWritePtr->setResult(TRUE);
                } else {
old mode 100644 (file)
new mode 100755 (executable)
index 5a4231a..79c179f
@@ -145,9 +145,6 @@ void NFCTarget::sendNDEF(const EventTargetActionSendPtr& event) {
 void NFCTarget::sendNDEFManualAnswer(unsigned int result) {
        LoggerD("Enter");
        if (m_EventTargetActionSendPtr.Get() != NULL) {
-               if (nfc_ndef_message_destroy(static_cast<nfc_ndef_message_h>(m_EventTargetActionSendPtr->getMessageForSending())) != NFC_ERROR_NONE)
-                       LoggerE("Can't destroy NdefMessage");
-
                if ((nfc_error_e)result == NFC_ERROR_NONE) {
                        m_EventTargetActionSendPtr->setResult(TRUE);
                } else {
old mode 100644 (file)
new mode 100755 (executable)
index 52acff8..70a5cb0
@@ -121,46 +121,39 @@ nfcTagType NFCUtil::convertTonfcTagType(const unsigned short type) {
        }
 }
 
-unsigned short NFCUtil::convertToTNF(nfcTNF tnf) {
-       switch (tnf) {
-               case NFC_TNF_WELL_KNOWN:
-                       return static_cast<unsigned short>(NFC_RECORD_TNF_WELL_KNOWN);
-               case NFC_TNF_MIME_MEDIA:
-                       return static_cast<unsigned short>(NFC_RECORD_TNF_MIME_MEDIA);
-               case NFC_TNF_URI:
-                       return static_cast<unsigned short>(NFC_RECORD_TNF_URI);
-               case NFC_TNF_EXTERNAL_RTD:
-                       return static_cast<unsigned short>(NFC_RECORD_TNF_EXTERNAL_RTD);
-               case NFC_TNF_UNKNOWN:
-                       return static_cast<unsigned short>(NFC_RECORD_TNF_UNKNOWN);
-               case NFC_TNF_UNCHANGED:
-                       return static_cast<unsigned short>(NFC_RECORD_TNF_UNCHAGNED);
-               case NFC_TNF_EMPTY:
-               default:
-                       return static_cast<unsigned short>(NFC_RECORD_TNF_EMPTY);
-       }
-}
+void *NFCUtil::makeNDEFRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
+       LoggerD("entered");
 
-nfcTNF NFCUtil::convertTonfcTNF(unsigned short tnf) {
-       switch (static_cast<nfc_record_tnf_e>(tnf)) {
-               case NFC_RECORD_TNF_WELL_KNOWN:
-                       return NFC_TNF_WELL_KNOWN;
-               case NFC_RECORD_TNF_MIME_MEDIA:
-                       return NFC_TNF_MIME_MEDIA;
-               case NFC_RECORD_TNF_URI:
-                       return NFC_TNF_URI;
-               case NFC_RECORD_TNF_EXTERNAL_RTD:
-                       return NFC_TNF_EXTERNAL_RTD;
-               case NFC_RECORD_TNF_UNKNOWN:
-                       return NFC_TNF_UNKNOWN;
-               case NFC_RECORD_TNF_UNCHAGNED:
-                       return NFC_TNF_UNCHANGED;
-               case NFC_RECORD_TNF_EMPTY:
-               default:
-                       return NFC_TNF_EMPTY;
+       if ((ndefRecordProperties.tnf < 0) || (ndefRecordProperties.tnf > 6))
+               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Not Supported tnf");
+
+       nfc_ndef_record_h handle = NULL;
+
+       unsigned char *recordPayload = toCharPtr(payload);
+       unsigned int payloadSize = payload.size();
+       unsigned char *typeName = toCharPtr(ndefRecordProperties.typeName);
+       int typeSize = (static_cast<int>(ndefRecordProperties.typeName.size()) > 255) ? 255 : static_cast<int>(ndefRecordProperties.typeName.size());
+       unsigned char *id = toCharPtr(ndefRecordProperties.id);
+       int idSize = (static_cast<int>(ndefRecordProperties.id.size()) > 255) ? 255 : static_cast<int>(ndefRecordProperties.id.size());
+
+       int result = nfc_ndef_record_create(&handle, static_cast<nfc_record_tnf_e>(ndefRecordProperties.tnf), typeName, typeSize,
+               id, idSize, recordPayload, payloadSize) ;
+
+       if (recordPayload)
+               free(recordPayload);
+       if (typeName)
+               free(typeName);
+       if (id)
+               free(id);
+
+       if (result != NFC_ERROR_NONE) {
+               if (handle)
+                       nfc_ndef_record_destroy(handle);
+               throwNFCException(result, " Can't create Ndef Record");
        }
-}
+       return (void *)handle;
 
+}
 
 NdefRecordData NFCUtil::getNDEFRecordData(void *handle) {
        nfc_ndef_record_h recordHandle = static_cast<nfc_ndef_record_h>(handle);
@@ -187,7 +180,7 @@ NdefRecordData NFCUtil::getNDEFRecordData(void *handle) {
        LoggerD("typeName : " << byteToString(typeName, typeSize));
        LoggerD("payload : " << byteToString(payload, payloadSize));
 
-       recordData.properties.tnf = convertTonfcTNF(static_cast<unsigned short>(tnf));
+       recordData.properties.tnf = static_cast<short>(tnf);
        recordData.properties.typeName = toVector(typeName, typeSize);
        recordData.properties.id = toVector(id, idSize);
        recordData.payload = toVector(payload, payloadSize);
@@ -195,43 +188,12 @@ NdefRecordData NFCUtil::getNDEFRecordData(void *handle) {
        return recordData;
 }
 
-bool NFCUtil::copyNDEFRecord(void **src, void **dest) {
-       nfc_ndef_record_h *srcHandle, *destHandle;
-       srcHandle = (nfc_ndef_record_h *)src;
-       destHandle = (nfc_ndef_record_h *)dest;
-
-       NdefRecordData recordData = getNDEFRecordData(*srcHandle);
-
-       unsigned char *typeName = toCharPtr(recordData.properties.typeName);
-       unsigned char *id = toCharPtr(recordData.properties.id);
-       unsigned char *payload = toCharPtr(recordData.payload);
-
-       if (nfc_ndef_record_create(destHandle, static_cast<nfc_record_tnf_e>(convertToTNF(recordData.properties.tnf)), typeName, recordData.properties.typeName.size(),
-               id, recordData.properties.id.size(), payload, recordData.payload.size()) != NFC_ERROR_NONE) {
-               if (typeName)
-                       free(typeName);
-               if (id)
-                       free(id);
-               if (payload)
-                       free(payload);
-
-               return false;
-       }
-
-       if (typeName)
-               free(typeName);
-       if (id)
-               free(id);
-       if (payload)
-               free(payload);
-
-       return true;
-}
-
 std::string NFCUtil::getNFCErrorString(const int errorCode) {
        LoggerD ("Errorcode : " << errorCode);
        switch(errorCode) {
                case NFC_ERROR_NONE:
+               case NFC_ERROR_ALREADY_ACTIVATED:
+               case NFC_ERROR_ALREADY_DEACTIVATED:
                        return "";
                case NFC_ERROR_INVALID_PARAMETER:
                case NFC_ERROR_INVALID_NDEF_MESSAGE:
@@ -256,6 +218,8 @@ std::string NFCUtil::getNFCErrorMessage(const int errorCode) {
        LoggerD ("Errorcode : " << errorCode);
        switch(errorCode) {
                case NFC_ERROR_NONE:
+               case NFC_ERROR_ALREADY_ACTIVATED:
+               case NFC_ERROR_ALREADY_DEACTIVATED:
                        return "";
                case NFC_ERROR_INVALID_PARAMETER:
                        return "Invalid Parameter";
@@ -285,6 +249,8 @@ std::string NFCUtil::getNFCErrorMessage(const int errorCode) {
                        return "No NDEF Message";
                case NFC_ERROR_NOT_NDEF_FORMAT:
                        return "Not NDEF Format";
+               case NFC_ERROR_SECURITY_RESTRICTED:
+                       return "Security Restricted";
        }
        return "UnknownError";
 }
@@ -303,6 +269,9 @@ void NFCUtil::throwNFCException(const int errorCode, const std::string &message)
                case NFC_ERROR_NOT_ACTIVATED:
                        ThrowMsg(WrtDeviceApis::Commons::PlatformException, message);
                        break;
+               case NFC_ERROR_SECURITY_RESTRICTED:
+                       ThrowMsg(WrtDeviceApis::Commons::SecurityException, message);
+                       break;
                case NFC_ERROR_NOT_SUPPORTED:
                case NFC_ERROR_OPERATION_FAILED:
                case NFC_ERROR_DEVICE_BUSY:
index 1ec835b..563bc53 100755 (executable)
@@ -40,13 +40,11 @@ class NFCUtil
        char *byteToString(const unsigned char* buffer, const int size);
        char *byteToString(std::vector<unsigned char> *buffer);
        nfcTagType convertTonfcTagType(const unsigned short type);
-       unsigned short convertToTNF(nfcTNF tnf);
-       nfcTNF convertTonfcTNF(unsigned short tnf);
        NdefRecordData getNDEFRecordData(void *handle);
-       bool copyNDEFRecord(void **src, void **dest);
        std::string getNFCErrorString(const int errorCode);
        std::string getNFCErrorMessage(const int errorCode);
        void throwNFCException(const int errorCode, const std::string &message);
+       void *makeNDEFRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
 };
 
 }
index 4e006d5..b0240ad 100755 (executable)
@@ -28,143 +28,125 @@ using namespace WrtDeviceApis::Commons;
 NdefMessage::NdefMessage()
 {
        LoggerD("entered");
-       recordPtr = NULL;
-       NFCUtil util;
-       int result = nfc_ndef_message_create(&handle);
-
-       if (result != NFC_ERROR_NONE) {
-               handle = NULL;
-               util.throwNFCException(result, "Can't create Ndef Message");
-       }
-}
-
-NdefMessage::NdefMessage(void *messageHandle)
-{
-       LoggerD("entered");
-       recordPtr = NULL;
-       if (messageHandle == NULL) {
-               handle = NULL;
-               ThrowMsg(UnknownException, "Message Handler is Null Pointer.");
-       }
-
-       handle = static_cast<nfc_ndef_message_h>(messageHandle);
-}
-
-NdefMessage::NdefMessage(std::vector<void *> &ndefRcords)
-{
-       LoggerD("entered");
-       recordPtr = NULL;
-       handle = NULL;
-       handle = static_cast<nfc_ndef_message_h>(makeMessage(ndefRcords));
-}
-
-NdefMessage::NdefMessage(const std::vector<unsigned char> &rawdata)
-{
-       LoggerD("entered");
-       recordPtr = NULL;
-       handle = static_cast<nfc_ndef_message_h>(makeMessage(rawdata));
 }
 
 NdefMessage::~NdefMessage()
 {
-       LoggerD("entered"<<recordPtr);
-       if (handle != NULL)
-               nfc_ndef_message_destroy(handle);
+       LoggerD("entered");
 }
 
-void *NdefMessage::makeMessage(std::vector<void *> &ndefRcords) {
+void *NdefMessage::makeNdefMessageHandle(std::vector<void *> &ndefRcords) {
        NFCUtil util;
-       nfc_ndef_message_h message;
+       if (ndefRcords.size() == 0)
+               return NULL;
+
+       nfc_ndef_message_h message = NULL;
        int result = nfc_ndef_message_create(&message);
 
        if (result != NFC_ERROR_NONE) {
+               LoggerE(util.getNFCErrorMessage(result));
+               if (message)
+                       nfc_ndef_message_destroy(message);
                util.throwNFCException(result, "Can't create Ndef Message");
        }
 
        for (int i = 0 ; i < static_cast<int>(ndefRcords.size()); i++) {
-               nfc_ndef_record_h insertRecord;
-
-               if (!util.copyNDEFRecord(&ndefRcords[i], (void **)(&insertRecord))) {
-                       LoggerD("copyNDEFRecord fail!");
-                       ThrowMsg(UnknownException, "Can't copy Record");
-               }
-
-               result = nfc_ndef_message_append_record(message, insertRecord);
+               if ((message == NULL) && (ndefRcords[i] != NULL))
+                       nfc_ndef_record_destroy((nfc_ndef_record_h)ndefRcords[i]);
+               result = nfc_ndef_message_append_record(message, (nfc_ndef_record_h)ndefRcords[i]);
 
                if (result != NFC_ERROR_NONE) {
-                       LoggerE(i << " record can't be inserted. " << insertRecord << " : " << message);
-                       nfc_ndef_message_destroy(message);
-                       util.throwNFCException(result, "Can't insert record in Ndef Message");
+                       LoggerE(i << " record can't be inserted. " << ndefRcords[i] << " : " << message);
+                       if (message)
+                               nfc_ndef_message_destroy(message);
+                       message = NULL;
                }
        }
-       return (void*)message;
+
+       return (void *)message;
 }
 
-void *NdefMessage::makeMessage(const std::vector<unsigned char> &rawdata) {
+std::vector<unsigned char> NdefMessage::toByte(std::vector<void *> &ndefRcords) {
        NFCUtil util;
-       unsigned char *messageRawdata = util.toCharPtr(rawdata);
-       nfc_ndef_message_h message;
-       int result = nfc_ndef_message_create_from_rawdata(&message, messageRawdata, rawdata.size());
-
-       if (result != NFC_ERROR_NONE) {
-               handle = NULL;
-               if (messageRawdata)
-                       free(messageRawdata);
-               util.throwNFCException(result, "Can't create Ndef Message");
-       }
-       if (messageRawdata)
-               free(messageRawdata);
-
-       return (void*)message;
-}
+       if (ndefRcords.size() == 0)
+               return util.toVector(NULL, 0);
 
-void NdefMessage::setRecordesPtr(void *records) {
-       LoggerD("entered"<<records);
-       recordPtr = records;
-}
+       nfc_ndef_message_h message = (nfc_ndef_message_h)makeNdefMessageHandle(ndefRcords);
+       if (message == NULL)
+               ThrowMsg(ConversionException, "Invalid NDEF Message");
+       unsigned char *rawdata = NULL;
+       int size = 0;
+       int result = nfc_ndef_message_get_rawdata(message, &rawdata, &size);
 
-void* NdefMessage::getRecordesPtr() {
-       LoggerD("entered"<<recordPtr);
-       
-       return recordPtr;
-}
+       std::vector<unsigned char> byteData = util.toVector(rawdata, size);
 
-long NdefMessage::getRecordCount() {
-       int count;
-       int result = nfc_ndef_message_get_record_count(handle, &count);
+       if (message)
+               nfc_ndef_message_destroy(message);
+       if (rawdata)
+               free(rawdata);
 
-       NFCUtil util;
        if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get Record Count");
+               util.throwNFCException(result, "Can't get serial bytes of NDEF message");
 
-       LoggerD("record Count : " << count);
-       return static_cast<long>(count);
+       return byteData;
 }
 
-std::vector<unsigned char> NdefMessage::toByte() {
-       unsigned char *rawdata = NULL;
-       int size;
+std::vector<NdefRecordData> NdefMessage::toNDEFRecords(const std::vector<unsigned char> &rawdata) {
+       LoggerD("entered");
        NFCUtil util;
+       unsigned char *messageRawdata = util.toCharPtr(rawdata);
+       nfc_ndef_message_h message = NULL;
 
-       if (getRecordCount() == 0)
-               return util.toVector(NULL, 0);
+       try {
+               int result = nfc_ndef_message_create_from_rawdata(&message, messageRawdata, rawdata.size());
+               if (messageRawdata)
+                       free(messageRawdata);
 
-       int result = nfc_ndef_message_get_rawdata(handle, &rawdata, &size);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, "Can't create Ndef Message");
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
 
-       if (result != NFC_ERROR_NONE) {
-               if (rawdata)
-                       free(rawdata);
-               util.throwNFCException(result, "Can't get serial bytes of NDEF message");
+       return toNDEFRecords((void *)message);
+}
+
+std::vector<NdefRecordData> NdefMessage::toNDEFRecords(void *message) {
+       LoggerD("entered");
+       NFCUtil util;
+       std::vector<NdefRecordData> records;
+
+       if (message == NULL)
+               return records;
+
+       try {
+               int count = 0;
+               int result = nfc_ndef_message_get_record_count((nfc_ndef_message_h)message, &count);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, "Can't get a record count of message");
+               for (int i=0; i<count; i++) {
+                       NdefRecordData record;
+                       try {
+                               record = _getNDEFRecord((nfc_ndef_message_h)message, i);
+                       } catch(const WrtDeviceApis::Commons::Exception& err) {
+                               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+                       }
+                       records.push_back(record);
+               }
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
        }
 
-       std::vector<unsigned char> byteData = util.toVector(rawdata, size);
-       if (rawdata)
-               free(rawdata);
 
-       return byteData;
+       if (message)
+               nfc_ndef_message_destroy((nfc_ndef_message_h)message);
+       message = NULL;
+
+       return records;
 }
 
-NdefRecordData NdefMessage::getNDEFRecord(const long index) {
+
+NdefRecordData NdefMessage::_getNDEFRecord(nfc_ndef_message_h handle, const long index) {
        nfc_ndef_record_h recordHandle;
        int result = nfc_ndef_message_get_record(handle, static_cast<int>(index), &recordHandle);
 
@@ -177,6 +159,5 @@ NdefRecordData NdefMessage::getNDEFRecord(const long index) {
        return util.getNDEFRecordData(recordHandle);
 }
 
-
 }
 }
index 92ebbf7..765e4c2 100755 (executable)
@@ -33,22 +33,14 @@ class NdefMessage : public INdefMessage
        friend class  NFCFactory;
     public:
                NdefMessage();
-               NdefMessage(void *messageHandle);
-               NdefMessage(std::vector<void *> &ndefRcords);
-               NdefMessage(const std::vector<unsigned char> &rawdata);
        virtual  ~NdefMessage();
 
-       virtual std::vector<unsigned char> toByte();
-       virtual long getRecordCount();
-       virtual NdefRecordData getNDEFRecord(const long index);
-
-       virtual void *makeMessage(std::vector<void *> &ndefRcords);
-       virtual void *makeMessage(const std::vector<unsigned char> &rawdata);
-       virtual void setRecordesPtr(void *records);
-       virtual void* getRecordesPtr();
-    private:
-       nfc_ndef_message_h handle;
-       void *recordPtr;
+       virtual std::vector<unsigned char> toByte(std::vector<void *> &ndefRcords);
+       virtual void *makeNdefMessageHandle(std::vector<void *> &ndefRcords);
+       virtual std::vector<NdefRecordData> toNDEFRecords(const std::vector<unsigned char> &rawdata);
+       virtual std::vector<NdefRecordData> toNDEFRecords(void *message);
+       private:
+               NdefRecordData _getNDEFRecord(nfc_ndef_message_h handle, const long index);
 };
 
 }
index 23a6fc6..802b0e0 100755 (executable)
@@ -15,7 +15,6 @@
 // limitations under the License.
 //
 
-#include <Commons/Exception.h>
 #include "NdefRecord.h"
 #include "NFCUtil.h"
 #include <Logger.h>
@@ -25,292 +24,79 @@ namespace NFC {
 
 using namespace WrtDeviceApis::Commons;
 
-NdefRecord::NdefRecord()
-{
-       handle = NULL;
-}
+NdefRecord::NdefRecord() : validStatus(INVALID_STATE) {}
 
-NdefRecord::NdefRecord(std::vector<unsigned char> data)
+NdefRecord::NdefRecord(std::vector<unsigned char> data) : validStatus(UNKNOWN_STATE)
 {
        LoggerD("entered");
 
-       nfc_ndef_message_h messageHandle;
+       nfc_ndef_message_h messageHandle = NULL;
+
        NFCUtil util;
        unsigned char *rawdata = util.toCharPtr(data);
-       int result = nfc_ndef_message_create_from_rawdata(&messageHandle, rawdata, data.size());
-
-       if (result != NFC_ERROR_NONE) {
-               if (messageHandle)
-                       nfc_ndef_message_destroy(messageHandle);
-
-               messageHandle = NULL;
-               if (rawdata)
-                       free(rawdata);
-               rawdata = NULL;
-               util.throwNFCException(result, "Can't create Ndef Record");
-       }
-
-       int count;
-       result = nfc_ndef_message_get_record_count(messageHandle, &count);
-       if ((result != NFC_ERROR_NONE) || (count != 1)) {
-               nfc_ndef_message_destroy(messageHandle);
-               messageHandle = NULL;
-               if (rawdata)
-                       free(rawdata);
-               rawdata = NULL;
-               util.throwNFCException(result, "Can't create Ndef Record");
+       try {
+               int result = nfc_ndef_message_create_from_rawdata(&messageHandle, rawdata, data.size());
+
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, "Can't create Ndef Message from data");
+
+               int count;
+               result = nfc_ndef_message_get_record_count(messageHandle, &count);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, "Can't get record count");
+
+               nfc_ndef_record_h recordHandle = NULL;
+               result = nfc_ndef_message_get_record(messageHandle, 0, &recordHandle);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, "Can't get Ndef Record");
+
+               ndefRecordData = util.getNDEFRecordData((void *)recordHandle);
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
        }
 
-       nfc_ndef_record_h recordHandle;
-       result = nfc_ndef_message_get_record(messageHandle, 0, &recordHandle);
-       if (result != NFC_ERROR_NONE) {
+       if (messageHandle)
                nfc_ndef_message_destroy(messageHandle);
-               messageHandle = NULL;
-               if (rawdata)
-                       free(rawdata);
-               rawdata = NULL;
-               util.throwNFCException(result, "Can't create Ndef Record");
-       }
+       messageHandle = NULL;
 
-       if (!util.copyNDEFRecord((void **)&recordHandle, (void **)&handle)) {
-               nfc_ndef_message_destroy(messageHandle);
-               if (rawdata)
-                       free(rawdata);
-               ThrowMsg(UnknownException, "Can't copy Ndef Record");
-       }
-
-       nfc_ndef_message_destroy(messageHandle);
        if (rawdata)
                free(rawdata);
+       rawdata = NULL;
 }
 
-NdefRecord::NdefRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload)
-{
-       LoggerD("entered");
-
-       NFCUtil util;
-
-       unsigned char * recordPayload = util.toCharPtr(payload);
-       unsigned int payloadSize = payload.size();
-       unsigned char * typeName = util.toCharPtr(ndefRecordProperties.typeName);
-       int typeSize = (static_cast<int>(ndefRecordProperties.typeName.size()) > 255) ? 255 : static_cast<int>(ndefRecordProperties.typeName.size());
-       unsigned char * id = util.toCharPtr(ndefRecordProperties.id);
-       int idSize = (static_cast<int>(ndefRecordProperties.id.size()) > 255) ? 255 : static_cast<int>(ndefRecordProperties.id.size());
-
-       int result = nfc_ndef_record_create(&handle, static_cast<nfc_record_tnf_e>(util.convertToTNF(ndefRecordProperties.tnf)), typeName, typeSize,
-               id, idSize, recordPayload, payloadSize) ;
-       if (recordPayload)
-               free(recordPayload);
-       if (typeName)
-               free(typeName);
-       if (id)
-               free(id);
-
-       if (result != NFC_ERROR_NONE) {
-               handle = NULL;
-               util.throwNFCException(result, "Can't create Ndef Record");
-       }
-}
-
-NdefRecord::NdefRecord(const std::string &text, const std::string &langCode, const short encodeType)
+NdefRecord::NdefRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload, bool isValid) : validStatus(UNKNOWN_STATE)
 {
        LoggerD("entered");
 
-       int result = nfc_ndef_record_create_text(&handle, text.c_str(), langCode.c_str(), _convertToEncodeType(static_cast<nfcTextEncodeUTF>(encodeType)));
+       ndefRecordData.properties = ndefRecordProperties;
+       ndefRecordData.payload = payload;
 
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE) {
-               handle = NULL;
-               util.throwNFCException(result, "Can't create Ndef Text Record");
-       }
-}
-
-NdefRecord::NdefRecord(const std::string &uri)
-{
-       LoggerD("entered");
-
-       int result = nfc_ndef_record_create_uri(&handle, uri.c_str());
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE) {
-               handle = NULL;
-               util.throwNFCException(result, "Can't create Ndef Uri Record");
-       }
-}
-
-NdefRecord::NdefRecord(const std::string &mimeType, const std::vector<unsigned char> data)
-{
-       LoggerD("entered");
-
-       NFCUtil util;
-
-       unsigned char *mimeData = util.toCharPtr(data);
-       int result = nfc_ndef_record_create_mime(&handle, mimeType.c_str(), mimeData, static_cast<int>(data.size()));
-
-       if (mimeData)
-               free(mimeData);
-
-       if (result != NFC_ERROR_NONE) {
-               handle = NULL;
-               util.throwNFCException(result, "Can't create Ndef Mime Record");
-       }
+       if (!isValid)
+               validStatus = INVALID_STATE;
 }
 
 NdefRecord::~NdefRecord()
 {
        LoggerD("entered");
-       if (handle != NULL)
-               nfc_ndef_record_destroy(handle);
-}
-
-nfc_encode_type_e NdefRecord::_convertToEncodeType(const nfcTextEncodeUTF type) {
-       switch(type) {
-               case NFC_TEXT_ENCODE_UTF_8:
-                       return NFC_ENCODE_UTF_8;
-               case NFC_TEXT_ENCODE_UTF_16:
-                       return NFC_ENCODE_UTF_16;
-       }
-}
-
-nfcTextEncodeUTF NdefRecord::_convertToNfcEncodeType(const nfc_encode_type_e type) {
-       switch(type) {
-               case NFC_ENCODE_UTF_8:
-                       return NFC_TEXT_ENCODE_UTF_8;
-               case NFC_ENCODE_UTF_16:
-                       return NFC_TEXT_ENCODE_UTF_16;
-       }
 }
 
 void *NdefRecord::getHandle() {
-       return (void *)handle;
-}
-
-NdefRecordProperties NdefRecord::getNDEFRecordProperties() {
-       LoggerD("entered");
-       NdefRecordProperties props;
+       if (validStatus == INVALID_STATE)
+               return NULL;
        NFCUtil util;
 
-       props.tnf = getTNF();
-       props.typeName = getTypeName();
-       props.id = getID();
-
-       return props;
-}
-
-nfcTNF NdefRecord::getTNF() {
-       nfc_record_tnf_e tnf;
-       int result = nfc_ndef_record_get_tnf(handle, &tnf);
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get record's tnf");
-
-       return util.convertTonfcTNF(static_cast<unsigned short>(tnf));
-}
-
-std::vector<unsigned char> NdefRecord::getTypeName() {
-       unsigned char *typeName;
-       int typeSize;
-       int result = nfc_ndef_record_get_type(handle, &typeName, &typeSize);
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get record's type");
-
-       return util.toVector(typeName, typeSize);
-}
-
-std::vector<unsigned char> NdefRecord::getID() {
-       unsigned char *id;
-       int idSize;
-       int result = nfc_ndef_record_get_id(handle, &id, &idSize);
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get record's id");
-
-       return util.toVector(id, idSize);
-}
-
-bool NdefRecord::getText(char **text) {
-       LoggerD("entered");
-
-       int result = nfc_ndef_record_get_text(handle, text);
-       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
-               return false;
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get text of record");
-
-       return true;
-}
-
-bool NdefRecord::getLangCode(char **langCode) {
-       LoggerD("entered");
-
-       int result = nfc_ndef_record_get_langcode(handle, langCode);
-       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
-               return false;
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get langcode of record");
-
-       return true;
-}
-bool NdefRecord::getEncodeType(nfcTextEncodeUTF *encodeType) {
-       LoggerD("entered");
-
-       nfc_encode_type_e type;
-       int result = nfc_ndef_record_get_encode_type(handle, &type);
-       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
-               return false;
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get encode type of record");
-
-       *encodeType = _convertToNfcEncodeType(type);
-       return true;
-}
-
-bool NdefRecord::getUri(char **uri) {
-       LoggerD("entered");
-       int result = nfc_ndef_record_get_uri(handle, uri);
-       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
-               return false;
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get uri of record");
-
-       return true;
-}
-
-bool NdefRecord::getMimeType(char **mimeType) {
-       LoggerD("entered");
-       int result = nfc_ndef_record_get_mime_type(handle, mimeType);
-       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
-               return false;
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get mime type of record");
-
-       return true;
-}
-std::vector<unsigned char> NdefRecord::getPayload() {
-       LoggerD("entered");
-       int size;
-       unsigned char *recordbuffer;
-       int result = nfc_ndef_record_get_payload(handle, &recordbuffer, &size);
-
-       NFCUtil util;
-       if (result != NFC_ERROR_NONE)
-               util.throwNFCException(result, "Can't get record's payload");
-
-       return util.toVector(recordbuffer, size);
+       void *handle = NULL;
+       try {
+               handle = util.makeNDEFRecord(ndefRecordData.properties, ndefRecordData.payload);
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               handle = NULL;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
+       return handle;
 }
 
 }
index e7020e5..c1c93f1 100755 (executable)
@@ -23,8 +23,7 @@
 #include <vector>
 #include <nfc.h>
 #include "INdefRecord.h"
-
-
+#include "NFCFactory.h"
 
 namespace DeviceAPI {
 namespace NFC {
@@ -34,27 +33,16 @@ class NdefRecord : public INdefRecord
        friend class  NFCFactory;
     public:
                NdefRecord();
-               NdefRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+               NdefRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload, bool isValid = true);
                NdefRecord(std::vector<unsigned char> data);
-               NdefRecord(const std::string &text, const std::string &langCode, const short encodeType);
-               NdefRecord(const std::string &uri);
-               NdefRecord(const std::string &mimeType, const std::vector<unsigned char> data);
        virtual  ~NdefRecord();
        virtual void *getHandle();
-       virtual NdefRecordProperties getNDEFRecordProperties();
-       virtual nfcTNF getTNF();
-       virtual std::vector<unsigned char> getTypeName();
-       virtual std::vector<unsigned char> getID();
-       virtual std::vector<unsigned char> getPayload();
-       virtual bool getText(char **text);
-       virtual bool getLangCode(char **langCode);
-       virtual bool getEncodeType(nfcTextEncodeUTF *encodeType);
-       virtual bool getUri(char **uri);
-       virtual bool getMimeType(char **mimeType);
-    private:
-       nfc_ndef_record_h handle;
-       nfc_encode_type_e _convertToEncodeType(const nfcTextEncodeUTF type);
-       nfcTextEncodeUTF _convertToNfcEncodeType(const nfc_encode_type_e type);
+       virtual NdefRecordData getNDEFRecordData() {return ndefRecordData;}
+
+       protected:
+               NdefRecordData ndefRecordData;
+               ndefStatus validStatus;
+
 };
 
 }
diff --git a/src/NFC/NdefRecordMedia.cpp b/src/NFC/NdefRecordMedia.cpp
new file mode 100755 (executable)
index 0000000..386fc78
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <Commons/Exception.h>
+#include "NdefRecordMedia.h"
+#include "NFCUtil.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace NFC {
+
+using namespace WrtDeviceApis::Commons;
+
+NdefRecordMedia::NdefRecordMedia(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload)
+{
+       LoggerD("entered");
+
+       ndefRecordData.properties = ndefRecordProperties;
+       ndefRecordData.payload = payload;
+
+       NFCUtil util;
+       nfc_ndef_record_h handle = NULL;
+       char *mime = NULL;
+       try {
+               handle = (nfc_ndef_record_h)util.makeNDEFRecord(ndefRecordProperties, payload);
+
+               int result = nfc_ndef_record_get_mime_type(handle, &mime);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, " Can't get mime type");
+               mimeType = mime;
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
+
+       if (mime)
+               free(mime);
+       mime = NULL;
+
+       if (handle)
+               nfc_ndef_record_destroy(handle);
+}
+
+NdefRecordMedia::NdefRecordMedia(const std::string &mimeType, const std::vector<unsigned char> data, bool isValid)
+{
+       LoggerD("entered");
+
+       this->mimeType = mimeType;
+
+       if (!isValid) {
+               validStatus = INVALID_STATE;
+               return;
+       }
+
+       NFCUtil util;
+       nfc_ndef_record_h handle = NULL;
+       unsigned char *mimeData = util.toCharPtr(data);
+       try {
+               int result = nfc_ndef_record_create_mime(&handle, mimeType.c_str(), mimeData, static_cast<int>(data.size()));
+
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, "Can't create Ndef Mime Record");
+
+               ndefRecordData = util.getNDEFRecordData(handle);
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
+
+       if (mimeData)
+               free(mimeData);
+       if (handle)
+               nfc_ndef_record_destroy(handle);
+}
+
+NdefRecordMedia::~NdefRecordMedia()
+{
+       LoggerD("entered");
+}
+
+}
+}
diff --git a/src/NFC/NdefRecordMedia.h b/src/NFC/NdefRecordMedia.h
new file mode 100755 (executable)
index 0000000..2e4e468
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+
+#ifndef _NDEFRECORDMEDIA_H_
+#define _NDEFRECORDMEDIA_H_
+
+#include "NdefRecord.h"
+#include <string>
+
+
+namespace DeviceAPI {
+namespace NFC {
+
+class NdefRecordMedia : public NdefRecord
+{
+       friend class  NFCFactory;
+    public:
+               NdefRecordMedia(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+               NdefRecordMedia(const std::string &mimeType, const std::vector<unsigned char> data, bool isValid = true);
+       virtual  ~NdefRecordMedia();
+       virtual std::string getMimeType() {return mimeType;}
+       protected:
+               std::string mimeType;
+};
+
+}
+}
+
+#endif /* _NDEFRECORDMEDIA_H_ */
index 63bf732..2021617 100755 (executable)
@@ -40,13 +40,20 @@ enum nfcTextEncodeUTF {
        NFC_TEXT_ENCODE_UTF_8 = 0,
        NFC_TEXT_ENCODE_UTF_16 = 1
 };
+
+enum ndefStatus {
+       UNKNOWN_STATE,
+       VALID_STATE,
+       INVALID_STATE
+};
+
 struct NdefRecordProperties
 {
-       nfcTNF  tnf;
+       short tnf;
        std::vector<unsigned char> typeName ;
        std::vector<unsigned char> id ;
        NdefRecordProperties()
-               : tnf(NFC_TNF_EMPTY)
+               : tnf(NFC_TNF_UNKNOWN)
        {
        }
 };
@@ -58,7 +65,7 @@ struct NdefRecordData
        NdefRecordData() {}
 };
 
-typedef DPL::SharedPtr<NdefRecordProperties> NdefRecordPropertiesPtr;
+//typedef DPL::SharedPtr<NdefRecordProperties> NdefRecordPropertiesPtr;
 
 } // NFC
 } // DeviceAPI
diff --git a/src/NFC/NdefRecordText.cpp b/src/NFC/NdefRecordText.cpp
new file mode 100755 (executable)
index 0000000..3615afe
--- /dev/null
@@ -0,0 +1,132 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <Commons/Exception.h>
+#include "NdefRecordText.h"
+#include "NFCUtil.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace NFC {
+
+using namespace WrtDeviceApis::Commons;
+
+NdefRecordText::NdefRecordText(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload)
+{
+       LoggerD("entered");
+
+       ndefRecordData.properties = ndefRecordProperties;
+       ndefRecordData.payload = payload;
+
+       NFCUtil util;
+       nfc_ndef_record_h handle = NULL;
+       char *recordText = NULL;
+       char *recordLang = NULL;
+       try {
+               handle = (nfc_ndef_record_h)util.makeNDEFRecord(ndefRecordProperties, payload);
+
+               int result = nfc_ndef_record_get_text(handle, &recordText);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, " Can't get text");
+               text = std::string(recordText);
+
+               result = nfc_ndef_record_get_langcode(handle, &recordLang);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, " Can't get languageCode");
+               languageCode = std::string(recordLang);
+
+               nfc_encode_type_e type;
+               result = nfc_ndef_record_get_encode_type(handle, &type);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, " Can't get encoding");
+
+               encoding = _convertToNfcEncodeType(type);
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               encoding = NFC_TEXT_ENCODE_UTF_8;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
+
+       if (recordText)
+               free(recordText);
+
+       if (recordLang)
+               free(recordLang);
+
+       if (handle)
+               nfc_ndef_record_destroy(handle);
+}
+
+NdefRecordText::NdefRecordText(const std::string &text, const std::string &langCode, const nfcTextEncodeUTF encodeType, bool isValid)
+{
+       LoggerD("entered");
+       this->text = text;
+       languageCode = langCode;
+       encoding = encodeType;
+
+       if (!isValid) {
+               validStatus = INVALID_STATE;
+               return;
+       }
+
+       nfc_ndef_record_h handle = NULL;
+       try {
+               int result = nfc_ndef_record_create_text(&handle, text.c_str(), langCode.c_str(), _convertToEncodeType(encodeType));
+
+               NFCUtil util;
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, "Can't create Ndef Text Record");
+
+               ndefRecordData = util.getNDEFRecordData(handle);
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
+       if (handle)
+               nfc_ndef_record_destroy(handle);
+}
+
+NdefRecordText::~NdefRecordText()
+{
+       LoggerD("entered");
+
+}
+
+nfc_encode_type_e NdefRecordText::_convertToEncodeType(const nfcTextEncodeUTF &type) {
+       switch(type) {
+               case NFC_TEXT_ENCODE_UTF_16:
+                       return NFC_ENCODE_UTF_16;
+               case NFC_TEXT_ENCODE_UTF_8:
+                       return NFC_ENCODE_UTF_8;
+       }
+}
+
+nfcTextEncodeUTF NdefRecordText::_convertToNfcEncodeType(const nfc_encode_type_e type) {
+       switch(type) {
+               case NFC_ENCODE_UTF_16:
+                       return NFC_TEXT_ENCODE_UTF_16;
+               case NFC_ENCODE_UTF_8:
+               default:
+                       return NFC_TEXT_ENCODE_UTF_8;
+       }
+}
+
+
+}
+}
diff --git a/src/NFC/NdefRecordText.h b/src/NFC/NdefRecordText.h
new file mode 100755 (executable)
index 0000000..70b1612
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+
+#ifndef _NDEFRECORDTEXT_H_
+#define _NDEFRECORDTEXT_H_
+
+#include "NdefRecord.h"
+
+namespace DeviceAPI {
+namespace NFC {
+
+class NdefRecordText : public NdefRecord
+{
+       friend class  NFCFactory;
+    public:
+               NdefRecordText(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+               NdefRecordText(const std::string &text, const std::string &langCode, const nfcTextEncodeUTF encodeType, bool isValid=true);
+       virtual  ~NdefRecordText();
+       virtual std::string getText() {return text;}
+       virtual std::string getLanguageCode() {return languageCode;}
+       virtual nfcTextEncodeUTF getEncoding() {return encoding;}
+    private:
+       std::string text;
+       std::string languageCode;
+       nfcTextEncodeUTF encoding;
+
+       nfc_encode_type_e _convertToEncodeType(const nfcTextEncodeUTF &type);
+       nfcTextEncodeUTF _convertToNfcEncodeType(const nfc_encode_type_e type);
+};
+
+}
+}
+
+#endif /* _NDEFRECORDTEXT_H_ */
diff --git a/src/NFC/NdefRecordURI.cpp b/src/NFC/NdefRecordURI.cpp
new file mode 100755 (executable)
index 0000000..7e7d687
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <Commons/Exception.h>
+#include "NdefRecordURI.h"
+#include "NFCUtil.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace NFC {
+
+using namespace WrtDeviceApis::Commons;
+
+NdefRecordUri::NdefRecordUri(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload)
+{
+       LoggerD("entered");
+
+       ndefRecordData.properties = ndefRecordProperties;
+       ndefRecordData.payload = payload;
+
+       NFCUtil util;
+       nfc_ndef_record_h handle = NULL;
+       char *recordUri = NULL;
+       try {
+               handle = (nfc_ndef_record_h)util.makeNDEFRecord(ndefRecordProperties, payload);
+
+               int result = nfc_ndef_record_get_uri(handle, &recordUri);
+               if (result != NFC_ERROR_NONE)
+                       util.throwNFCException(result, " Can't get uri");
+               uri = std::string(recordUri);
+
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
+       if (recordUri)
+               free(recordUri);
+
+       if (handle)
+               nfc_ndef_record_destroy(handle);
+}
+
+NdefRecordUri::NdefRecordUri(const std::string &uri, bool isValid)
+{
+       LoggerD("entered");
+
+       this->uri = uri;
+
+       if (!isValid) {
+               validStatus = INVALID_STATE;
+               return;
+       }
+
+       nfc_ndef_record_h handle = NULL;
+       try {
+               int result = nfc_ndef_record_create_uri(&handle, uri.c_str());
+
+               NFCUtil util;
+               if (result != NFC_ERROR_NONE) {
+                       util.throwNFCException(result, "Can't create Ndef Uri Record");
+               }
+               ndefRecordData = util.getNDEFRecordData(handle);
+               validStatus = VALID_STATE;
+       } catch (const WrtDeviceApis::Commons::Exception& err) {
+               validStatus = INVALID_STATE;
+               LoggerE(err.GetClassName() << ":"<<err.GetMessage());
+       }
+       if (handle)
+               nfc_ndef_record_destroy(handle);
+}
+
+NdefRecordUri::~NdefRecordUri()
+{
+       LoggerD("entered");
+}
+
+}
+}
diff --git a/src/NFC/NdefRecordURI.h b/src/NFC/NdefRecordURI.h
new file mode 100755 (executable)
index 0000000..1e062db
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+
+#ifndef _NDEFRECORDURI_H_
+#define _NDEFRECORDURI_H_
+
+#include "NdefRecord.h"
+
+
+
+namespace DeviceAPI {
+namespace NFC {
+
+
+class NdefRecordUri : public NdefRecord
+{
+       friend class  NFCFactory;
+    public:
+               NdefRecordUri(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+               NdefRecordUri(const std::string &uri, bool isValid = true);
+       virtual  ~NdefRecordUri();
+       virtual std::string getUri( ) {return uri;}
+    private:
+               std::string uri;
+
+};
+
+}
+}
+
+#endif /* _NDEFRECORDURI_H_ */
old mode 100644 (file)
new mode 100755 (executable)
index 2230cfd..cd1c8c1 100755 (executable)
@@ -170,6 +170,11 @@ void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerSelection
         return;
     }
     connection_profile_get_name(m_profileHandle, &defaultProfileName);    
+    if (defaultProfileName == NULL) {
+        LoggerE("default profile is not exist.");
+        makeRequestCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
+        return;
+    }
 
     if (connection_get_current_profile(m_connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
         LoggerD("Fail to get current profile handle");
@@ -177,6 +182,11 @@ void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerSelection
         return;
     }
     connection_profile_get_name(profileHandle, &currentProfileName);
+    if (currentProfileName == NULL) {
+        LoggerE("current profile is not exist.");
+        makeRequestCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
+        return;        
+    }    
 
     if (strcmp(defaultProfileName, currentProfileName) != 0) {
         NewtorkBearerSelectionPendingEvent *pendingEvent = new NewtorkBearerSelectionPendingEvent((void *)this, event);
@@ -193,14 +203,9 @@ void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerSelection
         registStateChangeListener(event);
     }
 
-    if(defaultProfileName != NULL) {
         free(defaultProfileName);
-    }
-
-    if(currentProfileName != NULL) {
         free(currentProfileName);
     }
-}
 
 void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerReleasePtr &event)
 {
@@ -227,9 +232,8 @@ void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerReleasePt
                     return;
                 }        
                 
-                NewtorkBearerReleasePendingEvent *pendingEvent = new NewtorkBearerReleasePendingEvent((void *)this, event);
-
                 if (m_isConnectionOpen) {
+                NewtorkBearerReleasePendingEvent *pendingEvent = new NewtorkBearerReleasePendingEvent((void *)this, event);
                     if (connection_close_profile(m_connectionHandle, m_profileHandle, connection_closed_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
                         LoggerD("connection close failed");
                         delete pendingEvent;
@@ -274,7 +278,6 @@ void NetworkBearerSelection::registStateChangeListener(const EventNetworkBearerS
     if(!host_entry) {
         LoggerD("gethostbyname is failed");
         makeRequestCallback(event, CONNECTION_STATE_INVALID_VALUES_ERROR);
-
         if (connection_close_profile(m_connectionHandle, m_profileHandle, connection_closed_callback2, NULL) != CONNECTION_ERROR_NONE) {
             LoggerD("connection close failed");
             makeRequestCallback(event, CONNECTION_STATE_PLATFORM_ERROR);
index 471351a..eefb695 100755 (executable)
@@ -64,6 +64,7 @@ JSStaticValue JSStatusNotification::m_property[] =
        {STATUS_NOTIFICATION_LIGHT_ONTIME, JSStatusNotification::getProperty, JSStatusNotification::setProperty,        kJSPropertyAttributeNone },
        {STATUS_NOTIFICATION_LIGHT_OFFTIME,  JSStatusNotification::getProperty, JSStatusNotification::setProperty,      kJSPropertyAttributeNone },
        {STATUS_NOTIFICATION_VIBRATION,  JSStatusNotification::getProperty, JSStatusNotification::setProperty,  kJSPropertyAttributeNone },
+       {NOTIFICATION_TITLE,  JSStatusNotification::getProperty, JSStatusNotification::setProperty,     kJSPropertyAttributeNone },
        {0, 0, 0, 0}
 };
 
@@ -137,27 +138,24 @@ bool JSStatusNotification::setProperty(JSContextRef context,
                        unsigned long onPeriod = JSUtil::JSValueToULong(context, value);
                        LoggerI("       LEDonPeriod = " << onPeriod);
                        priv->setLightOnTime(onPeriod);
-
-                       // JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_ONTIME,
-                       //      JSUtil::toJSValueRef(context, onPeriod), kJSPropertyAttributeNone);
                   }
                   else if ( property == STATUS_NOTIFICATION_LIGHT_OFFTIME)
                   {
                        unsigned long offPeriod = JSUtil::JSValueToULong(context, value);
                        LoggerI("       LEDoffPeriod = " << offPeriod);
                        priv->setLightOffTime(offPeriod);
-
-                       // JSUtil::setProperty(context, object, STATUS_NOTIFICATION_LIGHT_OFFTIME,
-                       //      JSUtil::toJSValueRef(context, offPeriod), kJSPropertyAttributeNone);
                   }
                   else if ( property == STATUS_NOTIFICATION_VIBRATION)
                   {
                        bool vibration = JSUtil::JSValueToBoolean(context, value);
                        LoggerI("       vibration = " << vibration);
                        priv->setDefaultVibration(vibration);
-
-                       // JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
-                       //      JSUtil::toJSValueRef(context, vibration), kJSPropertyAttributeNone);
+                  }
+                  else if ( property == NOTIFICATION_TITLE)
+                  {
+                       std::string title = JSUtil::JSValueToString(context, value);
+                       LoggerI("       title = " << title);
+                       priv->setTitle(title);
                   }
                   
     }
@@ -254,6 +252,11 @@ JSValueRef JSStatusNotification::getProperty(JSContextRef context,
                        bool vibration = priv->getDefaultVibration();
                        return  JSUtil::toJSValueRef(context, vibration);
                   }
+                  else if ( property == NOTIFICATION_TITLE)
+                  {
+                       std::string title = priv->getTitle();
+                       return  JSUtil::toJSValueRef(context, title);
+                  }
     }
     catch ( const BasePlatformException& err) 
     {
index 903179b..a6bb992 100755 (executable)
 #include <CommonsJavaScript/Converter.h>
 #include <Commons/Exception.h>
 #include <CommonsJavaScript/PrivateObject.h>
-#include <CommonsJavaScript/JSUtils.h>
 #include <CommonsJavaScript/JSCallbackManager.h>
 #include <CommonsJavaScript/Utils.h>
 #include <JSWebAPIErrorFactory.h>
 #include <SecurityExceptions.h>
 #include <ArgumentValidator.h>
+#include <JSUtil.h>
 #include "SEFactory.h"
 #include "SEResponseDispatcher.h"
 #include "JSSEService.h"
@@ -201,36 +201,34 @@ JSValueRef JSSEService::registerSEListener(JSContextRef context,
     AceSecurityStatus status = SECURE_ELEMENT_CHECK_ACCESS(SECUREELEMENT_FUNCTION_API_FUNCS);
     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-       Validator validator(context, exception);
+       SEListener seListener;
        try {
                ArgumentValidator argValidator(context, argumentCount, arguments);
-               if (!argValidator.toObject(0))
-                       throw TypeMismatchException("Parameter is not Object");
+               JSObjectRef listenerObj = argValidator.toCallbackObject(0, false, "onSEReady", "onSENotReady", NULL);
+               JSValueRef onSEReady = JSUtil::getProperty(context, listenerObj, "onSEReady", exception);
+               if (!JSValueIsUndefined(context, onSEReady))
+                       seListener.onSEReady = onSEReady;
+
+               JSValueRef onSENotReady = JSUtil::getProperty(context, listenerObj, "onSENotReady", exception);
+               if (!JSValueIsUndefined(context, onSENotReady))
+                       seListener.onSENotReady = onSENotReady;
        }catch(const BasePlatformException& err){
         return JSWebAPIErrorFactory::postException(context, exception, err);
     }
 
-       SEConverter convert(context);
-       SEListener seListener;
-       if (!validator.isCallback(arguments[0])) {
-               seListener = convert.toSEListener(arguments[0]);
-       } else {
-               /* 1st argument must be SEListener. */
-               LoggerE("SEListener must has onSEReady and onSENotReady");
-               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+       Try {
+               SEConverter convert(context);
 
+               SEServicePrivObject* privateObject = static_cast<SEServicePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (NULL == privateObject) {
+                       LoggerE("private object is null");
+                       return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               }
 
-       SEServicePrivObject* privateObject = static_cast<SEServicePrivObject*>(JSObjectGetPrivate(thisObject));
-       if (NULL == privateObject) {
-               LoggerE("private object is null");
-               return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
-       }
+               ISEServicePtr seService(privateObject->getObject());
+               JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), seListener.onSEReady, seListener.onSENotReady, true, true);
+               JSValueProtect(privateObject->getContext(), thisObject);    
 
-       ISEServicePtr seService(privateObject->getObject());
-       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), seListener.onSEReady, seListener.onSENotReady, true, true);
-       JSValueProtect(privateObject->getContext(), thisObject);    
-       Try {
                EventSEStateChangedEmitterPtr emitter(new EventSEStateChangedEmitter);
                emitter->setListener(&SEResponseDispatcher::getInstance());
                emitter->setEventPrivateData(DPL::StaticPointerCast<EventSEStateChanged::PrivateDataType>(callbackManager));
index b2211c8..ac355e1 100644 (file)
@@ -26,9 +26,6 @@ using namespace WrtDeviceApis::CommonsJavaScript;
 using namespace WrtDeviceApis;
 using namespace DeviceAPI::Common;
 
-#define SE_LISTENER_ONSEREADY "onSEReady"
-#define SE_LISTENER_ONSENOTREADY "onSENotReady"
-
 
 namespace DeviceAPI {
 namespace SecureElement {
@@ -61,35 +58,6 @@ JSValueRef SEConverter::toJSValueRef(const std::vector<unsigned char>& arg) {
     return jsResult;
 }
 
-SEListener SEConverter::toSEListener(const JSValueRef& arg) {
-       LoggerD("Entered");
-       JSObjectRef object = toJSObjectRef(arg);
-
-       SEListener result;
-       Validator validator(m_context);
-
-       result.onSEReady= JSUtils::getJSPropertyOrUndefined(
-       m_context, object, SE_LISTENER_ONSEREADY
-       );
-       if (!validator.isNullOrUndefined(result.onSEReady) &&
-       !validator.isCallback(result.onSEReady)) {
-       ThrowMsg(Commons::ConversionException, "Not a valid callback.");
-       }
-
-       result.onSENotReady= JSUtils::getJSPropertyOrUndefined(
-       m_context, object, SE_LISTENER_ONSENOTREADY
-       );
-       if (!validator.isNullOrUndefined(result.onSENotReady) &&
-       !validator.isCallback(result.onSENotReady)) {
-       ThrowMsg(Commons::ConversionException, "Not a valid callback.");
-       }
-
-       if (validator.isNullOrUndefined(result.onSEReady) && validator.isNullOrUndefined(result.onSENotReady))
-       ThrowMsg(Commons::ConversionException, "Not a valid callback.");
-
-       return result;
-}
-
 JSValueRef SEConverter::makeSeErrorObject(std::string error, std::string message) {
        return JSWebAPIErrorFactory::makeErrorObject(m_context, error, message);
 }
index 286f58e..2e4e41a 100755 (executable)
@@ -38,7 +38,6 @@ class SEConverter : public WrtDeviceApis::CommonsJavaScript::Converter
        virtual  ~SEConverter();
 
        JSValueRef toJSValueRef(const std::vector<unsigned char>& arg);
-       SEListener toSEListener(const JSValueRef& arg);
 
        JSValueRef makeSeErrorObject(std::string error, std::string message);
 };
index 69ee5cb..3a557e3 100755 (executable)
@@ -632,6 +632,12 @@ void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
                     simState = strdup("UNKNOWN");
                     break;
             }
+            if (simState == NULL) {
+                LoggerE("get fail sim state");
+                event->makeSimObject();
+                EventRequestReceiver<EventGetSysteminfo>::ManualAnswer(event);
+                return;
+            }
             event->setSimState(simState);
             if(strcmp(simState, "READY") == 0) {
                 if (tel_get_sim_imsi(m_tapiHandle, &imsi) == TAPI_API_SUCCESS) {
@@ -652,9 +658,7 @@ void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
                 event->makeSimObject();
                 EventRequestReceiver<EventGetSysteminfo>::ManualAnswer(event);
             }
-            if (simState) {
-                free(simState);
-            }
+            free(simState);
         } else {
             LoggerE("get fail sim state");
             event->makeSimObject();