# -----------------------------------------------------------------------------
# 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")
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
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 \
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;
}
}
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);
}
}
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 {
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)) {
}
}
-long DownloadManager::start(DownloadRequest *request, DownloadCallback *downloadCallback)
+long DownloadManager::start(DownloadRequest *request, DownloadCallback *downloadCallback, std::string& userAgent)
{
int ret;
int downloadId = 0;
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.");
}
}
}
+ // 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) {
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
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);
private:
typedef std::map<long, DownloadCallback*> DownloadCallbackMapT;
DownloadCallbackMapT mDownloadCallbacks;
+
+ std::map<std::string, std::string> getWebAppHttpHeader();
};
}
#include <JSUtil.h>
#include <ArgumentValidator.h>
#include <GlobalContextManager.h>
+#include <JSStringRefWrapper.h>
#include "plugin_config.h"
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,
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) {
NFCTag.cpp
NdefMessage.cpp
NdefRecord.cpp
+ NdefRecordText.cpp
+ NdefRecordURI.cpp
+ NdefRecordMedia.cpp
NFCTarget.cpp
NFCUtil.cpp
)
#include <vector>
#include "EventNFC.h"
#include <dpl/shared_ptr.h>
+#include <nfc.h>
namespace DeviceAPI {
namespace NFC {
void setNdefMessageHandle(void *handle) { messageHandle = handle; }
void *getNdefMessageHandle() { return messageHandle; }
public:
- EventTagAction() { }
+ EventTagAction() : messageHandle(NULL) { }
};
class EventTagActionRead : public EventNFCTemplate<EventTagActionRead>
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(){ }
#include <Commons/ListenerEvent.h>
#include <Commons/ListenerEventEmitter.h>
#include "EventNFC.h"
+#include <nfc.h>
namespace DeviceAPI {
namespace NFC {
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:
#include <dpl/shared_ptr.h>
#include <vector>
+#include <PropertyBag.h>
#include "NdefRecordProperties.h"
namespace DeviceAPI {
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;
#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");}
};
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());
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());
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());
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));
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());
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 {
finalize,
NULL, //hasProperty,
NULL,
- setProperty, //setProperty,
+ NULL, //setProperty,
NULL, //DeleteProperty,
NULL, //GetPropertyNames,
NULL, //CallAsFunction,
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)
{
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;
{
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;
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,
}
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());
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());
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");
#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 {
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);
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) {
{
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,
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) {
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);
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;
}
{
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,
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) {
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);
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;
}
{
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) {
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) {
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());
}
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);
#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>
}
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;
}
{
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) {
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());
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());
}
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);
#include <CommonsJavaScript/Validator.h>
#include <CommonsJavaScript/ScopedJSStringRef.h>
#include <CommonsJavaScript/JSUtils.h>
+#include <JSUtil.h>
#include "NFCFactory.h"
#include "NFCConverter.h"
#include "JSNdefRecord.h"
}
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()
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) {
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;
}
LoggerD("Entered");
if (!isNdefRecord(arg)) {
ThrowMsg(Commons::ConversionException,
- "Message is JS null or JS undefined.");
+ "Not record value");
}
JSObjectRef obj = toJSObjectRef(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) {
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();
#include "NFCAdapter.h"
#include "NdefMessage.h"
#include "NdefRecord.h"
+#include "NdefRecordMedia.h"
+#include "NdefRecordText.h"
+#include "NdefRecordURI.h"
#include "NFCTag.h"
#include "NFCTarget.h"
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) {
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);
{
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 {
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 {
}
}
-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);
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);
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:
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";
return "No NDEF Message";
case NFC_ERROR_NOT_NDEF_FORMAT:
return "Not NDEF Format";
+ case NFC_ERROR_SECURITY_RESTRICTED:
+ return "Security Restricted";
}
return "UnknownError";
}
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:
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);
};
}
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);
return util.getNDEFRecordData(recordHandle);
}
-
}
}
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);
};
}
// limitations under the License.
//
-#include <Commons/Exception.h>
#include "NdefRecord.h"
#include "NFCUtil.h"
#include <Logger.h>
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;
}
}
#include <vector>
#include <nfc.h>
#include "INdefRecord.h"
-
-
+#include "NFCFactory.h"
namespace DeviceAPI {
namespace NFC {
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;
+
};
}
--- /dev/null
+//
+// 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");
+}
+
+}
+}
--- /dev/null
+//
+// 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_ */
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)
{
}
};
NdefRecordData() {}
};
-typedef DPL::SharedPtr<NdefRecordProperties> NdefRecordPropertiesPtr;
+//typedef DPL::SharedPtr<NdefRecordProperties> NdefRecordPropertiesPtr;
} // NFC
} // DeviceAPI
--- /dev/null
+//
+// 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;
+ }
+}
+
+
+}
+}
--- /dev/null
+//
+// 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_ */
--- /dev/null
+//
+// 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");
+}
+
+}
+}
--- /dev/null
+//
+// 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_ */
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");
return;
}
connection_profile_get_name(profileHandle, ¤tProfileName);
+ 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);
registStateChangeListener(event);
}
- if(defaultProfileName != NULL) {
free(defaultProfileName);
- }
-
- if(currentProfileName != NULL) {
free(currentProfileName);
}
-}
void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerReleasePtr &event)
{
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;
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);
{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}
};
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);
}
}
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)
{
#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"
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));
using namespace WrtDeviceApis;
using namespace DeviceAPI::Common;
-#define SE_LISTENER_ONSEREADY "onSEReady"
-#define SE_LISTENER_ONSENOTREADY "onSENotReady"
-
namespace DeviceAPI {
namespace SecureElement {
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);
}
virtual ~SEConverter();
JSValueRef toJSValueRef(const std::vector<unsigned char>& arg);
- SEListener toSEListener(const JSValueRef& arg);
JSValueRef makeSeErrorObject(std::string error, std::string message);
};
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) {
event->makeSimObject();
EventRequestReceiver<EventGetSysteminfo>::ManualAnswer(event);
}
- if (simState) {
- free(simState);
- }
+ free(simState);
} else {
LoggerE("get fail sim state");
event->makeSimObject();