5fec926bc1675dd09703698f623c7d3f40b265f0
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / NFC / JSNFCManager.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include "JSNFCManager.h"
19 #include "JSNdefMessage.h"
20 #include "JSNdefRecord.h"
21 #include "NFCConverter.h"
22 #include "NFCStaticController.h"
23 #include "EventNFCChangedPrivateData.h"
24
25 #include <dpl/log/log.h>
26
27 #include <string>
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"
40
41 using namespace std;
42 using namespace DPL;
43 using namespace TizenApis::Api::NFC;
44 using namespace TizenApis::Commons;
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47
48 #define TIZEN10_NFCMANAGER_ATTRIBUTENAME "NFCManager"
49
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"
57
58 namespace TizenApis {
59 namespace Tizen1_0 {
60
61  JSClassDefinition JSNFCManager::m_classInfo =
62 {
63         0,
64         kJSClassAttributeNone,
65         TIZEN10_NFCMANAGER_ATTRIBUTENAME,
66         0,
67         m_property,
68         m_function,
69         initialize,
70         finalize,
71         NULL, //hasProperty,
72         NULL,
73         NULL, //setProperty,
74         NULL, //DeleteProperty,
75         NULL, //GetPropertyNames,
76         NULL, //CallAsFunction,
77         NULL, //CallAsConstructor,
78         NULL, //HasInstance,
79         NULL  //ConvertToType
80 };
81
82 JSStaticValue JSNFCManager::m_property[] =
83 {
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},
92         { 0, 0, 0, 0 }
93 };
94
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},
111         { 0, 0, 0}
112 };
113
114 JSClassRef JSNFCManager::m_jsClassRef = JSClassCreate(JSNFCManager::getClassInfo());
115
116 void JSNFCManager::initialize(JSContextRef context, JSObjectRef object)
117 {
118         NFCManagerPrivObject* priv = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(object));
119         if (!priv) {
120                 Try {
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.");
125                                 delete priv;
126                         }
127                 } Catch (UnsupportedException) {
128                         LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
129                 } Catch (WrtDeviceApis::Commons::Exception) {
130                         LogError("Exception: " << _rethrown_exception.GetMessage());
131                 }
132         }
133 }
134
135 void JSNFCManager::finalize(JSObjectRef object)
136 {
137         LogDebug( "entered" );
138         NFCManagerPrivObject *priv = static_cast<NFCManagerPrivObject*>( JSObjectGetPrivate( object ) ) ;
139         JSObjectSetPrivate(object, NULL);
140         LogDebug("Deleting NFC Manager object");
141         delete priv;
142 }
143
144
145 const JSClassRef JSNFCManager::getClassRef()
146 {
147         if (!m_jsClassRef) {
148                 m_jsClassRef = JSClassCreate(&m_classInfo);
149         }
150         return m_jsClassRef;
151 }
152
153 const JSClassDefinition* JSNFCManager::getClassInfo()
154 {
155         return &m_classInfo;
156 }
157
158 JSValueRef JSNFCManager::getProperty(JSContextRef context, JSObjectRef object,
159         JSStringRef propertyName, JSValueRef* exception)
160 {
161         LogDebug("Enter");
162
163         Try     {
164                 Converter convert(context);
165
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);
180                 }
181         } Catch (ConversionException) {
182                 LogError("ConversionException: " << _rethrown_exception.GetMessage());
183         } Catch (WrtDeviceApis::Commons::Exception) {
184                 LogError("Exception: " << _rethrown_exception.GetMessage());
185         }
186
187         return JSValueMakeUndefined(context);
188 }
189
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");
198         }
199
200         JSContextRef global_context = privateObject->getContext();
201         NFCConverter nfcConverter(context);
202         Validator validator(context, exception);
203
204         AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_TAG_FUNCS);
205         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
206
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");
211         }
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");
216         }
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");
222                 }
223         }
224
225         JSValueRef onErrorForCbm = NULL;
226         NFCChangedCallback callbacks;
227
228         if (JSValueIsObject(context, arguments[0]) &&
229             !validator.isCallback(arguments[0])) {
230             callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
231         } else {
232                 LogError("DetectedCB must has onAttach and onDetach");
233                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
234         }
235
236         if (argumentCount > 1) {
237                 if (validator.isCallback(arguments[1])) {
238                         onErrorForCbm = arguments[1];
239                 }
240         }
241
242         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onAttach, onErrorForCbm, true, true);
243         JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.onDetach, NULL);
244
245         Try {
246                 INFCManagerPtr NFC_ptr( privateObject->getObject() );
247
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]);
255
256                         } else
257                                 Throw(ConversionException);
258                 }
259                 else
260                 {
261                         TagFilterPtr _filter (new TagFilter());
262                         tagFilter = _filter;
263                 }
264
265                 EventNFCChangedPrivateDataPtr privateData(
266                     new EventNFCChangedPrivateData(callbackManager,
267                                                     detachedCallbackManager)
268                     );
269                 EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
270                 emitter->setListener(&NFCStaticController::getInstance());
271                 emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
272
273                 if (NFC_ptr->setTagListener(emitter, tagFilter, (void *)privateObject) != 0)
274                         Throw(PlatformException);
275
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"));
286         }
287         return JSValueMakeUndefined(context);
288 }
289
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");
298         }
299
300         JSContextRef global_context = privateObject->getContext();
301         NFCConverter nfcConverter(context);
302         Validator validator(context, exception);
303
304         AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_P2P_FUNCS);
305         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
306
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");
311         }
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");
316         }
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");
322                 }
323         }
324
325         JSValueRef onErrorForCbm = NULL;
326         NFCChangedCallback callbacks;
327
328         if (JSValueIsObject(context, arguments[0]) &&
329             !validator.isCallback(arguments[0])) {
330             callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
331         } else {
332                 LogError("DetectedCB must has onAttach and onDetach");
333                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
334         }
335
336         if (argumentCount > 1) {
337                 if (validator.isCallback(arguments[1])) {
338                         onErrorForCbm = arguments[1];
339                 }
340         }
341
342         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onAttach, onErrorForCbm, true, true);
343         JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.onDetach, NULL);
344
345         Try {
346                 INFCManagerPtr NFC_ptr( privateObject->getObject() );
347
348                 EventNFCChangedPrivateDataPtr privateData(
349                     new EventNFCChangedPrivateData(callbackManager,
350                                                     detachedCallbackManager)
351                     );
352
353                 EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
354                 emitter->setListener(&NFCStaticController::getInstance());
355                 emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
356
357                 if (NFC_ptr->setPeerListener(emitter, (void *)privateObject) != 0)
358                         Throw(PlatformException);
359
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"));
370         }
371         return JSValueMakeUndefined(context);
372 }
373
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");
382         }
383
384         JSContextRef global_context = privateObject->getContext();
385         Validator validator(context, exception);
386
387         AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_TAG_FUNCS);
388         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
389
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");
394         }
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");
399         }
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");
405                 }
406         }
407
408         JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
409         if (validator.isCallback(arguments[0])) {
410                         onSuccessForCbm = arguments[0];
411         }
412         if (argumentCount > 1) {
413                 if (validator.isCallback(arguments[1])) {
414                         onErrorForCbm = arguments[1];
415                 }
416         }
417
418         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
419
420         Try {
421                 INFCManagerPtr NFC_ptr( privateObject->getObject() );
422
423                 EventNFCChangedNdefEmitterPtr emitter(new EventNFCChangedNdefEmitter);
424                 emitter->setListener(&NFCStaticController::getInstance());
425                 emitter->setEventPrivateData(StaticPointerCast<EventNFCChangedNdef::PrivateDataType>(callbackManager));
426
427                 if (NFC_ptr->setNDEFListener(emitter) != 0)
428                         Throw(PlatformException);
429
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"));
440         }
441         return JSValueMakeUndefined(context);
442 }
443
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");
452         }
453
454         JSContextRef global_context = privateObject->getContext();
455         Validator validator(context, exception);
456
457         AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_SE_FUNCS);
458         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
459
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");
464         }
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");
469         }
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");
475                 }
476         }
477
478         JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
479         if (validator.isCallback(arguments[0])) {
480                         onSuccessForCbm = arguments[0];
481         }
482         if (argumentCount > 1) {
483                 if (validator.isCallback(arguments[1])) {
484                         onErrorForCbm = arguments[1];
485                 }
486         }
487
488         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
489
490         Try {
491                 INFCManagerPtr NFC_ptr( privateObject->getObject() );
492
493                 EventNFCChangedSeEventEmitterPtr emitter(new EventNFCChangedSeEventEmitter);
494                 emitter->setListener(&NFCStaticController::getInstance());
495                 emitter->setEventPrivateData(StaticPointerCast<EventNFCChangedSeEvent::PrivateDataType>(callbackManager));
496
497                 if (NFC_ptr->setSEEventListener(emitter) != 0)
498                         Throw(PlatformException);
499
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"));
510         }
511         return JSValueMakeUndefined(context);
512 }
513
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");
521         }
522
523         AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
524         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
525
526         Try     {
527                 INFCManagerPtr NFCs( privateObject->getObject() );
528
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");
536         }
537         return JSValueMakeUndefined(context);
538 }
539
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");
547         }
548
549         AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_P2P_FUNCS);
550         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
551
552         Try     {
553                 INFCManagerPtr NFCs( privateObject->getObject() );
554
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");
562         }
563         return JSValueMakeUndefined(context);
564 }
565
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");
573         }
574
575         AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_FUNCS);
576         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
577
578         Try     {
579                 INFCManagerPtr NFCs( privateObject->getObject() );
580
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");
588         }
589         return JSValueMakeUndefined(context);
590 }
591
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");
599         }
600
601         AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_SE_FUNCS);
602         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
603
604         Try {
605                 INFCManagerPtr NFCs( privateObject->getObject() );
606
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");
614         }
615         return JSValueMakeUndefined(context);
616 }
617
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");
626         }
627
628         JSContextRef global_context = privateObject->getContext();
629
630         AceSecurityStatus status = NFC_CHECK_ACCESS(global_context, NFC_FUNCTION_API_TAG_FUNCS);
631         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
632
633 Try {
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");
647         }
648         return JSValueMakeUndefined(context);
649 }
650
651 JSValueRef JSNFCManager::createNDEFMessage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
652         LogDebug("Entered ");
653         Try {
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");
658                 }
659
660                 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
661                 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
662
663                 INFCManagerPtr NFCManager(privateObject->getObject());
664                 NFCConverter convert(context);
665
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);
671                 }
672
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");
685         }
686
687         return JSValueMakeNull(context);
688 }
689
690 JSValueRef JSNFCManager::createNDEFMessageFromRawData(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
691         LogDebug("Entered ");
692         Try {
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");
697                 }
698
699                 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
700                 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
701
702                 INFCManagerPtr NFCManager(privateObject->getObject());
703                 NFCConverter convert(context);
704
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);
710                 }
711
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");
724         }
725
726         return JSValueMakeNull(context);
727 }
728
729 JSValueRef JSNFCManager::createNDEFRecord(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
730         LogDebug("Entered ");
731         Try {
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");
736                 }
737
738                 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
739                 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
740
741                 INFCManagerPtr NFCManager(privateObject->getObject());
742                 NFCConverter convert(context);
743
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);
748                 }
749
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");
762         }
763
764         return JSValueMakeNull(context);
765 }
766
767 JSValueRef JSNFCManager::createNDEFRecordText(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
768         LogDebug("Entered ");
769         Try {
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");
774                 }
775
776                 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
777                 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
778
779                 INFCManagerPtr NFCManager(privateObject->getObject());
780                 NFCConverter convert(context);
781
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);
786                 }
787
788                 short encodeType = NFC_TEXT_ENCODE_UTF_8;
789
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]));
794                 }
795
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");
808         }
809
810         return JSValueMakeNull(context);
811 }
812
813 JSValueRef JSNFCManager::createNDEFRecordURI(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
814         LogDebug("Entered ");
815         Try {
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");
820                 }
821
822                 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
823                 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
824
825                 INFCManagerPtr NFCManager(privateObject->getObject());
826                 NFCConverter convert(context);
827
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);
831                 }
832
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");
845         }
846
847         return JSValueMakeNull(context);
848 }
849
850 JSValueRef JSNFCManager::createNDEFRecordMedia(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
851         LogDebug("Entered ");
852         Try {
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");
857                 }
858
859                 AceSecurityStatus status = NFC_CHECK_ACCESS(privateObject->getContext(),NFC_FUNCTION_API_TAG_P2P_FUNCS);
860                 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
861
862                 INFCManagerPtr NFCManager(privateObject->getObject());
863                 NFCConverter convert(context);
864
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);
869                 }
870
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");
883         }
884
885         return JSValueMakeNull(context);
886 }
887
888 }
889 }