+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <dpl/log/log.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSNdefRecordArray.h"
+#include "JSNdefMessage.h"
+#include "NFCConverter.h"
+#include <API/NFC/NFCFactory.h>
+
+namespace {
+const char* FUNCTION_CONCAT = "concat";
+const char* FUNCTION_JOIN = "join";
+const char* FUNCTION_POP = "pop";
+const char* FUNCTION_PUSH = "push";
+const char* FUNCTION_REVERSE = "reverse";
+const char* FUNCTION_SHIFT = "shift";
+const char* FUNCTION_SLICE = "slice";
+const char* FUNCTION_SORT = "sort";
+const char* FUNCTION_SPLICE = "splice";
+const char* FUNCTION_TOSTRING = "toString";
+const char* FUNCTION_UNSHIFT = "unshift";
+const char* FUNCTION_VALUEOF = "valueOf";
+const char *ARRAY = "Array";
+const char *ATTRIBUTE_LENGTH = "length";
+}
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace TizenApis::Commons;
+using namespace Api::NFC;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSNdefRecordArray::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ ARRAY,
+ 0,
+ m_property,
+ m_function,
+ initialize,
+ finalize,
+ hasProperty,
+ getProperty,
+ setProperty,
+ NULL, //deleteProperty,
+ NULL, //getPropertyNames,
+ NULL, //callAsFunction,
+ NULL, //callAsConstructor,
+ NULL, //hasInstance,
+ NULL, //convertToType,
+};
+
+JSStaticValue JSNdefRecordArray::m_property[] = {
+ { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSNdefRecordArray::m_function[] = {
+ { FUNCTION_CONCAT, concat, kJSPropertyAttributeNone },
+ { FUNCTION_JOIN, join, kJSPropertyAttributeNone },
+ { FUNCTION_POP, pop, kJSPropertyAttributeNone },
+ { FUNCTION_PUSH, push, kJSPropertyAttributeNone },
+ { FUNCTION_REVERSE, reverse, kJSPropertyAttributeNone },
+ { FUNCTION_SHIFT, shift, kJSPropertyAttributeNone },
+ { FUNCTION_SLICE, slice, kJSPropertyAttributeNone },
+ { FUNCTION_SORT, sort, kJSPropertyAttributeNone },
+ { FUNCTION_SPLICE, splice, kJSPropertyAttributeNone },
+ { FUNCTION_TOSTRING, toString, kJSPropertyAttributeNone },
+ { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeNone },
+ { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+JSClassRef JSNdefRecordArray::m_jsClassRef = JSClassCreate(
+ JSNdefRecordArray::getClassInfo());
+
+JSValueRef JSNdefRecordArray::getLength(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ Throw(NullPointerException);
+ }
+ INdefMessagePtr privateDatas = priv->getObject();
+ if (privateDatas) {
+ Converter converter(context);
+ return converter.toJSValueRefLong(privateDatas->getRecordCount());
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("invalid conversion");
+ }
+ return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSNdefRecordArray::createArray(JSContextRef context,
+ const INdefMessagePtr &privateDatas)
+{
+ LogDebug("Enter");
+ NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, privateDatas);
+ return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSNdefRecordArray::getClassInfo()
+{
+ return &(m_classInfo);
+}
+
+JSClassRef JSNdefRecordArray::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+bool JSNdefRecordArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+ return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+INdefMessagePtr
+ JSNdefRecordArray::getNdefRecordArray(JSContextRef context, JSValueRef value)
+{
+ LogDebug("Enter");
+ if (!isObjectOfClass(context, value)) {
+ Throw(InvalidArgumentException);
+ }
+ JSObjectRef object = JSValueToObject(context, value, NULL);
+ if (!object) {
+ Throw(InvalidArgumentException);
+ }
+ NdefMessagePrivObject *priv = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ Throw(NullPointerException);
+ }
+ return priv->getObject();
+}
+
+void JSNdefRecordArray::initialize(JSContextRef context,
+ JSObjectRef object)
+{
+ LogDebug("Enter");
+}
+
+void JSNdefRecordArray::finalize(JSObjectRef object)
+{
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+ delete priv;
+ JSObjectSetPrivate(object, NULL);
+}
+
+bool JSNdefRecordArray::hasProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName)
+{
+ LogDebug("Enter");
+ Converter converter(context);
+ Try
+ {
+ size_t index = converter.toSizeT(propertyName);
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ Throw(NullPointerException);
+ }
+ INdefMessagePtr privateDatas = priv->getObject();
+ if (static_cast<long>(index) < privateDatas->getRecordCount()) {
+ return true;
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ //not reporting error is intended
+ }
+ return false;
+}
+
+JSValueRef JSNdefRecordArray::getProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+
+ Try
+ {
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ Throw(NullPointerException);
+ }
+
+ NFCConverter converter(priv->getContext());
+ size_t index = converter.toSizeT(propertyName);
+
+ INdefMessagePtr privateDatas = priv->getObject();
+ if (static_cast<long>(index) < privateDatas->getRecordCount()) {
+ NdefRecordData result = privateDatas->getNDEFRecord(index);
+ return converter.toJSValueRef(result);
+ }
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("invalid property");
+ }
+ return JSValueMakeUndefined(context);
+}
+
+bool JSNdefRecordArray::setProperty(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef propertyName,
+ JSValueRef value,
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ NFCConverter converter(context);
+ Try
+ {
+ size_t index = converter.toSizeT(propertyName);
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+ if (!priv) {
+ Throw(NullPointerException);
+ }
+ INdefMessagePtr privateDatas = priv->getObject();
+ if (!privateDatas) {
+ Throw(NullPointerException);
+ }
+ void *record = converter.getRecordHandle(value);
+ if (privateDatas->getRecordCount() == static_cast<long>(index)) {
+ privateDatas->appendNDEFRecord(record);
+ } else if (privateDatas->getRecordCount() > static_cast<long>(index)) {
+ privateDatas->removeNDEFRecord(static_cast<long>(index));
+ privateDatas->insertNDEFRecord(static_cast<long>(index), record);
+ } else
+ Throw(InvalidArgumentException);
+
+ return true;
+ } Catch (NullPointerException) {
+ LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+ *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ } Catch (ConversionException) {
+ LogError("ConversionException: " << _rethrown_exception.GetMessage());
+ *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ } Catch (InvalidArgumentException) {
+ LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+ *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+ } Catch(WrtDeviceApis::Commons::Exception) {
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ }
+ return false;
+}
+
+JSValueRef JSNdefRecordArray::concat(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ //copy current privateDatas
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ if (!priv) {
+ LogError("Private object is not set.");
+ ThrowMsg(NullPointerException, "Private object not initialized");
+ }
+
+ INdefMessagePtr myMessage = priv->getObject();
+
+ INdefMessagePtr NdefMessage = NFCFactory::getInstance().createNDEFMessageObject(myMessage->toByte());
+
+ if (argumentCount == 0)
+ return createArray(priv->getContext(), NdefMessage);
+
+ NFCConverter converter(context);
+ for (int i = 0; i < argumentCount; i++) {
+ if (JSIsArrayValue(context, arguments[i])) {
+ std::vector<void *> records = converter.toVectorOfRecordHandles(arguments[i]);
+ for (int j = 0; j < records.size(); j++)
+ NdefMessage->appendNDEFRecord(records[j]);
+ } else if (isObjectOfClass(context, arguments[i])) {
+ NdefMessagePrivObject* argPriv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(converter.toJSObjectRef(arguments[i])));
+ if (!argPriv) {
+ LogError(i << "record's private object is not set.");
+ ThrowMsg(InvalidArgumentException, "Record's private object not initialized");
+ }
+ INdefMessagePtr argMessage = argPriv->getObject();
+ for (long j = 0 ; j < argMessage->getRecordCount(); j++)
+ NdefMessage->appendNDEFRecord(argMessage->getRecordHandle(j));
+ } else
+ ThrowMsg(ConversionException, "No Array");
+ }
+
+ return createArray(priv->getContext(), NdefMessage);;
+ } Catch(NullPointerException) {
+ LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ } Catch(ConversionException) {
+ LogError("ConversionException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ } Catch (InvalidArgumentException) {
+ LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+ } Catch (WrtDeviceApis::Commons::Exception) {
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ }
+
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNdefRecordArray::join(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ std::string result;
+ std::string separator(",");
+ NFCConverter converter(context);
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+ if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+ separator = converter.toString(arguments[0]);
+ }
+ for (size_t i = 0; i < myMessage->getRecordCount(); i++) {
+ if (i != 0) {
+ result += separator;
+ }
+ result += "[object " + converter.toRecordClassName(myMessage->getNDEFRecord(i)) + "]";
+ }
+ return converter.toJSValueRef(result);
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("error occured");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+}
+
+JSValueRef JSNdefRecordArray::pop(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+
+ NFCConverter converter(priv->getContext());
+ long recordCount = myMessage->getRecordCount();
+ if (recordCount > 0) {
+ NdefRecordData result = myMessage->getNDEFRecord(recordCount - 1);
+ myMessage->removeNDEFRecord(recordCount - 1);
+ return converter.toJSValueRef(result);
+ }
+ return JSCreateArrayObject(context, 0, NULL);
+ } Catch(NullPointerException) {
+ LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ } Catch(ConversionException) {
+ LogError("ConversionException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ } Catch (InvalidArgumentException) {
+ LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+ } Catch (WrtDeviceApis::Commons::Exception) {
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNdefRecordArray::push(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ NFCConverter converter(context);
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+
+ for (size_t i = 0; i < argumentCount; ++i) {
+ void *record = converter.getRecordHandle(arguments[i]);
+ myMessage->appendNDEFRecord(record);
+ }
+ return converter.toJSValueRefLong(myMessage->getRecordCount());
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("error occured");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+}
+
+JSValueRef JSNdefRecordArray::reverse(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ NFCConverter converter(context);
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+
+ long recordCounts = myMessage->getRecordCount();
+ if (recordCounts > 0) {
+ std::vector<void *> records;
+ for (long i = recordCounts; i > 0; i--) {
+ records.push_back(myMessage->getRecordHandle(i-1));
+ }
+ myMessage->changeAllRecords(records);
+ }
+ return thisObject;
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("error occured");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNdefRecordArray::shift(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+
+ NFCConverter converter(priv->getContext());
+ long recordCount = myMessage->getRecordCount();
+ if (recordCount > 0) {
+ NdefRecordData result = myMessage->getNDEFRecord(0);
+ myMessage->removeNDEFRecord(0);
+ return converter.toJSValueRef(result);
+ }
+ return JSCreateArrayObject(context, 0, NULL);
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("error occured");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNdefRecordArray::slice(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ Try
+ {
+ if (argumentCount < 1) {
+ return JSValueMakeUndefined(context);
+ }
+
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+
+ NFCConverter converter(priv->getContext());
+ if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0]))
+ ThrowMsg(ConversionException, "parameter is JSNull/JSUndefined/Not number");
+
+ if ((argumentCount > 1) && (!JSValueIsNull(context, arguments[1]) && (JSValueIsUndefined(context, arguments[1]) || !JSValueIsNumber(context, arguments[1]))))
+ ThrowMsg(ConversionException, "parameter is JSNull/JSUndefined/Not number");
+
+ long recordCount = myMessage->getRecordCount();
+ long start = converter.toLong(arguments[0]);
+ long end = recordCount;
+ if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]))
+ end = converter.toLong(arguments[1]) < recordCount ? converter.toLong(arguments[1]) : recordCount;
+
+ if (start < 0)
+ start = recordCount + start;
+
+ if (start > end) {
+ INdefMessagePtr NdefMessage = NFCFactory::getInstance().createNDEFMessageObject();
+ return createArray(priv->getContext(), NdefMessage);
+ }
+
+ std::vector<void *> sliceRecords;
+ for (long i = start; i < end; i++) {
+ void * record = myMessage->getRecordHandle(i);
+ sliceRecords.push_back(record);
+ }
+ INdefMessagePtr NdefMessage = NFCFactory::getInstance().createNDEFMessageObject(sliceRecords);
+ return createArray(priv->getContext(), NdefMessage);
+}
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("error occured");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+}
+
+JSValueRef JSNdefRecordArray::sort(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ LogDebug("Enter");
+ return thisObject;
+}
+
+JSValueRef JSNdefRecordArray::splice(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ Try
+ {
+ if (argumentCount < 1) {
+ return JSCreateArrayObject(context, 0, NULL);
+ }
+
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+
+ NFCConverter converter(priv->getContext());
+ if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0]))
+ ThrowMsg(ConversionException, "parameter is JSNull/JSUndefined/Not number");
+
+ if ( (argumentCount > 1) && (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSValueIsNumber(context, arguments[1])))
+ ThrowMsg(ConversionException, "parameter is JSNull/JSUndefined/Not number");
+
+ long recordCount = myMessage->getRecordCount();
+ long start = converter.toLong(arguments[0]);
+ long howmany = 0;
+ if (argumentCount > 1)
+ howmany= converter.toLong(arguments[1]);
+
+ if (start < 0)
+ start = recordCount + start;
+
+ JSObjectRef result;
+ if (howmany > 0 ) {
+ if ((start + howmany) > recordCount)
+ howmany = recordCount - start;
+
+ std::vector<void *> spliceRecords;
+ for (long i = 0; i < howmany; i++) {
+ void * record = myMessage->getRecordHandle(i + start);
+ spliceRecords.push_back(record);
+ }
+ INdefMessagePtr NdefMessage = NFCFactory::getInstance().createNDEFMessageObject(spliceRecords);
+
+ result = createArray(priv->getContext(), NdefMessage);
+ } else
+ result = JSCreateArrayObject(context, 0, NULL);
+
+ if (argumentCount > 2) {
+ for (long j = 2; j < argumentCount; j++) {
+ void *record = converter.getRecordHandle(arguments[j]);
+ if (start < recordCount)
+ myMessage->appendNDEFRecord(record);
+ else
+ myMessage->insertNDEFRecord(start++, record);
+ }
+ }
+ return result;
+ } Catch(NullPointerException) {
+ LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ } Catch(ConversionException) {
+ LogError("ConversionException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+ } Catch (InvalidArgumentException) {
+ LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+ } Catch (WrtDeviceApis::Commons::Exception) {
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNdefRecordArray::toString(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+
+ return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSNdefRecordArray::unshift(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ Try
+ {
+ NdefMessagePrivObject* priv =
+ static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+ INdefMessagePtr myMessage = priv->getObject();
+
+ NFCConverter converter(priv->getContext());
+
+ if (argumentCount > 0) {
+ for (int i = 0; i < argumentCount; i++) {
+ if (converter.isNdefRecord(arguments[i]) == false)
+ ThrowMsg(ConversionException, "parameter is Not record");
+ }
+
+ for (long i = 0 ; i < argumentCount; i++) {
+ void *record = converter.getRecordHandle(arguments[i]);
+ myMessage->insertNDEFRecord(i, record);
+ }
+ }
+ return converter.toJSValueRefLong(myMessage->getRecordCount());
+ }
+ Catch(WrtDeviceApis::Commons::Exception)
+ {
+ LogError("error occured");
+ }
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+}
+
+JSValueRef JSNdefRecordArray::valueOf(JSContextRef context,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+
+ return join(context, function, thisObject, 0, arguments, exception);
+}
+}
+}