Update change log and spec for wrt-plugins-tizen_0.4.70
[framework/web/wrt-plugins-tizen.git] / src / NFC / JSNFCAdapter.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <string>
19 #include <CommonsJavaScript/Validator.h>
20 #include <Commons/Exception.h>
21 #include <CommonsJavaScript/PrivateObject.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/JSCallbackManager.h>
24 #include <CommonsJavaScript/Utils.h>
25 #include <JSWebAPIErrorFactory.h>
26 #include <SecurityExceptions.h>
27 #include <GlobalContextManager.h>
28 #include <ArgumentValidator.h>
29 #include <JSUtil.h>
30 #include <PlatformException.h>
31
32 #include "JSNFCManager.h"
33 #include "JSNFCAdapter.h"
34 #include "JSNdefMessage.h"
35 #include "JSNdefRecord.h"
36 #include "NFCConverter.h"
37 #include "NFCStaticController.h"
38 #include "EventNFCChangedPrivateData.h"
39 #include "NFCAsyncCallbackManager.h"
40 #include "NFCListenerManager.h"
41 #include "NFCFactory.h"
42 #include "EventNFCChanged.h"
43 #include "plugin_config_impl.h"
44 #include <Logger.h>
45
46 using namespace std;
47
48 using namespace DeviceAPI::Common;
49 using namespace WrtDeviceApis::Commons;
50 using namespace WrtDeviceApis::CommonsJavaScript;
51
52 #define TIZEN_NFCADAPTER_ATTRIBUTENAME "NFCAdapter"
53 #define TIZEN_NFCADAPTER_POWERED "powered"
54
55 namespace DeviceAPI {
56 namespace NFC {
57
58  JSClassDefinition JSNFCAdapter::m_classInfo =
59 {
60         0,
61         kJSClassAttributeNone,
62         TIZEN_NFCADAPTER_ATTRIBUTENAME,
63         0,
64         m_property,
65         m_function,
66         initialize,
67         finalize,
68         NULL, //hasProperty,
69         NULL,
70         NULL, //setProperty,
71         NULL, //DeleteProperty,
72         NULL, //GetPropertyNames,
73         NULL, //CallAsFunction,
74         NULL, //CallAsConstructor,
75         NULL, //HasInstance,
76         NULL  //ConvertToType
77 };
78
79 JSStaticValue JSNFCAdapter::m_property[] =
80 {
81     //NFCAdapterProperties
82         {TIZEN_NFCADAPTER_POWERED,  getProperty, NULL, kJSPropertyAttributeReadOnly},
83         { 0, 0, 0, 0 }
84 };
85
86 JSStaticFunction JSNFCAdapter::m_function[] = {
87         {"setTagListener",      JSNFCAdapter::setTagListener, kJSPropertyAttributeNone },
88         {"unsetTagListener",       JSNFCAdapter::unsetTagListener, kJSPropertyAttributeNone},
89         {"setPeerListener",      JSNFCAdapter::setPeerListener, kJSPropertyAttributeNone },
90         {"unsetPeerListener",       JSNFCAdapter::unsetPeerListener, kJSPropertyAttributeNone},
91         {"getCachedMessage", JSNFCAdapter::getCachedMessage, kJSPropertyAttributeNone},
92         {"setPowered",      JSNFCAdapter::setPowered, kJSPropertyAttributeNone },
93         { 0, 0, 0}
94 };
95
96 JSClassRef JSNFCAdapter::m_jsClassRef = JSClassCreate(JSNFCAdapter::getClassInfo());
97
98 void JSNFCAdapter::initialize(JSContextRef context, JSObjectRef object)
99 {
100         LoggerD("entered. Nothing to do");
101 }
102
103 void JSNFCAdapter::finalize(JSObjectRef object)
104 {
105         NFCAdapterPrivObject* priv =
106                 static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(object));
107         delete priv;
108         JSObjectSetPrivate(object, NULL);
109 }
110
111 JSObjectRef JSNFCAdapter::createJSObject(JSContextRef context, NFCManagerPrivObject *nfcManagerPriv) {
112         LoggerD("entered");
113
114         INFCAdapterPtr nfcAdapter(NFCFactory::getInstance().createNFCAdapterObject());
115         NFCAdapterPrivObject *priv = new NFCAdapterPrivObject(context, nfcAdapter);
116
117         if (!priv) {
118                 ThrowMsg(NullPointerException, "Can not new a NFCTag object");
119         }
120
121         priv->copyAceCheckAccessFunction(nfcManagerPriv);
122         return JSObjectMake(context, getClassRef(), priv);
123 }
124
125 const JSClassRef JSNFCAdapter::getClassRef()
126 {
127         if (!m_jsClassRef) {
128                 m_jsClassRef = JSClassCreate(&m_classInfo);
129         }
130         return m_jsClassRef;
131 }
132
133 const JSClassDefinition* JSNFCAdapter::getClassInfo()
134 {
135         return &m_classInfo;
136 }
137
138 JSValueRef JSNFCAdapter::getProperty(JSContextRef context, JSObjectRef object,
139         JSStringRef propertyName, JSValueRef* exception)
140 {
141         LoggerD("Enter");
142
143         Try     {
144                 NFCConverter convert(context);
145
146                 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_NFCADAPTER_POWERED)) {
147                         NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(object));
148                         if (!privateObject) {
149                                 LoggerE("private object is null");
150                                 ThrowMsg(NullPointerException, "Private object not initialized");
151                         }
152                         INFCAdapterPtr nfcAdapter(privateObject->getObject());
153                         return convert.toJSValueRef(nfcAdapter->getPowerState());
154                 }
155         } Catch (NullPointerException) {
156                 LoggerE("NullPointerException: " << _rethrown_exception.GetMessage());
157         } Catch (ConversionException) {
158                 LoggerE("ConversionException: " << _rethrown_exception.GetMessage());
159         } Catch (UnsupportedException) {
160                 LoggerE("UnsupportedException: " << _rethrown_exception.GetMessage());
161         } Catch (WrtDeviceApis::Commons::UnknownException) {
162                 LoggerE("UnknownExceptionException: " << _rethrown_exception.GetMessage());
163         } Catch (PlatformException) {
164                 LoggerE("PlatformExceptionException: " << _rethrown_exception.GetMessage());
165         } Catch (WrtDeviceApis::Commons::Exception) {
166                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
167         }
168
169     return JSValueMakeUndefined(context);
170 }
171
172 JSValueRef JSNFCAdapter::setTagListener (JSContextRef context, JSObjectRef object,
173                 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
174                 JSValueRef* exception) {
175         LoggerD("JSNFCAdapter::setTagListener Enter");
176
177         NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
178         if (!privateObject) {
179                 LoggerE("private object is null");
180                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
181         }
182
183         TIZEN_CHECK_ACCESS(context, exception, privateObject,
184         NFC_FUNCTION_API_TAG_FUNCS);
185
186         Try {
187                 ArgumentValidator validator(context, argumentCount, arguments);
188                 NFCChangedCallback callbacks;
189                 NFCConverter nfcConverter(context);
190                 if (validator.toObject(0))
191                         callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
192
193                 std::vector<std::string> filterValue = validator.toStringVector(1, true);
194
195                 JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
196                 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
197                 JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
198                 TagFilterPtr tagFilter(new TagFilter());
199                 for (unsigned int i=0; i<filterValue.size(); i++) {
200                         nfcTagType filter = nfcConverter.toNfcTagType(filterValue.at(i));
201
202                         tagFilter->addTagTypeValue(filter);
203                         LoggerD("tag_types.at(i): " << filterValue.at(i));
204                 }
205
206                 INFCAdapterPtr nfcAdapter(privateObject->getObject());
207
208                 EventNFCChangedPrivateDataPtr privateData(
209                     new EventNFCChangedPrivateData(callbackManager,
210                                                     detachedCallbackManager)
211                     );
212                 privateData->copyAceCheckAccessFunction(privateObject);
213         
214                 EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
215                 emitter->setListener(&NFCStaticController::getInstance());
216                 emitter->setEventPrivateData(DPL::StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
217
218                 if (nfcAdapter->setTagListener(emitter, tagFilter) != 0)
219                         Throw(WrtDeviceApis::Commons::UnknownException);
220
221                 NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_TAG_LISTENER)));
222                 IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
223                 NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
224
225                 return JSValueMakeUndefined(context);
226     } Catch (BasePlatformException) {
227         LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
228         return JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
229         } Catch (ConversionException) {
230                 LoggerE("JSNFCAdapter::setTagListener : ConversionException");
231                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
232     } Catch (PlatformException) {
233                 LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
234                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
235         } Catch (WrtDeviceApis::Commons::UnknownException) {
236                 LoggerE("UnknownException: " << _rethrown_exception.GetMessage());
237         } Catch (WrtDeviceApis::Commons::Exception) {
238                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
239         }
240         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
241 }
242
243 JSValueRef JSNFCAdapter::setPeerListener (JSContextRef context, JSObjectRef object,
244                 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
245                 JSValueRef* exception) {
246         LoggerD("JSNFCAdapter::setPeerListener Enter");
247
248         NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
249         if (!privateObject) {
250                 LoggerE("private object is null");
251                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
252         }
253
254         TIZEN_CHECK_ACCESS(context, exception, privateObject,
255         NFC_FUNCTION_API_P2P_FUNCS);
256
257         Try {
258                 ArgumentValidator validator(context, argumentCount, arguments);
259
260                 NFCConverter nfcConverter(context);
261                 NFCChangedCallback callbacks;
262
263                 if (validator.toObject(0))
264                         callbacks = nfcConverter.toNFCChangedCallback(arguments[0]);
265
266                 JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
267                 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, callbacks.onattach, NULL, true, true);
268                 JSCallbackManagerPtr detachedCallbackManager = JSCallbackManager::createObject(global_context, callbacks.ondetach, NULL);
269
270                 INFCAdapterPtr nfcAdapter(privateObject->getObject());
271
272                 EventNFCChangedPrivateDataPtr privateData(
273                     new EventNFCChangedPrivateData(callbackManager,
274                                                     detachedCallbackManager)
275                     );
276
277                 privateData->copyAceCheckAccessFunction(privateObject);
278                 EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
279                 emitter->setListener(&NFCStaticController::getInstance());
280                 emitter->setEventPrivateData(DPL::StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
281
282                 if (nfcAdapter->setPeerListener(emitter) != 0)
283                         Throw(WrtDeviceApis::Commons::UnknownException);
284
285                 NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_PEER_LISTENER)));
286                 IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
287                 NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
288
289                 return JSValueMakeUndefined(context);
290     } Catch (BasePlatformException) {
291         LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
292         return JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
293         } Catch (ConversionException) {
294                 LoggerE("JSNFCAdapter::setPeerListener : ConversionException");
295                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
296         } Catch (PlatformException) {
297                 LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
298                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
299         } Catch (WrtDeviceApis::Commons::UnknownException) {
300                 LoggerE("UnknownException: " << _rethrown_exception.GetMessage());
301         } Catch (WrtDeviceApis::Commons::Exception) {
302                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
303         }
304         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
305 }
306 JSValueRef JSNFCAdapter::unsetTagListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
307                 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
308         LoggerD("JSNFCAdapter::unsetNFCTagListener Enter");
309
310         NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
311         if (!privateObject) {
312                 LoggerE("private object is null");
313                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
314         }
315
316         TIZEN_CHECK_ACCESS(context, exception, privateObject,
317         NFC_FUNCTION_API_TAG_FUNCS);
318
319         Try     {
320                 INFCAdapterPtr nfcAdapter(privateObject->getObject());
321
322                 nfcAdapter->unsetTagListener();
323
324                 NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCADAPTER_TAG_LISTENER)));
325                 IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
326                 NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
327
328                 return JSValueMakeUndefined(context);
329         } Catch (NullPointerException) {
330                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
331         } Catch (PlatformException) {
332                 LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
333                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
334         } Catch (WrtDeviceApis::Commons::Exception) {
335                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
336         }
337         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
338 }
339
340 JSValueRef JSNFCAdapter::unsetPeerListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
341                 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
342         LoggerD("JSNFCAdapter::unsetPeerListener Enter");
343
344         NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
345         if (!privateObject) {
346                 LoggerE("private object is null");
347                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
348         }
349
350         TIZEN_CHECK_ACCESS(context, exception, privateObject,
351         NFC_FUNCTION_API_P2P_FUNCS);
352         Try {
353                 INFCAdapterPtr nfcAdapter( privateObject->getObject());
354
355                 nfcAdapter->unsetPeerListener();
356
357                 NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCADAPTER_PEER_LISTENER)));
358                 IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
359                 NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
360
361                 return JSValueMakeUndefined(context);
362         } Catch (NullPointerException) {
363                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
364         } Catch (PlatformException) {
365                 LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
366                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
367         } Catch (WrtDeviceApis::Commons::Exception) {
368                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
369         }
370         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
371 }
372
373 JSValueRef JSNFCAdapter::getCachedMessage (JSContextRef context, JSObjectRef object,
374                 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
375                 JSValueRef* exception) {
376         LoggerD("JSNFCAdapter::getCachedMessage Enter");
377
378         NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
379         if (!privateObject) {
380                 LoggerE("private object is null");
381                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
382         }
383
384         TIZEN_CHECK_ACCESS(context, exception, privateObject,
385         NFC_FUNCTION_API_COMMON_FUNCS);
386
387         Try {
388                 INFCAdapterPtr nfcAdapter(privateObject->getObject());
389                 void *cachedMessage = nfcAdapter->getCachedMessage();
390                 if (cachedMessage != NULL) {
391                         JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
392                         return JSNdefMessage::createJSObject(global_context, cachedMessage);
393                 }
394                 return JSValueMakeNull(context);
395         } Catch (WrtDeviceApis::Commons::UnknownException) {
396                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
397         } Catch (PlatformException) {
398                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
399                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available");
400         } Catch(NullPointerException) {
401                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
402                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
403         } Catch (WrtDeviceApis::Commons::Exception) {
404                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
405         }
406         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
407 }
408
409 JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
410                 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
411                 JSValueRef* exception) {
412         LoggerD("Enter");
413
414         NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(thisObject));
415         if (!privateObject) {
416                 LoggerE("private object is null");
417                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
418         }
419
420         TIZEN_CHECK_ACCESS(context, exception, privateObject,
421         NFC_FUNCTION_API_ADMIN_FUNCS);
422
423         JSContextRef global_context = GlobalContextManager::getInstance()->getGlobalContext(context);
424         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, NULL, NULL, true, true);
425
426         Try {
427                 ArgumentValidator validator(context, argumentCount, arguments);
428
429                 // state
430         bool state = validator.toBool(0);
431                 // successCallback
432                 if (validator.toFunction(1, true))
433                         callbackManager->setOnSuccess(arguments[1]);
434                 // errorCallback
435                 if (validator.toFunction(2, true))
436                         callbackManager->setOnError(arguments[2]);
437
438                 EventNFCChangedSetPoweredPtr event(new EventNFCChangedSetPowered(state));
439                 event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager) );
440                 event->setForAsynchronousCall(&NFCStaticController::getInstance());
441                 callbackManager->setObject(thisObject);
442                 INFCAdapterPtr nfcAdapter(privateObject->getObject());
443                 nfcAdapter->setPowered(event);
444                 NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
445                 return JSValueMakeUndefined(context);
446     } Catch (BasePlatformException) {
447         LoggerE(_rethrown_exception.getName() << ": " << _rethrown_exception.getMessage());
448         return JSWebAPIErrorFactory::postException(context, exception, _rethrown_exception);
449         } Catch (ConversionException) {
450                 LoggerE("ConversionException");
451                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
452         } Catch (PlatformException) {
453                 LoggerE("PlatformException: " << _rethrown_exception.GetMessage());
454                 callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::SERVICE_NOT_AVAILABLE_ERROR, "Service Not Available"));
455                 return JSValueMakeUndefined(context);
456         } Catch (WrtDeviceApis::Commons::UnknownException) {
457                 LoggerE("UnknownException: " << _rethrown_exception.GetMessage());
458         } Catch(NullPointerException) {
459                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
460                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
461         } Catch (WrtDeviceApis::Commons::Exception) {
462                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
463         }
464         callbackManager->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR,"Unknown Error"));
465         return JSValueMakeUndefined(context);
466 }
467
468
469 }
470 }