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 "JSNFCManager.h"
19 #include "JSNdefMessage.h"
20 #include "JSNdefRecord.h"
21 #include "NFCConverter.h"
22 #include "NFCStaticController.h"
23 #include "EventNFCChangedPrivateData.h"
25 #include <dpl/log/log.h>
28 #include <CommonsJavaScript/Validator.h>
29 #include <Commons/Exception.h>
30 #include <CommonsJavaScript/PrivateObject.h>
31 #include <CommonsJavaScript/JSUtils.h>
32 #include <CommonsJavaScript/JSCallbackManager.h>
33 #include <CommonsJavaScript/Utils.h>
34 #include <Tizen/Common/JSTizenExceptionFactory.h>
35 #include <Tizen/Common/JSTizenException.h>
36 #include <Tizen/Common/SecurityExceptions.h>
37 #include <API/NFC/NFCFactory.h>
38 #include <API/NFC/EventNFCChanged.h>
39 #include "plugin_config.h"
43 using namespace TizenApis::Api::NFC;
44 using namespace TizenApis::Commons;
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
48 #define TIZEN10_NFCMANAGER_ATTRIBUTENAME "NFCManager"
50 #define TIZEN10_NFCMANAGER_TNF_EMPTY "NFC_RECORD_TNF_EMPTY"
51 #define TIZEN10_NFCMANAGER_TNF_WELL_KNOWN "NFC_RECORD_TNF_WELL_KNOWN"
52 #define TIZEN10_NFCMANAGER_TNF_MIME_MEDIA "NFC_RECORD_TNF_MIME_MEDIA"
53 #define TIZEN10_NFCMANAGER_TNF_URI "NFC_RECORD_TNF_URI"
54 #define TIZEN10_NFCMANAGER_TNF_EXTERNAL_RTD "NFC_RECORD_TNF_EXTERNAL_RTD"
55 #define TIZEN10_NFCMANAGER_TNF_UNKNOWN "NFC_RECORD_TNF_UNKNOWN"
56 #define TIZEN10_NFCMANAGER_TNF_UNCHANGED "NFC_RECORD_TNF_UNCHAGNED"
61 JSClassDefinition JSNFCManager::m_classInfo =
64 kJSClassAttributeNone,
65 TIZEN10_NFCMANAGER_ATTRIBUTENAME,
74 NULL, //DeleteProperty,
75 NULL, //GetPropertyNames,
76 NULL, //CallAsFunction,
77 NULL, //CallAsConstructor,
82 JSStaticValue JSNFCManager::m_property[] =
84 //NFCManagerProperties
85 {TIZEN10_NFCMANAGER_TNF_EMPTY, getProperty, NULL, kJSPropertyAttributeReadOnly},
86 {TIZEN10_NFCMANAGER_TNF_WELL_KNOWN, getProperty, NULL, kJSPropertyAttributeReadOnly},
87 {TIZEN10_NFCMANAGER_TNF_MIME_MEDIA, getProperty, NULL, kJSPropertyAttributeReadOnly},
88 {TIZEN10_NFCMANAGER_TNF_URI, getProperty, NULL, kJSPropertyAttributeReadOnly},
89 {TIZEN10_NFCMANAGER_TNF_EXTERNAL_RTD, getProperty, NULL, kJSPropertyAttributeReadOnly},
90 {TIZEN10_NFCMANAGER_TNF_UNKNOWN, getProperty, NULL, kJSPropertyAttributeReadOnly},
91 {TIZEN10_NFCMANAGER_TNF_UNCHANGED, getProperty, NULL, kJSPropertyAttributeReadOnly},
95 JSStaticFunction JSNFCManager::m_function[] = {
96 {"setTagListener", JSNFCManager::setTagListener, kJSPropertyAttributeNone },
97 {"unsetTagListener", JSNFCManager::unsetTagListener, kJSPropertyAttributeNone},
98 {"setPeerListener", JSNFCManager::setPeerListener, kJSPropertyAttributeNone },
99 {"unsetPeerListener", JSNFCManager::unsetPeerListener, kJSPropertyAttributeNone},
100 {"setNDEFListener", JSNFCManager::setNDEFListener, kJSPropertyAttributeNone },
101 {"unsetNDEFListener", JSNFCManager::unsetNDEFListener, kJSPropertyAttributeNone},
102 {"setSEEventListener", JSNFCManager::setSEEventListener, kJSPropertyAttributeNone },
103 {"unsetSEEventListener", JSNFCManager::unsetSEEventListener, kJSPropertyAttributeNone},
104 {"getCachedMessage", JSNFCManager::getCachedMessage, kJSPropertyAttributeNone},
105 {"createNDEFMessage", JSNFCManager::createNDEFMessage, kJSPropertyAttributeNone},
106 {"createNDEFMessageFromRawData", JSNFCManager::createNDEFMessageFromRawData, kJSPropertyAttributeNone},
107 {"createNDEFRecord", JSNFCManager::createNDEFRecord, kJSPropertyAttributeNone},
108 {"createNDEFRecordText", JSNFCManager::createNDEFRecordText, kJSPropertyAttributeNone},
109 {"createNDEFRecordURI", JSNFCManager::createNDEFRecordURI, kJSPropertyAttributeNone},
110 {"createNDEFRecordMedia", JSNFCManager::createNDEFRecordMedia, kJSPropertyAttributeNone},
114 JSClassRef JSNFCManager::m_jsClassRef = JSClassCreate(JSNFCManager::getClassInfo());
116 void JSNFCManager::initialize(JSContextRef context, JSObjectRef object)
118 NFCManagerPrivObject* priv = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(object));
121 INFCManagerPtr NFCManager( NFCFactory::getInstance().createNFCManagerObject() );
122 priv = new NFCManagerPrivObject(context, NFCManager);
123 if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
124 LogError("Object can't store private data.");
127 } Catch (UnsupportedException) {
128 LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
129 } Catch (WrtDeviceApis::Commons::Exception) {
130 LogError("Exception: " << _rethrown_exception.GetMessage());
135 void JSNFCManager::finalize(JSObjectRef object)
137 LogDebug( "entered" );
138 NFCManagerPrivObject *priv = static_cast<NFCManagerPrivObject*>( JSObjectGetPrivate( object ) ) ;
139 JSObjectSetPrivate(object, NULL);
140 LogDebug("Deleting NFC Manager object");
145 const JSClassRef JSNFCManager::getClassRef()
148 m_jsClassRef = JSClassCreate(&m_classInfo);
153 const JSClassDefinition* JSNFCManager::getClassInfo()
158 JSValueRef JSNFCManager::getProperty(JSContextRef context, JSObjectRef object,
159 JSStringRef propertyName, JSValueRef* exception)
164 Converter convert(context);
166 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_EMPTY)) {
167 return convert.toJSValueRef(NFC_TNF_EMPTY);
168 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_WELL_KNOWN)) {
169 return convert.toJSValueRef(NFC_TNF_WELL_KNOWN);
170 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_MIME_MEDIA)) {
171 return convert.toJSValueRef(NFC_TNF_MIME_MEDIA);
172 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_URI)) {
173 return convert.toJSValueRef(NFC_TNF_URI);
174 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_EXTERNAL_RTD)) {
175 return convert.toJSValueRef(NFC_TNF_EXTERNAL_RTD);
176 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_UNKNOWN)) {
177 return convert.toJSValueRef(NFC_TNF_UNKNOWN);
178 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_UNCHANGED)) {
179 return convert.toJSValueRef(NFC_TNF_UNCHAGNED);
181 } Catch (ConversionException) {
182 LogError("ConversionException: " << _rethrown_exception.GetMessage());
183 } Catch (WrtDeviceApis::Commons::Exception) {
184 LogError("Exception: " << _rethrown_exception.GetMessage());
187 return JSValueMakeUndefined(context);
190 JSValueRef JSNFCManager::setTagListener (JSContextRef context, JSObjectRef object,
191 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
192 JSValueRef* exception) {
193 LogDebug("JSNFCManager::setTagListener Enter");
194 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
195 if (!privateObject) {
196 LogError("private object is null");
197 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
200 JSContextRef global_context = privateObject->getContext();
201 NFCConverter nfcConverter(context);
202 Validator validator(context, exception);
204 AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_TAG_FUNCS);
205 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
207 if (argumentCount == 0) {
208 /* Argument count must be 1, 2 or 3. */
209 LogError("JSNFCManager::setTagListener TypeMismatchException");
210 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
212 if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) ) {
213 /* 1st argument is mandatory. And 1st argument must be Callback. */
214 LogError("JSNFCManager::setTagListener TypeMismatchException!");
215 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
217 if (argumentCount > 1) {
218 if (!JSValueIsNull(context, arguments[1]) && !validator.isCallback(arguments[1])) {
219 /* 2nd argument must be Callback. */
220 LogError("JSNFCManager::setTagListener TypeMismatchException!");
221 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
225 JSValueRef onErrorForCbm = NULL;
226 NFCChangedCallback callbacks;
228 if (JSValueIsObject(context, arguments[0]) &&
229 !validator.isCallback(arguments[0])) {
230 callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
232 LogError("DetectedCB must has onAttach and onDetach");
233 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
236 if (argumentCount > 1) {
237 if (validator.isCallback(arguments[1])) {
238 onErrorForCbm = arguments[1];
242 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onAttach, onErrorForCbm, true, true);
243 JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.onDetach, NULL);
246 INFCManagerPtr NFC_ptr( privateObject->getObject() );
248 //process the filter object
249 TagFilterPtr tagFilter;
250 if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2])) {
251 if (!JSValueIsNull(context, arguments[2]) &&
252 !JSValueIsUndefined(context, arguments[2]) &&
253 JSIsArrayValue(context, arguments[2])) {
254 tagFilter = nfcConverter.toNFCTagFilter(arguments[2]);
257 Throw(ConversionException);
261 TagFilterPtr _filter (new TagFilter());
265 EventNFCChangedPrivateDataPtr privateData(
266 new EventNFCChangedPrivateData(callbackManager,
267 detachedCallbackManager)
269 EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
270 emitter->setListener(&NFCStaticController::getInstance());
271 emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
273 if (NFC_ptr->setTagListener(emitter, tagFilter, (void *)privateObject) != 0)
274 Throw(PlatformException);
276 return JSValueMakeNull(context);
277 } Catch (ConversionException) {
278 LogError("JSNFCManager::setTagListener : ConversionException");
279 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
280 } Catch (InvalidArgumentException) {
281 LogError("JSNFCManager::setTagListener InvalidArgumentException");
282 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
283 } Catch (WrtDeviceApis::Commons::Exception) {
284 LogError("Exception: " << _rethrown_exception.GetMessage());
285 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
287 return JSValueMakeUndefined(context);
290 JSValueRef JSNFCManager::setPeerListener (JSContextRef context, JSObjectRef object,
291 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
292 JSValueRef* exception) {
293 LogDebug("JSNFCManager::setPeerListener Enter");
294 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
295 if (!privateObject) {
296 LogError("private object is null");
297 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
300 JSContextRef global_context = privateObject->getContext();
301 NFCConverter nfcConverter(context);
302 Validator validator(context, exception);
304 AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_P2P_FUNCS);
305 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
307 if (argumentCount == 0) {
308 /* Argument count must be 1, 2 or 3. */
309 LogError("JSNFCManager::setPeerListener TypeMismatchException");
310 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
312 if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) ) {
313 /* 1st argument is mandatory. And 1st argument must be Callback. */
314 LogError("JSNFCManager::setPeerListener TypeMismatchException!");
315 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
317 if (argumentCount > 1) {
318 if (!JSValueIsNull(context, arguments[1]) && !validator.isCallback(arguments[1])) {
319 /* 2nd argument must be Callback. */
320 LogError("JSNFCManager::setPeerListener TypeMismatchException!");
321 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
325 JSValueRef onErrorForCbm = NULL;
326 NFCChangedCallback callbacks;
328 if (JSValueIsObject(context, arguments[0]) &&
329 !validator.isCallback(arguments[0])) {
330 callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
332 LogError("DetectedCB must has onAttach and onDetach");
333 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
336 if (argumentCount > 1) {
337 if (validator.isCallback(arguments[1])) {
338 onErrorForCbm = arguments[1];
342 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onAttach, onErrorForCbm, true, true);
343 JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.onDetach, NULL);
346 INFCManagerPtr NFC_ptr( privateObject->getObject() );
348 EventNFCChangedPrivateDataPtr privateData(
349 new EventNFCChangedPrivateData(callbackManager,
350 detachedCallbackManager)
353 EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
354 emitter->setListener(&NFCStaticController::getInstance());
355 emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
357 if (NFC_ptr->setPeerListener(emitter, (void *)privateObject) != 0)
358 Throw(PlatformException);
360 return JSValueMakeNull(context);
361 } Catch (ConversionException) {
362 LogError("JSNFCManager::setPeerListener : ConversionException");
363 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
364 } Catch (InvalidArgumentException) {
365 LogError("JSNFCManager::setPeerListener InvalidArgumentException");
366 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
367 } Catch (WrtDeviceApis::Commons::Exception) {
368 LogError("Exception: " << _rethrown_exception.GetMessage());
369 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
371 return JSValueMakeUndefined(context);
374 JSValueRef JSNFCManager::setNDEFListener (JSContextRef context, JSObjectRef object,
375 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
376 JSValueRef* exception) {
377 LogDebug("JSNFCManager::setNDEFListener Enter");
378 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
379 if (!privateObject) {
380 LogError("private object is null");
381 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
384 JSContextRef global_context = privateObject->getContext();
385 Validator validator(context, exception);
387 AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_TAG_FUNCS);
388 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
390 if (argumentCount == 0) {
391 /* Argument count must be 1 or 2. */
392 LogError("JSNFCManager::setNDEFListener TypeMismatchException");
393 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
395 if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !validator.isCallback(arguments[0])) {
396 /* 1st argument is mandatory. And 1st argument must be Callback. */
397 LogError("JSNFCManager::setNDEFListener TypeMismatchException!");
398 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
400 if (argumentCount > 1) {
401 if (!JSValueIsNull(context, arguments[1]) && !validator.isCallback(arguments[1])) {
402 /* 2nd argument must be Callback. */
403 LogError("JSNFCManager::setNDEFListener TypeMismatchException!");
404 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
408 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
409 if (validator.isCallback(arguments[0])) {
410 onSuccessForCbm = arguments[0];
412 if (argumentCount > 1) {
413 if (validator.isCallback(arguments[1])) {
414 onErrorForCbm = arguments[1];
418 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
421 INFCManagerPtr NFC_ptr( privateObject->getObject() );
423 EventNFCChangedNdefEmitterPtr emitter(new EventNFCChangedNdefEmitter);
424 emitter->setListener(&NFCStaticController::getInstance());
425 emitter->setEventPrivateData(StaticPointerCast<EventNFCChangedNdef::PrivateDataType>(callbackManager));
427 if (NFC_ptr->setNDEFListener(emitter) != 0)
428 Throw(PlatformException);
430 return JSValueMakeNull(context);
431 } Catch (ConversionException) {
432 LogError("JSNFCManager::setNDEFListener : ConversionException");
433 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
434 } Catch (InvalidArgumentException) {
435 LogError("JSNFCManager::setNDEFListener InvalidArgumentException");
436 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
437 } Catch (WrtDeviceApis::Commons::Exception) {
438 LogError("Exception: " << _rethrown_exception.GetMessage());
439 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
441 return JSValueMakeUndefined(context);
444 JSValueRef JSNFCManager::setSEEventListener (JSContextRef context, JSObjectRef object,
445 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
446 JSValueRef* exception) {
447 LogDebug("JSNFCManager::setSEEventListener Enter");
448 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
449 if (!privateObject) {
450 LogError("private object is null");
451 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
454 JSContextRef global_context = privateObject->getContext();
455 Validator validator(context, exception);
457 AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_SE_FUNCS);
458 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
460 if (argumentCount == 0) {
461 /* Argument count must be 1 or 2. */
462 LogError("JSNFCManager::setSEEventListener TypeMismatchException");
463 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
465 if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !validator.isCallback(arguments[0])) {
466 /* 1st argument is mandatory. And 1st argument must be Callback. */
467 LogError("JSNFCManager::setSEEventListener TypeMismatchException!");
468 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
470 if (argumentCount > 1) {
471 if (!JSValueIsNull(context, arguments[1]) && !validator.isCallback(arguments[1])) {
472 /* 2nd argument must be Callback. */
473 LogError("JSNFCManager::setSEEventListener TypeMismatchException!");
474 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
478 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
479 if (validator.isCallback(arguments[0])) {
480 onSuccessForCbm = arguments[0];
482 if (argumentCount > 1) {
483 if (validator.isCallback(arguments[1])) {
484 onErrorForCbm = arguments[1];
488 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
491 INFCManagerPtr NFC_ptr( privateObject->getObject() );
493 EventNFCChangedSeEventEmitterPtr emitter(new EventNFCChangedSeEventEmitter);
494 emitter->setListener(&NFCStaticController::getInstance());
495 emitter->setEventPrivateData(StaticPointerCast<EventNFCChangedSeEvent::PrivateDataType>(callbackManager));
497 if (NFC_ptr->setSEEventListener(emitter) != 0)
498 Throw(PlatformException);
500 return JSValueMakeNull(context);
501 } Catch (ConversionException) {
502 LogError("JSNFCManager::setSEEventListener : ConversionException");
503 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR,"Invalid Parameter"));
504 } Catch (InvalidArgumentException) {
505 LogError("JSNFCManager::setSEEventListener InvalidArgumentException");
506 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR,"Invalid Parameter"));
507 } Catch (WrtDeviceApis::Commons::Exception) {
508 LogError("Exception: " << _rethrown_exception.GetMessage());
509 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
511 return JSValueMakeUndefined(context);
514 JSValueRef JSNFCManager::unsetTagListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
515 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
516 LogDebug("JSNFCManager::unsetNFCTagListener Enter");
517 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
518 if (!privateObject) {
519 LogError("private object is null");
520 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
523 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
524 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
527 INFCManagerPtr NFCs( privateObject->getObject() );
529 NFCs->unsetTagListener();
530 return JSValueMakeUndefined(context);
531 } Catch (NullPointerException) {
532 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
533 } Catch (WrtDeviceApis::Commons::Exception) {
534 LogError("Exception: " << _rethrown_exception.GetMessage());
535 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
537 return JSValueMakeUndefined(context);
540 JSValueRef JSNFCManager::unsetPeerListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
541 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
542 LogDebug("JSNFCManager::unsetPeerListener Enter");
543 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
544 if (!privateObject) {
545 LogError("private object is null");
546 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
549 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_P2P_FUNCS);
550 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
553 INFCManagerPtr NFCs( privateObject->getObject() );
555 NFCs->unsetPeerListener();
556 return JSValueMakeUndefined(context);
557 } Catch (NullPointerException) {
558 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
559 } Catch (WrtDeviceApis::Commons::Exception) {
560 LogError("Exception: " << _rethrown_exception.GetMessage());
561 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
563 return JSValueMakeUndefined(context);
566 JSValueRef JSNFCManager::unsetNDEFListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
567 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
568 LogDebug("JSNFCManager::unsetNDEFListener Enter");
569 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
570 if (!privateObject) {
571 LogError("private object is null");
572 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
575 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
576 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
579 INFCManagerPtr NFCs( privateObject->getObject() );
581 NFCs->unsetNDEFListener();
582 return JSValueMakeUndefined(context);
583 } Catch (NullPointerException) {
584 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
585 } Catch (WrtDeviceApis::Commons::Exception) {
586 LogError("Exception: " << _rethrown_exception.GetMessage());
587 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
589 return JSValueMakeUndefined(context);
592 JSValueRef JSNFCManager::unsetSEEventListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
593 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
594 LogDebug("JSNFCManager::unsetSEEventListener Enter");
595 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
596 if (!privateObject) {
597 LogError("private object is null");
598 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
601 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_SE_FUNCS);
602 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
605 INFCManagerPtr NFCs( privateObject->getObject() );
607 NFCs->unsetSEEventListener();
608 return JSValueMakeUndefined(context);
609 } Catch (NullPointerException) {
610 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
611 } Catch (WrtDeviceApis::Commons::Exception) {
612 LogError("Exception: " << _rethrown_exception.GetMessage());
613 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
615 return JSValueMakeUndefined(context);
618 JSValueRef JSNFCManager::getCachedMessage (JSContextRef context, JSObjectRef object,
619 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
620 JSValueRef* exception) {
621 LogDebug("JSNFCManager::getCachedMessage Enter");
622 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
623 if (!privateObject) {
624 LogError("private object is null");
625 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
628 JSContextRef global_context = privateObject->getContext();
630 AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_TAG_FUNCS);
631 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
634 INFCManagerPtr NFC_ptr( privateObject->getObject() );
635 void *cachedMessage = NFC_ptr->getCachedMessage();
636 if (cachedMessage != NULL)
637 return JSNdefMessage::createJSObject(global_context, NFC_ptr->getCachedMessage());
638 } Catch (PlatformException) {
639 LogError("Exception: " << _rethrown_exception.GetMessage());
640 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
641 } Catch(NullPointerException) {
642 LogError("Exception: " << _rethrown_exception.GetMessage());
643 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
644 } Catch (WrtDeviceApis::Commons::Exception) {
645 LogError("Exception: " << _rethrown_exception.GetMessage());
646 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
648 return JSValueMakeUndefined(context);
651 JSValueRef JSNFCManager::createNDEFMessage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
652 LogDebug("Entered ");
654 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
655 if (NULL == privateObject) {
656 LogError("private object is null");
657 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
660 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
661 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
663 INFCManagerPtr NFCManager(privateObject->getObject());
664 NFCConverter convert(context);
666 if ((argumentCount < 1) || JSValueIsNull(context, arguments[0])) {
667 LogError("NdefRecordArray parameter is JSNull/JSUndefined/Not Number");
668 return JSNdefMessage::createJSObject(privateObject->getContext());
669 } else if ((JSValueIsUndefined(context, arguments[0]) || !JSIsArrayValue(context, arguments[0]))) {
670 Throw(ConversionException);
673 return JSNdefMessage::createJSObject(privateObject->getContext(), convert.toVectorOfRecordHandles(arguments[0]));
674 } Catch(ConversionException) {
675 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
676 } Catch (PlatformException) {
677 LogError("Exception: " << _rethrown_exception.GetMessage());
678 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
679 } Catch(NullPointerException) {
680 LogError("Exception: " << _rethrown_exception.GetMessage());
681 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
682 } Catch (WrtDeviceApis::Commons::Exception) {
683 LogError("Exception: " << _rethrown_exception.GetMessage());
684 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
687 return JSValueMakeNull(context);
690 JSValueRef JSNFCManager::createNDEFMessageFromRawData(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
691 LogDebug("Entered ");
693 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
694 if (NULL == privateObject) {
695 LogError("private object is null");
696 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
699 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
700 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
702 INFCManagerPtr NFCManager(privateObject->getObject());
703 NFCConverter convert(context);
705 if ((argumentCount < 1) || JSValueIsNull(context, arguments[0])) {
706 LogError("NdefRecordArray parameter is JSNull/JSUndefined/Not Number");
707 return JSNdefMessage::createJSObject(privateObject->getContext());
708 } else if ((JSValueIsUndefined(context, arguments[0]) || !JSIsArrayValue(context, arguments[0]))) {
709 Throw(ConversionException);
712 return JSNdefMessage::createJSObject(privateObject->getContext(), convert.toVectorOfUChars(arguments[0]));
713 } Catch(ConversionException) {
714 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
715 } Catch (PlatformException) {
716 LogError("Exception: " << _rethrown_exception.GetMessage());
717 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
718 } Catch(NullPointerException) {
719 LogError("Exception: " << _rethrown_exception.GetMessage());
720 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
721 } Catch (WrtDeviceApis::Commons::Exception) {
722 LogError("Exception: " << _rethrown_exception.GetMessage());
723 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
726 return JSValueMakeNull(context);
729 JSValueRef JSNFCManager::createNDEFRecord(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
730 LogDebug("Entered ");
732 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
733 if (NULL == privateObject) {
734 LogError("private object is null");
735 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
738 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
739 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
741 INFCManagerPtr NFCManager(privateObject->getObject());
742 NFCConverter convert(context);
744 if ((argumentCount < 2) || (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]))
745 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSIsArrayValue(context, arguments[1]))) {
746 LogError("parameter is JSNull/JSUndefined/Not array");
747 Throw(ConversionException);
750 return JSNdefRecord::createJSObject(privateObject->getContext(), convert.toNdefRecordProperties(arguments[0], exception), convert.toVectorOfUChars(arguments[1]));
751 } Catch(ConversionException) {
752 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
753 } Catch (PlatformException) {
754 LogError("Exception: " << _rethrown_exception.GetMessage());
755 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
756 } Catch(NullPointerException) {
757 LogError("Exception: " << _rethrown_exception.GetMessage());
758 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
759 } Catch (WrtDeviceApis::Commons::Exception) {
760 LogError("Exception: " << _rethrown_exception.GetMessage());
761 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
764 return JSValueMakeNull(context);
767 JSValueRef JSNFCManager::createNDEFRecordText(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
768 LogDebug("Entered ");
770 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
771 if (NULL == privateObject) {
772 LogError("private object is null");
773 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
776 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
777 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
779 INFCManagerPtr NFCManager(privateObject->getObject());
780 NFCConverter convert(context);
782 if ((argumentCount < 2) || (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsString(context, arguments[0]))
783 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSValueIsString(context, arguments[1]))) {
784 LogError("parameter is JSNull/JSUndefined/Not array");
785 Throw(ConversionException);
788 short encodeType = NFC_TEXT_ENCODE_UTF_8;
790 if ((argumentCount > 2) && (!JSValueIsNull(context, arguments[2]))) {
791 if (JSValueIsUndefined(context, arguments[2]) || !JSValueIsString(context, arguments[2]))
792 Throw(ConversionException);
793 encodeType = convert.toNfcTextEncodeUTF(convert.toString(arguments[2]));
796 return JSNdefRecord::createJSObject(privateObject->getContext(), convert.toString(arguments[0]), convert.toString(arguments[1]), encodeType);
797 } Catch(ConversionException) {
798 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
799 } Catch (PlatformException) {
800 LogError("Exception: " << _rethrown_exception.GetMessage());
801 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
802 } Catch(NullPointerException) {
803 LogError("Exception: " << _rethrown_exception.GetMessage());
804 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
805 } Catch (WrtDeviceApis::Commons::Exception) {
806 LogError("Exception: " << _rethrown_exception.GetMessage());
807 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
810 return JSValueMakeNull(context);
813 JSValueRef JSNFCManager::createNDEFRecordURI(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
814 LogDebug("Entered ");
816 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
817 if (NULL == privateObject) {
818 LogError("private object is null");
819 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
822 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
823 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
825 INFCManagerPtr NFCManager(privateObject->getObject());
826 NFCConverter convert(context);
828 if ((argumentCount < 1) || (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsString(context, arguments[0]))) {
829 LogError("parameter is JSNull/JSUndefined/Not array");
830 Throw(ConversionException);
833 return JSNdefRecord::createJSObject(privateObject->getContext(), convert.toString(arguments[0]));
834 } Catch(ConversionException) {
835 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
836 } Catch (PlatformException) {
837 LogError("Exception: " << _rethrown_exception.GetMessage());
838 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
839 } Catch(NullPointerException) {
840 LogError("Exception: " << _rethrown_exception.GetMessage());
841 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
842 } Catch (WrtDeviceApis::Commons::Exception) {
843 LogError("Exception: " << _rethrown_exception.GetMessage());
844 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
847 return JSValueMakeNull(context);
850 JSValueRef JSNFCManager::createNDEFRecordMedia(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
851 LogDebug("Entered ");
853 NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
854 if (NULL == privateObject) {
855 LogError("private object is null");
856 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
859 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
860 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
862 INFCManagerPtr NFCManager(privateObject->getObject());
863 NFCConverter convert(context);
865 if ((argumentCount < 2) || (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0]) || !JSValueIsString(context, arguments[0]))
866 || (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1]) || !JSIsArrayValue(context, arguments[1]))) {
867 LogError("parameter is JSNull/JSUndefined/Not array");
868 Throw(InvalidArgumentException);
871 return JSNdefRecord::createJSObject(privateObject->getContext(), convert.toString(arguments[0]), convert.toVectorOfUChars(arguments[1]));
872 } Catch(ConversionException) {
873 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
874 } Catch (PlatformException) {
875 LogError("Exception: " << _rethrown_exception.GetMessage());
876 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
877 } Catch(NullPointerException) {
878 LogError("Exception: " << _rethrown_exception.GetMessage());
879 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
880 } Catch (WrtDeviceApis::Commons::Exception) {
881 LogError("Exception: " << _rethrown_exception.GetMessage());
882 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
885 return JSValueMakeNull(context);