2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file JSContactManager.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
25 #include "JSContactManager.h"
28 #include <CommonsJavaScript/JSCallbackManager.h>
29 #include <CommonsJavaScript/Validator.h>
30 #include <CommonsJavaScript/Converter.h>
31 #include <CommonsJavaScript/JSUtils.h>
32 #include <CommonsJavaScript/JSPendingOperation.h>
33 #include <SecurityExceptions.h>
34 #include <FilterConverter.h>
35 #include "ContactFactory.h"
36 #include "ContactTypes.h"
37 #include "plugin_config.h"
38 #include "ContactManagerController.h"
39 #include "ContactAsyncCallbackManager.h"
40 #include "ContactListenerManager.h"
41 #include "ContactConverter.h"
43 #include "JSContactManagerChangeCallbackManager.h"
44 #include "ContactFilterConverter.h"
45 #include <ArgumentValidator.h>
46 #include <JSWebAPIErrorFactory.h>
47 #include <TimeTracer.h>
54 using namespace DeviceAPI::Common;
55 using namespace DeviceAPI::Tizen;
56 using namespace WrtDeviceApis::Commons;
57 using namespace WrtDeviceApis::CommonsJavaScript;
59 JSClassDefinition JSContactManager::m_classInfo = {
61 kJSClassAttributeNone,
71 NULL, //DeleteProperty,
72 NULL, //GetPropertyNames,
73 NULL, //CallAsFunction,
74 NULL, //CallAsConstructor,
76 NULL, //ConvertToType,
79 const JSClassDefinition* JSContactManager::getClassInfo()
84 JSStaticValue JSContactManager::m_property[] = {
88 JSStaticFunction JSContactManager::m_function[] = {
89 { "getAddressBooks", getAddressBooks, kJSPropertyAttributeNone },
90 { "getDefaultAddressBook", getDefaultAddressBook, kJSPropertyAttributeNone },
91 { "getUnifiedAddressBook", getUnifiedAddressBook, kJSPropertyAttributeNone },
92 { "getAddressBook", getAddressBook, kJSPropertyAttributeNone },
93 { "get", get, kJSPropertyAttributeNone },
94 { "update", update, kJSPropertyAttributeNone },
95 { "updateBatch", updateBatch, kJSPropertyAttributeNone },
96 { "remove", remove, kJSPropertyAttributeNone },
97 { "removeBatch", removeBatch, kJSPropertyAttributeNone },
98 { "find", find, kJSPropertyAttributeNone },
99 { "addChangeListener", addChangeListener, kJSPropertyAttributeNone },
100 { "removeChangeListener", removeChangeListener, kJSPropertyAttributeNone },
104 JSClassRef DLL_EXPORT JSContactManager::getClassRef()
107 m_classRef = JSClassCreate(&m_classInfo);
112 JSClassRef JSContactManager::m_classRef = JSClassCreate(JSContactManager::getClassInfo());
114 void JSContactManager::Initialize(JSContextRef context,
118 ContactManagerPtr contactManager = ContactFactory::getInstance().createContactManager();
120 ContactManagerController *priv = new ContactManagerController(context, contactManager);
122 JSObjectSetPrivate(object, static_cast<void*>(priv));
125 void JSContactManager::Finalize(JSObjectRef object)
128 ContactManagerController *priv = static_cast<ContactManagerController*>(JSObjectGetPrivate(object));
129 LoggerI("Delete address book manager");
133 JSValueRef JSContactManager::getAddressBooks(JSContextRef context,
135 JSObjectRef thisObject,
136 size_t argumentCount,
137 const JSValueRef arguments[],
138 JSValueRef* exception)
141 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
142 ContactManagerPtr contactManager;
143 JSContextRef gContext;
144 ContactManagerController *controller;
146 bool js2ndParamIsFunction = false;
149 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
151 ThrowMsg(InvalidArgumentException, "No private object.");
153 contactManager = controller->getObject();
154 gContext = controller->getContext();
156 LoggerE("No private object");
157 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
160 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOKS);
161 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
163 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
165 ArgumentValidator validator(context, argumentCount, arguments);
166 validator.toFunction(0, false);
167 JSObjectRef errorObj = validator.toFunction(1, true);
169 js2ndParamIsFunction = true;
170 } catch (const TypeMismatchException& err ) {
171 return JSWebAPIErrorFactory::postException(context, exception, err);
172 } catch(const BasePlatformException& err) {
173 return JSWebAPIErrorFactory::postException(context, exception, err);
174 } catch(const ConversionException& err) {
175 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
176 } catch(const NullPointerException& err) {
177 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
180 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
182 callbackManager->setOnSuccess(arguments[0]);
184 if(js2ndParamIsFunction)
185 callbackManager->setOnError(arguments[1]);
187 callbackManager->setObject(thisObject);
189 EventContactManagerGetAddressBooksPtr dplEvent(new EventContactManagerGetAddressBooks());
191 // set event handler's data
192 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
193 dplEvent->setForAsynchronousCall(controller);
195 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
196 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
199 contactManager->getAddressBooks(dplEvent);
200 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
202 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
203 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
206 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
207 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
208 return JSValueMakeUndefined(context);
211 JSValueRef JSContactManager::getDefaultAddressBook(JSContextRef context,
213 JSObjectRef thisObject,
214 size_t argumentCount,
215 const JSValueRef arguments[],
216 JSValueRef* exception)
219 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
220 ContactManagerController *priv =
221 static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
223 LoggerE("private object is null");
224 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
227 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK);
228 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
230 ContactManagerPtr contactManager;
231 JSContextRef gContext;
233 contactManager = priv->getObject();
234 gContext = priv->getContext();
236 LoggerE("contact manager or context is null");
237 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
240 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
242 EventContactManagerGetDefaultAddressBookPtr dplEvent(new EventContactManagerGetDefaultAddressBook());
244 dplEvent->setForSynchronousCall();
247 contactManager->getDefaultAddressBook(dplEvent);
249 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
250 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
253 if (!dplEvent->getResult() || !dplEvent->getDefaultAddressBookIsSet())
255 std::stringstream oss;
256 switch (dplEvent->getExceptionCode())
258 case ExceptionCodes::NotFoundException:
259 case ExceptionCodes::InvalidArgumentException:
260 LoggerE("Not Found error");
261 oss << "No default address book";
262 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
264 case ExceptionCodes::PlatformException:
265 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
268 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
273 AddressBookPtr defaultAddressBook = dplEvent->getDefaultAddressBook();
275 JSValueRef resultValue;
277 resultValue = converter->toJSValueRef(defaultAddressBook);
279 LoggerE("Conversion error.");
280 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
283 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
287 JSValueRef JSContactManager::getUnifiedAddressBook(JSContextRef context,
289 JSObjectRef thisObject,
290 size_t argumentCount,
291 const JSValueRef arguments[],
292 JSValueRef* exception)
295 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
296 ContactManagerController *priv =
297 static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
299 LoggerE("private object is null");
300 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
303 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_UNIFIED_ADDRESS_BOOK);
304 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
306 ContactManagerPtr contactManager;
307 JSContextRef gContext;
309 contactManager = priv->getObject();
310 gContext = priv->getContext();
312 LoggerE("contact manager or context is null");
313 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
316 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
318 EventContactManagerGetUnifiedAddressBookPtr dplEvent(new EventContactManagerGetUnifiedAddressBook());
320 dplEvent->setForSynchronousCall();
323 contactManager->getUnifiedAddressBook(dplEvent);
325 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
326 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
329 if (!dplEvent->getResult() || !dplEvent->getUnifiedAddressBookIsSet())
331 std::stringstream oss;
332 switch (dplEvent->getExceptionCode())
334 case ExceptionCodes::NotFoundException:
335 case ExceptionCodes::InvalidArgumentException:
336 LoggerE("Not Found error");
337 oss << "No default address book";
338 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
340 case ExceptionCodes::PlatformException:
341 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
344 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
349 AddressBookPtr unifiedAddressBook = dplEvent->getUnifiedAddressBook();
351 JSValueRef resultValue;
353 resultValue = converter->toJSValueRef(unifiedAddressBook);
355 LoggerE("Conversion error.");
356 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
359 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
363 JSValueRef JSContactManager::getAddressBook(JSContextRef context,
365 JSObjectRef thisObject,
366 size_t argumentCount,
367 const JSValueRef arguments[],
368 JSValueRef* exception)
371 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
372 ContactManagerController *priv =
373 static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
375 LoggerE("private object is null");
376 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
379 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOK);
380 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
382 ContactManagerPtr contactManager;
383 JSContextRef gContext;
385 contactManager = priv->getObject();
386 gContext = priv->getContext();
388 LoggerE("contact manager or context is null");
389 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
392 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
394 std::string addressBookId;
396 ArgumentValidator validator(context, argumentCount, arguments);
397 addressBookId = validator.toString(0, false);
398 } catch (const TypeMismatchException& err ) {
399 return JSWebAPIErrorFactory::postException(context, exception, err);
400 } catch(const BasePlatformException& err) {
401 return JSWebAPIErrorFactory::postException(context, exception, err);
402 } catch(const ConversionException& err) {
403 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
404 } catch(const NullPointerException& err) {
405 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
408 EventContactManagerGetAddressBookPtr dplEvent(new EventContactManagerGetAddressBook());
410 dplEvent->setAddressBookId(addressBookId);
411 dplEvent->setForSynchronousCall();
414 contactManager->getAddressBook(dplEvent);
416 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
417 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
420 if (!dplEvent->getResult() || !dplEvent->getAddressBookIsSet())
422 std::stringstream oss;
423 switch (dplEvent->getExceptionCode())
425 case ExceptionCodes::NotFoundException:
426 case ExceptionCodes::InvalidArgumentException:
427 LoggerE("Not Found error : " << addressBookId);
428 oss << "No addressBookId id '" << addressBookId << "'";
429 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
431 case ExceptionCodes::PlatformException:
432 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
435 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
440 AddressBookPtr addressBook = dplEvent->getAddressBook();
442 JSValueRef resultValue;
444 resultValue = converter->toJSValueRef(addressBook);
446 LoggerE("Conversion error.");
447 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
450 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
454 JSValueRef JSContactManager::get(JSContextRef context,
456 JSObjectRef thisObject,
457 size_t argumentCount,
458 const JSValueRef arguments[],
459 JSValueRef* exception)
462 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
463 ContactManagerPtr addressBook;
464 ContactManagerController *controller;
467 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
469 ThrowMsg(InvalidArgumentException, "No private object.");
471 addressBook = controller->getObject();
473 LoggerE("No private object");
474 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
477 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET);
478 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
480 if (argumentCount < 1) {
481 /* 1st Argument must be string. */
482 LoggerE("1st argument must not be undefined.");
483 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "No id 'undefined'");
488 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
490 ArgumentValidator validator(context, argumentCount, arguments);
491 id = validator.toString(0, false);
492 } catch (const TypeMismatchException& err ) {
493 return JSWebAPIErrorFactory::postException(context, exception, err);
494 } catch(const BasePlatformException& err) {
495 return JSWebAPIErrorFactory::postException(context, exception, err);
496 } catch(const ConversionException& err) {
497 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
498 } catch(const NullPointerException& err) {
499 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
502 EventContactManagerGetPtr dplEvent(new EventContactManagerGet());
505 dplEvent->setForSynchronousCall();
508 addressBook->get(dplEvent);
510 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
511 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
514 if (!dplEvent->getResult() || !dplEvent->getPersonIsSet())
516 std::stringstream oss;
517 switch (dplEvent->getExceptionCode())
519 case ExceptionCodes::NotFoundException:
520 case ExceptionCodes::InvalidArgumentException:
521 LoggerE("Not Found error : " << id);
522 oss << "No Person id '" << id << "'";
523 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
525 case ExceptionCodes::PlatformException:
526 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
529 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
534 PersonPtr person = dplEvent->getPerson();
538 result = converter->toJSValueRef(person);
540 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
541 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
544 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
548 JSValueRef JSContactManager::update(JSContextRef context,
550 JSObjectRef thisObject,
551 size_t argumentCount,
552 const JSValueRef arguments[],
553 JSValueRef* exception)
556 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
557 ContactManagerPtr addressBook;
558 ContactManagerController *controller;
561 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
563 ThrowMsg(InvalidArgumentException, "No private object.");
565 addressBook = controller->getObject();
567 LoggerE("No private object");
568 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
571 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE);
572 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
575 ArgumentValidator validator(context, argumentCount, arguments);
576 validator.toObject(0, false);
577 } catch (const TypeMismatchException& err ) {
578 return JSWebAPIErrorFactory::postException(context, exception, err);
579 } catch(const BasePlatformException& err) {
580 return JSWebAPIErrorFactory::postException(context, exception, err);
581 } catch(const ConversionException& err) {
582 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
583 } catch(const NullPointerException& err) {
584 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
587 PersonPtr person(NULL);
589 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
591 if (!JSPerson::isObjectOfClass(context, arguments[0]))
592 ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
593 person = converter->toPerson(arguments[0]);
595 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
596 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument is not a 'Contact object'");
599 EventContactManagerUpdatePtr dplEvent(new EventContactManagerUpdate());
601 dplEvent->setPerson(person);
602 dplEvent->setForSynchronousCall();
605 addressBook->update(dplEvent);
607 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
608 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
611 if (!dplEvent->getResult())
613 std::stringstream oss;
614 switch (dplEvent->getExceptionCode())
616 case ExceptionCodes::NotFoundException:
617 case ExceptionCodes::InvalidArgumentException:
618 oss << "No id '" << person->getId() << "'";
619 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
621 case ExceptionCodes::PlatformException:
622 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
625 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
630 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
631 return JSValueMakeUndefined(context);
634 JSValueRef JSContactManager::updateBatch(JSContextRef context,
636 JSObjectRef thisObject,
637 size_t argumentCount,
638 const JSValueRef arguments[],
639 JSValueRef* exception)
642 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
643 ContactManagerPtr addressBook;
644 JSContextRef gContext;
645 ContactManagerController *controller;
647 bool js2ndParamIsFunction = false;
648 bool js3rdParamIsFunction = false;
651 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
653 ThrowMsg(InvalidArgumentException, "No private object.");
655 addressBook = controller->getObject();
656 gContext = controller->getContext();
658 LoggerE("No private object");
659 return JSWebAPIErrorFactory::postException(context, exception,
660 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
663 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE_BATCH);
664 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
667 ArgumentValidator validator(context, argumentCount, arguments);
669 validator.toObject(0, false);
670 JSObjectRef successObj = validator.toFunction(1, true);
672 js2ndParamIsFunction = true;
674 JSObjectRef errorObj = validator.toFunction(2, true);
676 js3rdParamIsFunction = true;
677 } catch (const TypeMismatchException& err ) {
678 return JSWebAPIErrorFactory::postException(context, exception, err);
679 } catch(const BasePlatformException& err) {
680 return JSWebAPIErrorFactory::postException(context, exception, err);
681 } catch(const ConversionException& err) {
682 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
683 } catch(const NullPointerException& err) {
684 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
687 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
689 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
691 if(js2ndParamIsFunction)
692 callbackManager->setOnSuccess(arguments[1]);
694 if(js3rdParamIsFunction)
695 callbackManager->setOnError(arguments[2]);
697 callbackManager->setObject(thisObject);
699 EventContactManagerUpdateBatchPtr dplEvent(new EventContactManagerUpdateBatch());
701 dplEvent->setPersons(converter->toPersonArray(arguments[0]));
702 } Catch(ConversionException) {
703 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
704 return JSWebAPIErrorFactory::postException(context, exception,
705 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be a 'function' or a 'null'");
708 // set event handler's data
709 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
710 dplEvent->setForAsynchronousCall(controller);
712 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
713 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
716 addressBook->updateBatch(dplEvent);
717 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
719 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
720 return JSWebAPIErrorFactory::postException(context, exception,
721 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
724 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
725 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
726 return JSValueMakeUndefined(context);
729 JSValueRef JSContactManager::remove(JSContextRef context,
731 JSObjectRef thisObject,
732 size_t argumentCount,
733 const JSValueRef arguments[],
734 JSValueRef* exception)
737 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
738 ContactManagerPtr addressBook;
739 ContactManagerController *controller;
742 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
744 ThrowMsg(InvalidArgumentException, "No private object.");
746 addressBook = controller->getObject();
748 LoggerE("No private object");
749 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
752 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE);
753 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
755 std::string personId;
757 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
759 ArgumentValidator validator(context, argumentCount, arguments);
760 personId = validator.toString(0, false);
761 } catch (const TypeMismatchException& err ) {
762 return JSWebAPIErrorFactory::postException(context, exception, err);
763 } catch(const BasePlatformException& err) {
764 return JSWebAPIErrorFactory::postException(context, exception, err);
765 } catch(const ConversionException& err) {
766 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
767 } catch(const NullPointerException& err) {
768 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
771 EventContactManagerRemovePtr dplEvent(new EventContactManagerRemove());
773 dplEvent->setPersonId(personId);
774 dplEvent->setForSynchronousCall();
777 addressBook->remove(dplEvent);
779 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
780 return JSWebAPIErrorFactory::postException(context, exception,
781 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
784 if (!dplEvent->getResult())
786 std::stringstream oss;
787 switch (dplEvent->getExceptionCode())
789 case ExceptionCodes::NotFoundException:
790 case ExceptionCodes::InvalidArgumentException:
791 LoggerE("Not Found error : " << personId);
792 oss << "No id '" << personId << "'";
793 return JSWebAPIErrorFactory::postException(context, exception,
794 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
796 case ExceptionCodes::PlatformException:
797 return JSWebAPIErrorFactory::postException(context, exception,
798 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
801 return JSWebAPIErrorFactory::postException(context, exception,
802 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
807 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
808 return JSValueMakeUndefined(context);
811 JSValueRef JSContactManager::removeBatch(JSContextRef context,
813 JSObjectRef thisObject,
814 size_t argumentCount,
815 const JSValueRef arguments[],
816 JSValueRef* exception)
819 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
820 ContactManagerPtr addressBook;
821 JSContextRef gContext;
822 ContactManagerController *controller;
824 bool js2ndParamIsFunction = false;
825 bool js3rdParamIsFunction = false;
828 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
830 ThrowMsg(InvalidArgumentException, "No private object.");
832 addressBook = controller->getObject();
833 gContext = controller->getContext();
835 LoggerE("No private object");
836 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
839 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_BATCH);
840 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
843 ArgumentValidator validator(context, argumentCount, arguments);
845 validator.toObject(0, false);
846 JSObjectRef successObj = validator.toFunction(1, true);
848 js2ndParamIsFunction = true;
850 JSObjectRef errorObj = validator.toFunction(2, true);
852 js3rdParamIsFunction = true;
853 } catch (const TypeMismatchException& err ) {
854 return JSWebAPIErrorFactory::postException(context, exception, err);
855 } catch(const BasePlatformException& err) {
856 return JSWebAPIErrorFactory::postException(context, exception, err);
857 } catch(const ConversionException& err) {
858 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
859 } catch(const NullPointerException& err) {
860 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
863 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
865 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
867 if(js2ndParamIsFunction)
868 callbackManager->setOnSuccess(arguments[1]);
870 if(js3rdParamIsFunction)
871 callbackManager->setOnError(arguments[2]);
873 callbackManager->setObject(thisObject);
875 EventContactManagerRemoveBatchPtr dplEvent(new EventContactManagerRemoveBatch());
877 dplEvent->setPersonIds(converter->toStringArray(arguments[0]));
878 } Catch(ConversionException) {
879 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
880 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact id'");
883 // set event handler's data
884 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
885 dplEvent->setForAsynchronousCall(controller);
887 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
888 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
891 addressBook->removeBatch(dplEvent);
892 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
894 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
895 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
898 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
899 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
900 return JSValueMakeUndefined(context);
903 JSValueRef JSContactManager::find(JSContextRef context,
905 JSObjectRef thisObject,
906 size_t argumentCount,
907 const JSValueRef arguments[],
908 JSValueRef* exception)
911 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
912 ContactManagerPtr addressBook;
913 JSContextRef gContext;
914 ContactManagerController *controller;
916 bool js2ndParamIsFunction = false;
917 bool js3rdParamIsObject = false;
918 bool js4thParamIsObject = false;
921 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
923 ThrowMsg(InvalidArgumentException, "No private object.");
925 addressBook = controller->getObject();
926 gContext = controller->getContext();
928 LoggerE("No private object");
929 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
932 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_FIND);
933 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
936 ArgumentValidator validator(context, argumentCount, arguments);
938 validator.toFunction(0, false);
939 JSObjectRef errorObj = validator.toFunction(1, true);
941 js2ndParamIsFunction = true;
943 JSObjectRef filterObj = validator.toObject(2, true);
945 js3rdParamIsObject = true;
947 JSObjectRef sortObj = validator.toObject(3, true);
949 js4thParamIsObject = true;
951 } catch (const TypeMismatchException& err ) {
952 return JSWebAPIErrorFactory::postException(context, exception, err);
953 } catch(const BasePlatformException& err) {
954 return JSWebAPIErrorFactory::postException(context, exception, err);
955 } catch(const ConversionException& err) {
956 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
957 } catch(const NullPointerException& err) {
958 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
961 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
963 callbackManager->setOnSuccess(arguments[0]);
965 if (js2ndParamIsFunction)
966 callbackManager->setOnError(arguments[1]);
968 callbackManager->setObject(thisObject);
970 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
971 PersonFilterConverterFactory::ConverterType filterConverter = PersonFilterConverterFactory::getConverter(context);
973 EventContactManagerFindPtr dplEvent(new EventContactManagerFind());
975 if (js3rdParamIsObject){
976 FilterPtr filter = filterConverter->toFilter(arguments[2]);
978 dplEvent->setFilter(filter);
980 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an Correct 'Filter object' or 'null'");
983 LoggerE("Error on 3rd parameter conversion : " << _rethrown_exception.GetMessage());
984 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an 'Filter object' or 'null'");
988 if (js4thParamIsObject){
989 SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
990 dplEvent->setSortMode(sortMode);
993 LoggerE("Error on 4th parameter conversion : " << _rethrown_exception.GetMessage());
994 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "4th argument must be an 'SortMode object' or 'null'");
997 // set event handler's data
998 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
999 dplEvent->setForAsynchronousCall(controller);
1001 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
1002 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
1005 addressBook->find(dplEvent);
1006 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
1007 } Catch(Exception) {
1008 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1009 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1012 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1013 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
1014 return JSValueMakeUndefined(context);
1017 JSValueRef JSContactManager::addChangeListener(JSContextRef context,
1019 JSObjectRef thisObject,
1020 size_t argumentCount,
1021 const JSValueRef arguments[],
1022 JSValueRef* exception)
1025 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1026 ContactManagerPtr addressBook;
1027 JSContextRef gContext;
1028 ContactManagerController *controller;
1030 bool js2ndParamIsFunction = false;
1033 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
1035 ThrowMsg(InvalidArgumentException, "No private object.");
1037 addressBook = controller->getObject();
1038 gContext = controller->getContext();
1039 } Catch(Exception) {
1040 LoggerE("No private object");
1041 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1044 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_ADD_CHANGE_LISTENER);
1045 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1047 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
1049 ArgumentValidator Argvalidator(context, argumentCount, arguments);
1051 Argvalidator.toObject(0, false);
1052 JSObjectRef errorObj = Argvalidator.toFunction(1, true);
1054 js2ndParamIsFunction = true;
1056 } catch (const TypeMismatchException& err ) {
1057 return JSWebAPIErrorFactory::postException(context, exception, err);
1058 } catch(const BasePlatformException& err) {
1059 return JSWebAPIErrorFactory::postException(context, exception, err);
1060 } catch(const ConversionException& err) {
1061 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1062 } catch(const NullPointerException& err) {
1063 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1066 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1068 JSValueRef onpersonsadded;
1069 JSValueRef onpersonsupdated;
1070 JSValueRef onpersonsdeleted;
1072 JSObjectRef callbackObject = converter->toJSObjectRef(arguments[0]);
1074 onpersonsadded = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onpersonsadded");
1075 if (validator->isNullOrUndefined(onpersonsadded))
1076 onpersonsadded = NULL;
1077 else if (!validator->isCallback(onpersonsadded)) {
1078 ThrowMsg(ConversionException, "2nd argument's onpersonsadded attribute is not a 'function'");
1081 onpersonsupdated = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onpersonsupdated");
1082 if (validator->isNullOrUndefined(onpersonsupdated))
1083 onpersonsupdated = NULL;
1084 else if (!validator->isCallback(onpersonsupdated)) {
1085 ThrowMsg(ConversionException, "2nd argument's onpersonsupdated attribute is not a 'function'");
1088 onpersonsdeleted = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onpersonsremoved");
1089 if (validator->isNullOrUndefined(onpersonsdeleted))
1090 onpersonsdeleted = NULL;
1091 else if (!validator->isCallback(onpersonsdeleted)) {
1092 ThrowMsg(ConversionException, "2nd argument's onpersonsremoved attribute is not a 'function'");
1095 if (onpersonsadded == NULL && onpersonsupdated == NULL && onpersonsdeleted == NULL)
1096 ThrowMsg(ConversionException, "invalid 2nd argument");
1098 } Catch(ConversionException) {
1099 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1100 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1103 JSContactManagerChangeCallbackManagerPtr callbackManager = JSContactManagerChangeCallbackManager::createObject(gContext);
1105 callbackManager->setOnPersonsAdded(onpersonsadded);
1106 callbackManager->setOnPersonsUpdated(onpersonsupdated);
1107 callbackManager->setOnPersonsDeleted(onpersonsdeleted);
1108 if(js2ndParamIsFunction)
1109 callbackManager->setOnError(arguments[1]);
1111 EventContactManagerChangeListenerEmitterPtr emitter(new EventContactManagerChangeListenerEmitter());
1113 emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
1114 emitter->setListener(controller);
1116 EventContactManagerAddChangeListenerPtr dplEvent(new EventContactManagerAddChangeListener());
1118 dplEvent->setEmitter(emitter);
1119 dplEvent->setForSynchronousCall();
1122 addressBook->addChangeListener(dplEvent);
1123 } Catch(Exception) {
1124 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1125 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1128 if (!dplEvent->getResult() || !dplEvent->getIdIsSet())
1130 switch (dplEvent->getExceptionCode())
1132 case ExceptionCodes::InvalidArgumentException:
1133 case ExceptionCodes::PlatformException:
1134 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1137 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1142 long watchId = dplEvent->getId();
1144 PersonsChangeListenerCancellerPtr canceller = PersonsChangeListenerCancellerPtr(new PersonsChangeListenerCanceller(gContext, thisObject, watchId));
1145 DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1146 ContactListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
1150 result = converter->toJSValueRefLong(watchId);
1151 } Catch(Exception) {
1152 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1153 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1155 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1159 JSValueRef JSContactManager::removeChangeListener(JSContextRef context,
1161 JSObjectRef thisObject,
1162 size_t argumentCount,
1163 const JSValueRef arguments[],
1164 JSValueRef* exception)
1167 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1168 ContactManagerPtr addressBook;
1169 JSContextRef gContext;
1170 ContactManagerController *controller;
1173 controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
1175 ThrowMsg(InvalidArgumentException, "No private object.");
1177 addressBook = controller->getObject();
1178 gContext = controller->getContext();
1179 } Catch(Exception) {
1180 LoggerE("No private object");
1181 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1184 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER);
1185 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1187 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1191 ArgumentValidator validator(context, argumentCount, arguments);
1192 watchId = validator.toLong(0, false, 0);
1193 } catch (const TypeMismatchException& err ) {
1194 return JSWebAPIErrorFactory::postException(context, exception, err);
1195 } catch(const BasePlatformException& err) {
1196 return JSWebAPIErrorFactory::postException(context, exception, err);
1197 } catch(const ConversionException& err) {
1198 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1199 } catch(const NullPointerException& err) {
1200 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1203 EventContactManagerRemoveChangeListenerPtr dplEvent(new EventContactManagerRemoveChangeListener());
1205 dplEvent->setId(watchId);
1206 dplEvent->setForSynchronousCall();
1209 addressBook->removeChangeListener(dplEvent);
1210 } Catch(Exception) {
1211 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1212 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1215 PersonsChangeListenerCancellerPtr canceller = PersonsChangeListenerCancellerPtr(new PersonsChangeListenerCanceller(gContext, thisObject, watchId));
1216 DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1217 ContactListenerManagerSingleton::Instance().unregisterListener(listenerItem);
1219 if (!dplEvent->getResult())
1221 switch (dplEvent->getExceptionCode())
1223 case ExceptionCodes::InvalidArgumentException:
1224 case ExceptionCodes::NotFoundException:
1225 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "Watch id not found");
1228 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1232 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1233 return JSValueMakeUndefined(context);