2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "JSNFCTagMifareClassic.h"
19 #include "NFCConverter.h"
20 #include "ResponseDispatcher.h"
22 #include <dpl/log/log.h>
24 #include <CommonsJavaScript/Validator.h>
25 #include <Commons/Exception.h>
26 #include <CommonsJavaScript/PrivateObject.h>
27 #include <CommonsJavaScript/JSUtils.h>
28 #include <CommonsJavaScript/JSCallbackManager.h>
29 #include <CommonsJavaScript/Utils.h>
30 #include <Tizen/Common/JSTizenExceptionFactory.h>
31 #include <Tizen/Common/JSTizenException.h>
32 #include <Tizen/Common/SecurityExceptions.h>
33 #include <API/NFC/NFCFactory.h>
34 #include <API/NFC/EventTagMifareClassicAction.h>
36 #include "plugin_config.h"
39 using namespace TizenApis::Api::NFC;
40 using namespace TizenApis::Commons;
41 using namespace WrtDeviceApis::Commons;
42 using namespace WrtDeviceApis::CommonsJavaScript;
45 #define TIZEN10_NFCTTAGMIFARECLASSIC_ATTRIBUTENAME "NFCTagMifareClassic"
50 JSClassDefinition JSNFCTagMifareClassic::m_classInfo =
53 kJSClassAttributeNone,
54 TIZEN10_NFCTTAGMIFARECLASSIC_ATTRIBUTENAME,
55 JSNFCTag::getClassRef(),
63 NULL, //DeleteProperty,
64 NULL, //GetPropertyNames,
65 NULL, //CallAsFunction,
66 NULL, //CallAsConstructor,
67 hasInstance, //HasInstance,
71 JSStaticFunction JSNFCTagMifareClassic::m_function[] = {
72 {"authenticateWithKeyA", JSNFCTagMifareClassic::authenticateWithKeyA, kJSPropertyAttributeNone},
73 {"authenticateWithKeyB", JSNFCTagMifareClassic::authenticateWithKeyB, kJSPropertyAttributeNone},
74 {"readBlock", JSNFCTagMifareClassic::readBlock, kJSPropertyAttributeNone},
75 {"writeBlock", JSNFCTagMifareClassic::writeBlock, kJSPropertyAttributeNone},
76 {"incrementBlockValue", JSNFCTagMifareClassic::incrementBlockValue, kJSPropertyAttributeNone},
77 {"decrementBlockValue", JSNFCTagMifareClassic::decrementBlockValue, kJSPropertyAttributeNone},
78 {"transfer", JSNFCTagMifareClassic::transfer, kJSPropertyAttributeNone},
79 {"restore", JSNFCTagMifareClassic::restore, kJSPropertyAttributeNone},
83 JSClassRef JSNFCTagMifareClassic::m_jsClassRef = JSClassCreate(JSNFCTagMifareClassic::getClassInfo());
85 JSObjectRef JSNFCTagMifareClassic::createJSObject(JSContextRef context, void *tagHandle, void* privManager) {
88 INFCTagMifareClassicPtr NFCTagMifareClassic = NFCFactory::getInstance().createNFCTagMifareClassicObject(tagHandle);
89 NFCTagMifareClassic->setPrivateNFCManagerPtr(privManager);
91 NFCTagMifareClassicPrivObject *priv = new NFCTagMifareClassicPrivObject(context, NFCTagMifareClassic);
94 ThrowMsg(NullPointerException, "Can not new a NFCTagMifareClassic object");
97 return JSObjectMake(context, getClassRef(), priv);
100 void JSNFCTagMifareClassic::initialize(JSContextRef context, JSObjectRef object)
104 void JSNFCTagMifareClassic::finalize(JSObjectRef object)
106 LogDebug( "entered" );
107 NFCTagMifareClassicPrivObject *priv = static_cast<NFCTagMifareClassicPrivObject*>( JSObjectGetPrivate( object ) ) ;
108 JSObjectSetPrivate(object, NULL);
109 LogDebug("Deleting timezone object");
114 const JSClassRef JSNFCTagMifareClassic::getClassRef()
117 m_jsClassRef = JSClassCreate(&m_classInfo);
122 const JSClassDefinition* JSNFCTagMifareClassic::getClassInfo()
127 bool JSNFCTagMifareClassic::hasInstance(JSContextRef context,
128 JSObjectRef constructor,
129 JSValueRef possibleInstance,
130 JSValueRef* exception)
132 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
135 JSValueRef JSNFCTagMifareClassic::authenticateWithKeyA(JSContextRef context,
137 JSObjectRef thisObject,
138 size_t argumentCount,
139 const JSValueRef arguments[],
140 JSValueRef* exception)
142 LogDebug("Entered ");
144 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
145 if (NULL == privateObject) {
146 LogError("private object is null");
147 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
150 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
151 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
153 NFCConverter convert(context);
154 Validator validator(context, exception);
156 if ((argumentCount < 2) || (argumentCount > 4)) {
157 LogError("JSNFCTagMifareClassic::authenticateWithKeyA arguemtcount error");
158 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
161 if ((JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSIsArrayValue(context, arguments[0]))
162 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSValueIsNumber(context, arguments[1]))){
163 LogError("JSNFCTagMifareClassic::authenticateWithKeyA key or sectorIndex TypeMismatchException!");
164 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
167 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
168 /* 1st argument is mandatory. And 1st argument must be Callback. */
169 LogError("JSNFCTagMifareClassic::authenticateWithKeyA SuccessCallback TypeMismatchException!");
170 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
172 if((argumentCount > 3) && !JSValueIsNull(context, arguments[3]) && (JSValueIsUndefined(context, arguments[3]) || !validator.isCallback(arguments[3]))) {
173 /* 2nd argument must be Callback. */
174 LogError("JSNFCTagMifareClassic::authenticateWithKeyA ErrorCallback TypeMismatchException!");
175 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
178 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
179 if ((argumentCount > 2) && (validator.isCallback(arguments[2]))) {
180 onSuccessForCbm = arguments[2];
182 if ((argumentCount > 3) && (validator.isCallback(arguments[3]))) {
183 onErrorForCbm = arguments[3];
187 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
188 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
190 EventTagMifareClassicAuthenticateWithKeyAPtr event(new EventTagMifareClassicAuthenticateWithKeyA(convert.toVectorOfUChars(arguments[0]), convert.toInt(arguments[1])));
191 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
192 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
193 NFCTagMifareClassic->authenticateWithKeyA(event);
195 return JSValueMakeNull(context);
196 } Catch (ConversionException) {
197 LogError("JSNFCManager::authenticateWithKeyA : ConversionException");
198 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
199 } Catch (InvalidArgumentException) {
200 LogError("JSNFCManager::authenticateWithKeyA InvalidArgumentException");
201 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
202 } Catch (PlatformException) {
203 LogError("PlatformException: " << _rethrown_exception.GetMessage());
204 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
205 return JSValueMakeNull(context);
206 } Catch (WrtDeviceApis::Commons::Exception) {
207 LogError("Exception: " << _rethrown_exception.GetMessage());
208 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
209 return JSValueMakeNull(context);
212 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
213 return JSValueMakeNull(context);
216 JSValueRef JSNFCTagMifareClassic::authenticateWithKeyB(JSContextRef context,
218 JSObjectRef thisObject,
219 size_t argumentCount,
220 const JSValueRef arguments[],
221 JSValueRef* exception)
223 LogDebug("Entered ");
225 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
226 if (NULL == privateObject) {
227 LogError("private object is null");
228 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
231 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
232 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
234 NFCConverter convert(context);
235 Validator validator(context, exception);
237 if ((argumentCount < 2) || (argumentCount > 4)) {
238 LogError("JSNFCTagMifareClassic::authenticateWithKeyB argumentCount error");
239 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
242 if ((JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSIsArrayValue(context, arguments[0]))
243 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSValueIsNumber(context, arguments[1]))){
244 LogError("JSNFCTagMifareClassic::authenticateWithKeyB key or sectorIndex TypeMismatchException!");
245 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
248 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
249 /* 1st argument is mandatory. And 1st argument must be Callback. */
250 LogError("JSNFCTagMifareClassic::authenticateWithKeyB SuccessCallback TypeMismatchException!");
251 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
253 if((argumentCount > 3) && !JSValueIsNull(context, arguments[3]) && (JSValueIsUndefined(context, arguments[3]) || !validator.isCallback(arguments[3]))){
254 /* 2nd argument must be Callback. */
255 LogError("JSNFCTagMifareClassic::authenticateWithKeyB ErrorCallback TypeMismatchException!");
256 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
259 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
260 if (validator.isCallback(arguments[2])) {
261 onSuccessForCbm = arguments[2];
263 if ((argumentCount > 3) && validator.isCallback(arguments[3])) {
264 onErrorForCbm = arguments[3];
268 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
269 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
271 EventTagMifareClassicAuthenticateWithKeyBPtr event(new EventTagMifareClassicAuthenticateWithKeyB(convert.toVectorOfUChars(arguments[0]), convert.toInt(arguments[1])));
272 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
273 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
274 NFCTagMifareClassic->authenticateWithKeyB(event);
276 return JSValueMakeNull(context);
277 } Catch (ConversionException) {
278 LogError("JSNFCManager::authenticateWithKeyB : ConversionException");
279 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
280 } Catch (InvalidArgumentException) {
281 LogError("JSNFCManager::authenticateWithKeyB InvalidArgumentException");
282 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
283 } Catch (PlatformException) {
284 LogError("PlatformException: " << _rethrown_exception.GetMessage());
285 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
286 return JSValueMakeNull(context);
287 } Catch (WrtDeviceApis::Commons::Exception) {
288 LogError("Exception: " << _rethrown_exception.GetMessage());
289 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
290 return JSValueMakeNull(context);
293 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
294 return JSValueMakeNull(context);
297 JSValueRef JSNFCTagMifareClassic::readBlock(JSContextRef context,
299 JSObjectRef thisObject,
300 size_t argumentCount,
301 const JSValueRef arguments[],
302 JSValueRef* exception)
304 LogDebug("Entered ");
306 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
307 if (NULL == privateObject) {
308 LogError("private object is null");
309 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
312 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
313 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
315 NFCConverter convert(context);
316 Validator validator(context, exception);
318 if ((argumentCount < 2) || (argumentCount > 3)) {
319 LogError("JSNFCTagMifareClassic::readBlock argumentCount error");
320 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
323 if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0])) {
324 LogError("JSNFCTagMifareClassic::readBlock blockIndex TypeMismatchException!");
325 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
328 if (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !validator.isCallback(arguments[1])) {
329 /* 1st argument is mandatory. And 1st argument must be Callback. */
330 LogError("JSNFCTagMifareClassic::readBlock NFCDataReadCB TypeMismatchException!");
331 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
333 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
334 /* 2nd argument must be Callback. */
335 LogError("JSNFCTagMifareClassic::readBlock errorCallback TypeMismatchException!");
336 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
339 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
340 if (validator.isCallback(arguments[1])) {
341 onSuccessForCbm = arguments[1];
343 if ((argumentCount > 2) && (validator.isCallback(arguments[2]))) {
344 onErrorForCbm = arguments[2];
348 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
349 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
351 EventTagMifareClassicReadBlockPtr event(new EventTagMifareClassicReadBlock(convert.toInt(arguments[0])));
352 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
353 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
354 NFCTagMifareClassic->readBlock(event);
356 return JSValueMakeNull(context);
357 } Catch (ConversionException) {
358 LogError("JSNFCManager::readBlock : ConversionException");
359 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
360 } Catch (InvalidArgumentException) {
361 LogError("JSNFCManager::readBlock InvalidArgumentException");
362 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
363 } Catch (PlatformException) {
364 LogError("PlatformException: " << _rethrown_exception.GetMessage());
365 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
366 return JSValueMakeNull(context);
367 } Catch (WrtDeviceApis::Commons::Exception) {
368 LogError("Exception: " << _rethrown_exception.GetMessage());
369 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
370 return JSValueMakeNull(context);
373 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
374 return JSValueMakeNull(context);
377 JSValueRef JSNFCTagMifareClassic::writeBlock(JSContextRef context,
379 JSObjectRef thisObject,
380 size_t argumentCount,
381 const JSValueRef arguments[],
382 JSValueRef* exception)
384 LogDebug("Entered ");
386 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
387 if (NULL == privateObject) {
388 LogError("private object is null");
389 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
392 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
393 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
395 NFCConverter convert(context);
396 Validator validator(context, exception);
398 if ((argumentCount < 2) || (argumentCount > 4)) {
399 LogError("JSNFCTagMifareClassic::writeBlock argumentCount error");
400 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
403 if ((JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0]))
404 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSIsArrayValue(context, arguments[1]))){
405 LogError("JSNFCTagMifareClassic::writeBlock blockIndex or block TypeMismatchException!");
406 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
409 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
410 /* 1st argument is mandatory. And 1st argument must be Callback. */
411 LogError("JSNFCTagMifareClassic::writeBlock successCallback TypeMismatchException!");
412 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
414 if ((argumentCount > 3) && !JSValueIsNull(context, arguments[3]) && (JSValueIsUndefined(context, arguments[3]) || !validator.isCallback(arguments[3]))) {
415 /* 2nd argument must be Callback. */
416 LogError("JSNFCTagMifareClassic::writeBlock errorCallback TypeMismatchException!");
417 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
420 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
421 if ((argumentCount > 2) && (validator.isCallback(arguments[2]))) {
422 onSuccessForCbm = arguments[2];
424 if ((argumentCount > 3) && (validator.isCallback(arguments[3]))) {
425 onErrorForCbm = arguments[3];
429 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
430 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
432 EventTagMifareClassicWriteBlockPtr event(new EventTagMifareClassicWriteBlock(convert.toInt(arguments[0]), convert.toVectorOfUChars(arguments[1])));
433 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
434 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
435 NFCTagMifareClassic->writeBlock(event);
437 return JSValueMakeNull(context);
438 } Catch (ConversionException) {
439 LogError("JSNFCManager::writeBlock : ConversionException");
440 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR,"Invalid Parameter"));
441 } Catch (InvalidArgumentException) {
442 LogError("JSNFCManager::writeBlock InvalidArgumentException");
443 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
444 } Catch (PlatformException) {
445 LogError("PlatformException: " << _rethrown_exception.GetMessage());
446 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
447 return JSValueMakeNull(context);
448 } Catch (WrtDeviceApis::Commons::Exception) {
449 LogError("Exception: " << _rethrown_exception.GetMessage());
450 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
451 return JSValueMakeNull(context);
454 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
455 return JSValueMakeNull(context);
458 JSValueRef JSNFCTagMifareClassic::incrementBlockValue(JSContextRef context,
460 JSObjectRef thisObject,
461 size_t argumentCount,
462 const JSValueRef arguments[],
463 JSValueRef* exception)
465 LogDebug("Entered ");
467 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
468 if (NULL == privateObject) {
469 LogError("private object is null");
470 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
473 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
474 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
476 NFCConverter convert(context);
477 Validator validator(context, exception);
479 if ((argumentCount < 2) || (argumentCount > 4)) {
480 LogError("JSNFCTagMifareClassic::incrementBlockValue argumentCount error");
481 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
484 if ((JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0]))
485 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSValueIsNumber(context, arguments[1]))){
486 LogError("JSNFCTagMifareClassic::incrementBlockValue index or value TypeMismatchException!");
487 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
490 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
491 /* 1st argument is mandatory. And 1st argument must be Callback. */
492 LogError("JSNFCTagMifareClassic::incrementBlockValue successCallback TypeMismatchException!");
493 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
495 if ((argumentCount > 3) && !JSValueIsNull(context, arguments[3]) && (JSValueIsUndefined(context, arguments[3]) || !validator.isCallback(arguments[3]))) {
496 /* 2nd argument must be Callback. */
497 LogError("JSNFCTagMifareClassic::incrementBlockValue errorCallbackTypeMismatchException!");
498 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
501 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
502 if ((argumentCount > 2) && (validator.isCallback(arguments[2]))) {
503 onSuccessForCbm = arguments[2];
505 if ((argumentCount > 3) && (validator.isCallback(arguments[3]))) {
506 onErrorForCbm = arguments[3];
510 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
511 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
513 EventTagMifareClassicIncrementBlockValuePtr event(new EventTagMifareClassicIncrementBlockValue(convert.toInt(arguments[0]), convert.toInt(arguments[1])));
514 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
515 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
516 NFCTagMifareClassic->incrementBlockValue(event);
518 return JSValueMakeNull(context);
519 } Catch (ConversionException) {
520 LogError("JSNFCManager::incrementBlockValue : ConversionException");
521 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
522 } Catch (InvalidArgumentException) {
523 LogError("JSNFCManager::incrementBlockValue InvalidArgumentException");
524 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
525 } Catch (PlatformException) {
526 LogError("PlatformException: " << _rethrown_exception.GetMessage());
527 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
528 return JSValueMakeNull(context);
529 } Catch (WrtDeviceApis::Commons::Exception) {
530 LogError("Exception: " << _rethrown_exception.GetMessage());
531 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
532 return JSValueMakeNull(context);
535 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
536 return JSValueMakeNull(context);
539 JSValueRef JSNFCTagMifareClassic::decrementBlockValue(JSContextRef context,
541 JSObjectRef thisObject,
542 size_t argumentCount,
543 const JSValueRef arguments[],
544 JSValueRef* exception)
546 LogDebug("Entered ");
548 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
549 if (NULL == privateObject) {
550 LogError("private object is null");
551 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
554 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
555 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
557 NFCConverter convert(context);
558 Validator validator(context, exception);
560 if ((argumentCount < 2) || (argumentCount > 4)) {
561 LogError("JSNFCTagMifareClassic::decrementBlockValue argumentCount error");
562 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
565 if ((JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0]))
566 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSValueIsNumber(context, arguments[1]))){
567 LogError("JSNFCTagMifareClassic::decrementBlockValue index or value TypeMismatchException!");
568 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
571 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
572 /* 1st argument is mandatory. And 1st argument must be Callback. */
573 LogError("JSNFCTagMifareClassic::decrementBlockValue successCallback TypeMismatchException!");
574 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
576 if ((argumentCount > 3) && !JSValueIsNull(context, arguments[3]) && (JSValueIsUndefined(context, arguments[3]) || !validator.isCallback(arguments[3]))) {
577 /* 2nd argument must be Callback. */
578 LogError("JSNFCTagMifareClassic::decrementBlockValue errorCallbackTypeMismatchException!");
579 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
582 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
583 if ((argumentCount > 2) && (validator.isCallback(arguments[2]))) {
584 onSuccessForCbm = arguments[2];
586 if ((argumentCount > 3) && (validator.isCallback(arguments[3]))) {
587 onErrorForCbm = arguments[3];
591 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
592 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
594 EventTagMifareClassicDecrementBlockValuePtr event(new EventTagMifareClassicDecrementBlockValue(convert.toInt(arguments[0]), convert.toInt(arguments[1])));
595 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
596 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
597 NFCTagMifareClassic->decrementBlockValue(event);
599 return JSValueMakeNull(context);
600 } Catch (ConversionException) {
601 LogError("JSNFCManager::decrementBlockValue : ConversionException");
602 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
603 } Catch (InvalidArgumentException) {
604 LogError("JSNFCManager::decrementBlockValue InvalidArgumentException");
605 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
606 } Catch (PlatformException) {
607 LogError("PlatformException: " << _rethrown_exception.GetMessage());
608 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
609 return JSValueMakeNull(context);
610 } Catch (WrtDeviceApis::Commons::Exception) {
611 LogError("Exception: " << _rethrown_exception.GetMessage());
612 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
613 return JSValueMakeNull(context);
616 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
617 return JSValueMakeNull(context);
620 JSValueRef JSNFCTagMifareClassic::transfer(JSContextRef context,
622 JSObjectRef thisObject,
623 size_t argumentCount,
624 const JSValueRef arguments[],
625 JSValueRef* exception)
627 LogDebug("Entered ");
628 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
629 if (NULL == privateObject) {
630 LogError("private object is null");
631 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
634 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
635 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
637 NFCConverter convert(context);
638 Validator validator(context, exception);
640 if ((argumentCount < 1) || (argumentCount > 3)) {
641 LogError("JSNFCTagMifareClassic::transfer argumentCount error");
642 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
645 if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0])) {
646 LogError("JSNFCTagMifareClassic::transfer blockIndex TypeMismatchException!");
647 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
650 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
651 /* 2nd argument must be Callback. */
652 LogError("JSNFCTagMifareClassic::transfer successCallback TypeMismatchException!");
653 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
655 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
656 /* 2nd argument must be Callback. */
657 LogError("JSNFCTagMifareClassic::transfer errorCallback TypeMismatchException!");
658 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
661 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
662 if ((argumentCount > 1) && (validator.isCallback(arguments[1]))) {
663 onSuccessForCbm = arguments[1];
665 if ((argumentCount > 2) && (validator.isCallback(arguments[2]))) {
666 onErrorForCbm = arguments[2];
670 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
671 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
673 EventTagMifareClassicTransferPtr event(new EventTagMifareClassicTransfer(convert.toInt(arguments[0])));
674 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
675 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
676 NFCTagMifareClassic->transfer(event);
678 return JSValueMakeNull(context);
679 } Catch (ConversionException) {
680 LogError("JSNFCManager::transfer : ConversionException");
681 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
682 } Catch (InvalidArgumentException) {
683 LogError("JSNFCManager::transfer InvalidArgumentException");
684 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
685 } Catch (PlatformException) {
686 LogError("PlatformException: " << _rethrown_exception.GetMessage());
687 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
688 return JSValueMakeNull(context);
689 } Catch (WrtDeviceApis::Commons::Exception) {
690 LogError("Exception: " << _rethrown_exception.GetMessage());
691 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
692 return JSValueMakeNull(context);
695 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
696 return JSValueMakeNull(context);
699 JSValueRef JSNFCTagMifareClassic::restore(JSContextRef context,
701 JSObjectRef thisObject,
702 size_t argumentCount,
703 const JSValueRef arguments[],
704 JSValueRef* exception)
706 LogDebug("Entered ");
707 NFCTagMifareClassicPrivObject* privateObject = static_cast<NFCTagMifareClassicPrivObject*>(JSObjectGetPrivate(thisObject));
708 if (NULL == privateObject) {
709 LogError("private object is null");
710 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
713 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
714 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
716 NFCConverter convert(context);
717 Validator validator(context, exception);
719 if ((argumentCount < 1) || (argumentCount > 3)) {
720 LogError("JSNFCTagMifareClassic::restore argumentCount error");
721 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
724 if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsNumber(context, arguments[0])) {
725 LogError("JSNFCTagMifareClassic::restore blockIndex TypeMismatchException!");
726 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
729 if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1]) && (JSValueIsUndefined(context, arguments[1]) || !validator.isCallback(arguments[1]))) {
730 /* 1st argument is mandatory. And 1st argument must be Callback. */
731 LogError("JSNFCTagMifareClassic::restore successCallback TypeMismatchException!");
732 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
734 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2]) && (JSValueIsUndefined(context, arguments[2]) || !validator.isCallback(arguments[2]))) {
735 /* 2nd argument must be Callback. */
736 LogError("JSNFCTagMifareClassic::restore errorCallback TypeMismatchException!");
737 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
740 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
741 if ((argumentCount > 1) && (validator.isCallback(arguments[1]))) {
742 onSuccessForCbm = arguments[1];
744 if ((argumentCount > 2) && (validator.isCallback(arguments[2]))) {
745 onErrorForCbm = arguments[2];
749 INFCTagMifareClassicPtr NFCTagMifareClassic(privateObject->getObject());
750 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
752 EventTagMifareClassicRestorePtr event(new EventTagMifareClassicRestore(convert.toInt(arguments[0])));
753 event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
754 event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
755 NFCTagMifareClassic->restore(event);
757 return JSValueMakeNull(context);
758 } Catch (ConversionException) {
759 LogError("JSNFCManager::restore : ConversionException");
760 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
761 } Catch (InvalidArgumentException) {
762 LogError("JSNFCManager::restore InvalidArgumentException");
763 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
764 } Catch (PlatformException) {
765 LogError("PlatformException: " << _rethrown_exception.GetMessage());
766 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
767 return JSValueMakeNull(context);
768 } Catch (WrtDeviceApis::Commons::Exception) {
769 LogError("Exception: " << _rethrown_exception.GetMessage());
770 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
771 return JSValueMakeNull(context);
774 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
775 return JSValueMakeNull(context);