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 JSAddressBook.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
22 * @brief Implementation of the JSAddressBook class
25 #include <CommonsJavaScript/Validator.h>
26 #include <CommonsJavaScript/Converter.h>
27 #include <CommonsJavaScript/JSCallbackManager.h>
28 #include <CommonsJavaScript/JSUtils.h>
29 #include <CommonsJavaScript/JSPendingOperation.h>
30 #include <SecurityExceptions.h>
31 #include <FilterConverter.h>
32 #include "ContactFactory.h"
33 #include "EventAddressBookAddBatch.h"
34 #include "EventAddressBookUpdateBatch.h"
35 #include "EventAddressBookRemoveBatch.h"
36 #include "EventAddressBookFind.h"
37 #include "EventAddressBookChangeListener.h"
38 #include "EventAddressBookRemoveBatch.h"
39 #include "plugin_config.h"
40 #include "JSAddressBook.h"
41 #include "JSContact.h"
42 #include "JSContactGroup.h"
43 #include "ContactConverter.h"
44 #include "AddressBookController.h"
45 #include "JSAddressBookChangeCallbackManager.h"
46 #include "ContactAsyncCallbackManager.h"
47 #include "ContactListenerManager.h"
48 #include "ContactFilterConverter.h"
49 #include <ArgumentValidator.h>
50 #include <JSWebAPIErrorFactory.h>
52 #include <TimeTracer.h>
57 #define TIZEN_ADDRESS_BOOK_ID "id"
58 #define TIZEN_ADDRESS_BOOK_NAME "name"
59 #define TIZEN_ADDRESS_BOOK_READ_ONLY "readOnly"
60 #define TIZEN_ADDRESS_BOOK_ACCOUNT_ID "accountId"
62 #define TIZEN_ADDRESS_BOOK "AddressBook"
67 using namespace DeviceAPI::Common;
68 using namespace DeviceAPI::Tizen;
69 using namespace WrtDeviceApis::Commons;
70 using namespace WrtDeviceApis::CommonsJavaScript;
72 JSClassRef JSAddressBook::m_jsClassRef = NULL;
74 JSClassDefinition JSAddressBook::m_classInfo = {
76 kJSClassAttributeNone,
86 NULL, //DeleteProperty,
87 NULL, //GetPropertyNames,
88 NULL, //CallAsFunction,
89 NULL, //CallAsConstructor,
91 NULL, //ConvertToType,
94 JSStaticValue JSAddressBook::m_property[] = {
95 { TIZEN_ADDRESS_BOOK_ID, getId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
96 { TIZEN_ADDRESS_BOOK_NAME, getName, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
97 { TIZEN_ADDRESS_BOOK_READ_ONLY, getReadOnly, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
98 // { TIZEN_ADDRESS_BOOK_ACCOUNT_ID, getAccountId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
102 JSStaticFunction JSAddressBook::m_function[] = {
103 { "get", get, kJSPropertyAttributeNone },
104 { "add", add, kJSPropertyAttributeNone },
105 { "addBatch", addBatch, kJSPropertyAttributeNone },
106 { "update", update, kJSPropertyAttributeNone },
107 { "updateBatch", updateBatch, kJSPropertyAttributeNone },
108 { "remove", remove, kJSPropertyAttributeNone },
109 { "removeBatch", removeBatch, kJSPropertyAttributeNone },
110 { "find", find, kJSPropertyAttributeNone },
111 { "addChangeListener", addChangeListener, kJSPropertyAttributeNone },
112 { "removeChangeListener", removeChangeListener, kJSPropertyAttributeNone },
113 { "getGroup", getGroup, kJSPropertyAttributeNone },
114 { "addGroup", addGroup, kJSPropertyAttributeNone },
115 { "updateGroup", updateGroup, kJSPropertyAttributeNone },
116 { "removeGroup", removeGroup, kJSPropertyAttributeNone },
117 { "getGroups", getGroups, kJSPropertyAttributeNone },
121 const JSClassDefinition* JSAddressBook::getClassInfo()
126 const JSClassRef JSAddressBook::getClassRef()
130 m_jsClassRef = JSClassCreate(&m_classInfo);
135 void JSAddressBook::Initialize(JSContextRef context,
138 // AddressBookController *priv =
139 // static_cast<AddressBookController*>(JSObjectGetPrivate(object));
142 void JSAddressBook::Finalize(JSObjectRef object)
144 AddressBookController *priv =
145 static_cast<AddressBookController*>(JSObjectGetPrivate(object));
150 bool JSAddressBook::isObjectOfClass(JSContextRef context, JSValueRef value)
152 return JSValueIsObjectOfClass(context, value, getClassRef());
155 AddressBookPtr JSAddressBook::getAddressBook(JSContextRef context, JSValueRef value)
157 if (!isObjectOfClass(context, value)) {
158 Throw(InvalidArgumentException);
160 JSObjectRef object = JSValueToObject(context, value, NULL);
162 Throw(InvalidArgumentException);
164 AddressBookController *priv = static_cast<AddressBookController*>(JSObjectGetPrivate(object));
166 Throw(NullPointerException);
168 return priv->getObject();
171 AddressBookPtr JSAddressBook::getPrivData(JSObjectRef object)
173 AddressBookController *priv =
174 static_cast<AddressBookController*>(JSObjectGetPrivate(object));
176 return priv->getObject();
178 Throw(NullPointerException);
181 JSValueRef JSAddressBook::getId(JSContextRef context,
183 JSStringRef propertyName,
184 JSValueRef* exception)
188 ContactConverterFactory::ConverterType converter =
189 ContactConverterFactory::getConverter(context);
190 AddressBookPtr addressBook = getPrivData(object);
191 string id = addressBook->getId();
193 return converter->toJSValueRef(id);
195 return JSValueMakeNull(context);
197 Catch(WrtDeviceApis::Commons::Exception)
199 LoggerW("trying to get incorrect value");
201 return JSValueMakeUndefined(context);
204 JSValueRef JSAddressBook::getName(JSContextRef context,
206 JSStringRef propertyName,
207 JSValueRef* exception)
211 ContactConverterFactory::ConverterType converter =
212 ContactConverterFactory::getConverter(context);
213 AddressBookPtr addressBook = getPrivData(object);
214 return converter->toJSValueRef(addressBook->getName());
216 Catch(WrtDeviceApis::Commons::Exception)
218 LoggerW("trying to get incorrect value");
221 return JSValueMakeUndefined(context);
224 JSValueRef JSAddressBook::getReadOnly(JSContextRef context,
226 JSStringRef propertyName,
227 JSValueRef* exception)
231 ContactConverterFactory::ConverterType converter =
232 ContactConverterFactory::getConverter(context);
233 AddressBookPtr addressBook = getPrivData(object);
234 return converter->toJSValueRef(addressBook->getReadOnly());
236 Catch(WrtDeviceApis::Commons::Exception)
238 LoggerW("trying to get incorrect value");
241 return JSValueMakeUndefined(context);
244 JSValueRef JSAddressBook::getAccountId(JSContextRef context,
246 JSStringRef propertyName,
247 JSValueRef* exception)
251 ContactConverterFactory::ConverterType converter =
252 ContactConverterFactory::getConverter(context);
253 AddressBookPtr addressBook = getPrivData(object);
254 string accountId = addressBook->getAccountId();
256 return converter->toJSValueRef(accountId);
258 return JSValueMakeNull(context);
260 Catch(WrtDeviceApis::Commons::Exception)
262 LoggerW("trying to get incorrect value");
264 return JSValueMakeUndefined(context);
267 JSValueRef JSAddressBook::get(JSContextRef context,
269 JSObjectRef thisObject,
270 size_t argumentCount,
271 const JSValueRef arguments[],
272 JSValueRef* exception)
275 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
276 AddressBookPtr addressBook;
277 AddressBookController *controller;
278 JSContextRef gContext;
281 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
283 ThrowMsg(InvalidArgumentException, "No private object.");
285 addressBook = controller->getObject();
286 gContext = controller->getContext();
289 LoggerE("No private object");
290 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
293 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET);
294 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
299 ArgumentValidator validator(context, argumentCount, arguments);
300 id = validator.toString(0, false);
301 } catch (const TypeMismatchException& err ) {
302 return JSWebAPIErrorFactory::postException(context, exception, err);
303 } catch(const BasePlatformException& err) {
304 return JSWebAPIErrorFactory::postException(context, exception, err);
305 } catch(const ConversionException& err) {
306 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
307 } catch(const NullPointerException& err) {
308 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
311 EventAddressBookGetPtr dplEvent(new EventAddressBookGet());
314 dplEvent->setForSynchronousCall();
317 addressBook->get(dplEvent);
319 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
320 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
323 if (!dplEvent->getResult() || !dplEvent->getContactIsSet())
325 std::stringstream oss;
326 switch (dplEvent->getExceptionCode())
328 case ExceptionCodes::NotFoundException:
329 case ExceptionCodes::InvalidArgumentException:
330 LoggerE("Not Found error : " << id);
331 oss << "No Contact id '" << id << "'";
332 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
334 case ExceptionCodes::PlatformException:
335 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
338 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
343 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
345 ContactPtr contact = dplEvent->getContact();
348 result = converter->toJSValueRef(contact);
350 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
351 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
354 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
358 JSValueRef JSAddressBook::add(JSContextRef context,
360 JSObjectRef thisObject,
361 size_t argumentCount,
362 const JSValueRef arguments[],
363 JSValueRef* exception)
366 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
367 AddressBookPtr addressBook;
368 AddressBookController *controller;
369 JSContextRef gContext;
372 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
374 ThrowMsg(InvalidArgumentException, "No private object.");
376 addressBook = controller->getObject();
377 gContext = controller->getContext();
379 LoggerE("No private object");
380 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
383 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD);
384 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
387 ArgumentValidator validator(context, argumentCount, arguments);
388 validator.toObject(0, false);
389 } catch (const TypeMismatchException& err ) {
390 return JSWebAPIErrorFactory::postException(context, exception, err);
391 } catch(const BasePlatformException& err) {
392 return JSWebAPIErrorFactory::postException(context, exception, err);
393 } catch(const ConversionException& err) {
394 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
395 } catch(const NullPointerException& err) {
396 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
399 ContactPtr contact(NULL);
401 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
403 if (!JSContact::isObjectOfClass(context, arguments[0]))
404 ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
405 contact = converter->toContact(arguments[0]);
407 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
408 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be a 'Contact object'");
411 EventAddressBookAddPtr dplEvent(new EventAddressBookAdd());
413 dplEvent->setContact(contact);
414 dplEvent->setForSynchronousCall();
417 addressBook->add(dplEvent);
419 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
420 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
423 if (!dplEvent->getResult())
425 switch (dplEvent->getExceptionCode())
427 case ExceptionCodes::PlatformException:
428 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
430 case ExceptionCodes::InvalidArgumentException:
431 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "There is Invalid input value");
434 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
439 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
440 return JSValueMakeUndefined(context);
443 JSValueRef JSAddressBook::addBatch(JSContextRef context,
445 JSObjectRef thisObject,
446 size_t argumentCount,
447 const JSValueRef arguments[],
448 JSValueRef* exception)
451 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
452 AddressBookPtr addressBook;
453 JSContextRef gContext;
454 AddressBookController *controller;
456 bool js2ndParamIsFunction = false;
457 bool js3rdParamIsFunction = false;
460 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
462 ThrowMsg(InvalidArgumentException, "No private object.");
464 addressBook = controller->getObject();
465 gContext = controller->getContext();
467 LoggerE("No private object");
468 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
471 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_BATCH);
472 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
475 ArgumentValidator validator(context, argumentCount, arguments);
477 validator.toObject(0, false);
478 JSObjectRef successObj = validator.toFunction(1, true);
480 js2ndParamIsFunction = true;
482 JSObjectRef errorObj = validator.toFunction(2, true);
484 js3rdParamIsFunction = true;
486 } catch (const TypeMismatchException& err ) {
487 return JSWebAPIErrorFactory::postException(context, exception, err);
488 } catch(const BasePlatformException& err) {
489 return JSWebAPIErrorFactory::postException(context, exception, err);
490 } catch(const ConversionException& err) {
491 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
492 } catch(const NullPointerException& err) {
493 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
496 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
498 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
500 if(js2ndParamIsFunction)
501 callbackManager->setOnSuccess(arguments[1]);
503 if(js3rdParamIsFunction)
504 callbackManager->setOnError(arguments[2]);
506 callbackManager->setObject(thisObject);
508 EventAddressBookAddBatchPtr dplEvent(new EventAddressBookAddBatch());
510 dplEvent->setContacts(converter->toContactArray(arguments[0]));
511 } Catch(ConversionException) {
512 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
513 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be an array of 'Contact object'");
516 // set event handler's data
517 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
518 dplEvent->setForAsynchronousCall(controller);
520 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
521 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
524 addressBook->addBatch(dplEvent);
525 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
527 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
528 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
531 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
532 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
533 return JSValueMakeUndefined(context);
536 JSValueRef JSAddressBook::update(JSContextRef context,
538 JSObjectRef thisObject,
539 size_t argumentCount,
540 const JSValueRef arguments[],
541 JSValueRef* exception)
544 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
545 AddressBookPtr addressBook;
546 AddressBookController *controller;
547 JSContextRef gContext;
550 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
552 ThrowMsg(InvalidArgumentException, "No private object.");
554 addressBook = controller->getObject();
555 gContext = controller->getContext();
557 LoggerE("No private object");
558 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
561 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE);
562 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
565 ArgumentValidator validator(context, argumentCount, arguments);
566 validator.toObject(0, false);
568 } catch (const TypeMismatchException& err ) {
569 return JSWebAPIErrorFactory::postException(context, exception, err);
570 } catch(const BasePlatformException& err) {
571 return JSWebAPIErrorFactory::postException(context, exception, err);
572 } catch(const ConversionException& err) {
573 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
574 } catch(const NullPointerException& err) {
575 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
578 ContactPtr contact(NULL);
580 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
582 if (!JSContact::isObjectOfClass(context, arguments[0]))
583 ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
584 contact = converter->toContact(arguments[0]);
586 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
587 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument is not a 'Contact object'");
590 EventAddressBookUpdatePtr dplEvent(new EventAddressBookUpdate());
592 dplEvent->setContact(contact);
593 dplEvent->setForSynchronousCall();
596 addressBook->update(dplEvent);
598 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
599 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
602 if (!dplEvent->getResult())
604 std::stringstream oss;
605 switch (dplEvent->getExceptionCode())
607 case ExceptionCodes::NotFoundException:
608 case ExceptionCodes::InvalidArgumentException:
609 oss << "No Contact id '" << contact->getId() << "'";
610 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
612 case ExceptionCodes::PlatformException:
613 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
616 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
621 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
622 return JSValueMakeUndefined(context);
625 JSValueRef JSAddressBook::updateBatch(JSContextRef context,
627 JSObjectRef thisObject,
628 size_t argumentCount,
629 const JSValueRef arguments[],
630 JSValueRef* exception)
633 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
634 AddressBookPtr addressBook;
635 JSContextRef gContext;
636 AddressBookController *controller;
638 bool js2ndParamIsFunction = false;
639 bool js3rdParamIsFunction = false;
642 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
644 ThrowMsg(InvalidArgumentException, "No private object.");
646 addressBook = controller->getObject();
647 gContext = controller->getContext();
649 LoggerE("No private object");
650 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
653 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_BATCH);
654 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
657 ArgumentValidator validator(context, argumentCount, arguments);
659 validator.toObject(0, false);
661 JSObjectRef successObj = validator.toFunction(1, true);
663 js2ndParamIsFunction = true;
665 JSObjectRef errorObj = validator.toFunction(2, true);
667 js3rdParamIsFunction = true;
669 } catch (const TypeMismatchException& err ) {
670 return JSWebAPIErrorFactory::postException(context, exception, err);
671 } catch(const BasePlatformException& err) {
672 return JSWebAPIErrorFactory::postException(context, exception, err);
673 } catch(const ConversionException& err) {
674 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
675 } catch(const NullPointerException& err) {
676 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
679 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
681 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
683 if(js2ndParamIsFunction)
684 callbackManager->setOnSuccess(arguments[1]);
686 if(js3rdParamIsFunction)
687 callbackManager->setOnError(arguments[2]);
689 callbackManager->setObject(thisObject);
691 EventAddressBookUpdateBatchPtr dplEvent(new EventAddressBookUpdateBatch());
693 dplEvent->setContacts(converter->toContactArray(arguments[0]));
694 } Catch(ConversionException) {
695 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
696 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact object'");
699 // set event handler's data
700 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
701 dplEvent->setForAsynchronousCall(controller);
703 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
704 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
707 addressBook->updateBatch(dplEvent);
708 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
710 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
711 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
714 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
715 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
716 return JSValueMakeUndefined(context);
719 JSValueRef JSAddressBook::remove(JSContextRef context,
721 JSObjectRef thisObject,
722 size_t argumentCount,
723 const JSValueRef arguments[],
724 JSValueRef* exception)
727 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
728 AddressBookPtr addressBook;
729 AddressBookController *controller;
732 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
734 ThrowMsg(InvalidArgumentException, "No private object.");
736 addressBook = controller->getObject();
738 LoggerE("No private object");
739 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
742 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE);
743 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
745 ArgumentValidator validator(context, argumentCount, arguments);
748 contactId = validator.toString(0, false);
749 } catch (const TypeMismatchException& err ) {
750 return JSWebAPIErrorFactory::postException(context, exception, err);
751 } catch(const BasePlatformException& err) {
752 return JSWebAPIErrorFactory::postException(context, exception, err);
753 } catch(const ConversionException& err) {
754 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
755 } catch(const NullPointerException& err) {
756 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
759 EventAddressBookRemovePtr dplEvent(new EventAddressBookRemove());
761 dplEvent->setContactId(contactId);
762 dplEvent->setForSynchronousCall();
765 addressBook->remove(dplEvent);
767 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
768 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
771 if (!dplEvent->getResult())
773 std::stringstream oss;
774 switch (dplEvent->getExceptionCode())
776 case ExceptionCodes::NotFoundException:
777 case ExceptionCodes::InvalidArgumentException:
778 LoggerE("Not Found error : " << contactId);
779 oss << "No Contact id '" << contactId << "'";
780 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
782 case ExceptionCodes::PlatformException:
783 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
786 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
790 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
791 return JSValueMakeUndefined(context);
794 JSValueRef JSAddressBook::removeBatch(JSContextRef context,
796 JSObjectRef thisObject,
797 size_t argumentCount,
798 const JSValueRef arguments[],
799 JSValueRef* exception)
802 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
803 AddressBookPtr addressBook;
804 JSContextRef gContext;
805 AddressBookController *controller;
807 bool js2ndParamIsFunction = false;
808 bool js3rdParamIsFunction = false;
811 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
813 ThrowMsg(InvalidArgumentException, "No private object.");
815 addressBook = controller->getObject();
816 gContext = controller->getContext();
818 LoggerE("No private object");
819 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
822 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_BATCH);
823 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
826 ArgumentValidator validator(context, argumentCount, arguments);
828 validator.toObject(0, false);
829 JSObjectRef successObj = validator.toFunction(1, true);
831 js2ndParamIsFunction = true;
833 JSObjectRef errorObj = validator.toFunction(2, true);
835 js3rdParamIsFunction = true;
837 } catch (const TypeMismatchException& err ) {
838 return JSWebAPIErrorFactory::postException(context, exception, err);
839 } catch(const BasePlatformException& err) {
840 return JSWebAPIErrorFactory::postException(context, exception, err);
841 } catch(const ConversionException& err) {
842 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
843 } catch(const NullPointerException& err) {
844 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
847 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
849 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
851 if(js2ndParamIsFunction)
852 callbackManager->setOnSuccess(arguments[1]);
854 if(js3rdParamIsFunction)
855 callbackManager->setOnError(arguments[2]);
857 callbackManager->setObject(thisObject);
859 EventAddressBookRemoveBatchPtr dplEvent(new EventAddressBookRemoveBatch());
861 dplEvent->setContactIds(converter->toStringArray(arguments[0]));
862 } Catch(ConversionException) {
863 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
864 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact id'");
867 // set event handler's data
868 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
869 dplEvent->setForAsynchronousCall(controller);
871 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
872 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
875 addressBook->removeBatch(dplEvent);
876 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
878 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
879 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
882 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
883 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
884 return JSValueMakeUndefined(context);
887 JSValueRef JSAddressBook::find(JSContextRef context,
889 JSObjectRef thisObject,
890 size_t argumentCount,
891 const JSValueRef arguments[],
892 JSValueRef* exception)
895 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
896 AddressBookPtr addressBook;
897 JSContextRef gContext;
898 AddressBookController *controller;
900 bool js2ndParamIsFunction = false;
901 bool js3rdParamIsObject = false;
902 bool js4thParamIsObject = false;
905 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
907 ThrowMsg(InvalidArgumentException, "No private object.");
909 addressBook = controller->getObject();
910 gContext = controller->getContext();
912 LoggerE("No private object");
913 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
916 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_FIND);
917 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
920 ArgumentValidator validator(context, argumentCount, arguments);
922 validator.toFunction(0, false);
923 JSObjectRef errorObj = validator.toFunction(1, true);
925 js2ndParamIsFunction = true;
927 JSObjectRef filterObj = validator.toObject(2, true);
929 js3rdParamIsObject = true;
931 JSObjectRef sortObj = validator.toObject(3, true);
933 js4thParamIsObject = true;
935 } catch (const TypeMismatchException& err ) {
936 return JSWebAPIErrorFactory::postException(context, exception, err);
937 } catch(const BasePlatformException& err) {
938 return JSWebAPIErrorFactory::postException(context, exception, err);
939 } catch(const ConversionException& err) {
940 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
941 } catch(const NullPointerException& err) {
942 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
945 JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
947 callbackManager->setOnSuccess(arguments[0]);
949 if (js2ndParamIsFunction)
950 callbackManager->setOnError(arguments[1]);
952 callbackManager->setObject(thisObject);
954 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
955 ContactFilterConverterFactory::ConverterType filterConverter = ContactFilterConverterFactory::getConverter(context);
957 EventAddressBookFindPtr dplEvent(new EventAddressBookFind());
959 if (js3rdParamIsObject)
960 dplEvent->setFilter(filterConverter->toFilter(arguments[2]));
962 LoggerE("Error on 3rd parameter conversion : " << _rethrown_exception.GetMessage());
963 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an 'Filter object' or 'null'");
967 if (js4thParamIsObject)
968 dplEvent->setSortMode(filterConverter->toSortMode(arguments[3]));
970 LoggerE("Error on 4th parameter conversion : " << _rethrown_exception.GetMessage());
971 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "4th argument must be an 'SortMode object' or 'null'");
974 // set event handler's data
975 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
976 dplEvent->setForAsynchronousCall(controller);
978 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
979 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
982 addressBook->find(dplEvent);
983 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
985 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
986 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
989 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
990 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
991 return JSValueMakeUndefined(context);
994 JSValueRef JSAddressBook::addChangeListener(JSContextRef context,
996 JSObjectRef thisObject,
997 size_t argumentCount,
998 const JSValueRef arguments[],
999 JSValueRef* exception)
1002 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1003 AddressBookPtr addressBook;
1004 JSContextRef gContext;
1005 AddressBookController *controller;
1007 bool js2ndParamIsFunction = false;
1010 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1012 ThrowMsg(InvalidArgumentException, "No private object.");
1014 addressBook = controller->getObject();
1015 gContext = controller->getContext();
1016 } Catch(Exception) {
1017 LoggerE("No private object");
1018 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1021 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_CHANGE_LISTENER);
1022 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1024 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
1026 ArgumentValidator Argvalidator(context, argumentCount, arguments);
1027 Argvalidator.toObject(0, false);
1028 JSObjectRef errorObj = Argvalidator.toFunction(1, true);
1030 js2ndParamIsFunction = true;
1031 } catch (const TypeMismatchException& err ) {
1032 return JSWebAPIErrorFactory::postException(context, exception, err);
1033 } catch(const BasePlatformException& err) {
1034 return JSWebAPIErrorFactory::postException(context, exception, err);
1035 } catch(const ConversionException& err) {
1036 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1037 } catch(const NullPointerException& err) {
1038 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1041 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1043 JSValueRef oncontactsadded;
1044 JSValueRef oncontactsupdated;
1045 JSValueRef oncontactsdeleted;
1047 JSObjectRef callbackObject = converter->toJSObjectRef(arguments[0]);
1049 oncontactsadded = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsadded");
1050 if (validator->isNullOrUndefined(oncontactsadded))
1051 oncontactsadded = NULL;
1052 else if (!validator->isCallback(oncontactsadded)) {
1053 ThrowMsg(ConversionException, "2nd argument's oncontactsadded attribute is not a 'function'");
1056 oncontactsupdated = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsupdated");
1057 if (validator->isNullOrUndefined(oncontactsupdated))
1058 oncontactsupdated = NULL;
1059 else if (!validator->isCallback(oncontactsupdated)) {
1060 ThrowMsg(ConversionException, "2nd argument's oncontactsupdated attribute is not a 'function'");
1063 oncontactsdeleted = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsremoved");
1064 if (validator->isNullOrUndefined(oncontactsdeleted))
1065 oncontactsdeleted = NULL;
1066 else if (!validator->isCallback(oncontactsdeleted)) {
1067 ThrowMsg(ConversionException, "2nd argument's oncontactsremoved attribute is not a 'function'");
1070 if (oncontactsadded == NULL && oncontactsupdated == NULL && oncontactsdeleted == NULL)
1071 ThrowMsg(ConversionException, "2nd argument must have at least one function");
1073 } Catch(ConversionException) {
1074 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1075 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1078 JSAddressBookChangeCallbackManagerPtr callbackManager = JSAddressBookChangeCallbackManager::createObject(gContext);
1080 callbackManager->setOnContactsAdded(oncontactsadded);
1081 callbackManager->setOnContactsUpdated(oncontactsupdated);
1082 callbackManager->setOnContactsDeleted(oncontactsdeleted);
1083 if(js2ndParamIsFunction)
1084 callbackManager->setOnError(arguments[1]);
1086 EventAddressBookChangeListenerEmitterPtr emitter(new EventAddressBookChangeListenerEmitter());
1088 emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
1089 emitter->setListener(controller);
1091 EventAddressBookAddChangeListenerPtr dplEvent(new EventAddressBookAddChangeListener());
1093 dplEvent->setEmitter(emitter);
1094 dplEvent->setForSynchronousCall();
1097 addressBook->addChangeListener(dplEvent);
1098 } Catch(Exception) {
1099 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1100 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1103 if (!dplEvent->getResult() || !dplEvent->getIdIsSet())
1105 switch (dplEvent->getExceptionCode())
1107 case ExceptionCodes::InvalidArgumentException:
1108 case ExceptionCodes::PlatformException:
1109 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1112 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1117 long watchId = dplEvent->getId();
1119 ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
1120 DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1121 ContactListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
1125 result = JSUtil::toJSValueRef(context, watchId);
1126 // result = converter->toJSValueRefLong(watchId);
1127 } Catch(Exception) {
1128 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1129 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1131 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1135 JSValueRef JSAddressBook::removeChangeListener(JSContextRef context,
1137 JSObjectRef thisObject,
1138 size_t argumentCount,
1139 const JSValueRef arguments[],
1140 JSValueRef* exception)
1143 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1144 AddressBookPtr addressBook;
1145 JSContextRef gContext;
1146 AddressBookController *controller;
1149 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1151 ThrowMsg(InvalidArgumentException, "No private object.");
1153 addressBook = controller->getObject();
1154 gContext = controller->getContext();
1155 } Catch(Exception) {
1156 LoggerE("No private object");
1157 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1160 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER);
1161 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1166 ArgumentValidator validator(context, argumentCount, arguments);
1167 watchId = validator.toLong(0, false);
1168 } catch (const TypeMismatchException& err ) {
1169 return JSWebAPIErrorFactory::postException(context, exception, err);
1170 } catch(const BasePlatformException& err) {
1171 return JSWebAPIErrorFactory::postException(context, exception, err);
1172 } catch(const ConversionException& err) {
1173 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1174 } catch(const NullPointerException& err) {
1175 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1178 EventAddressBookRemoveChangeListenerPtr dplEvent(new EventAddressBookRemoveChangeListener());
1180 dplEvent->setId(watchId);
1181 dplEvent->setForSynchronousCall();
1184 addressBook->removeChangeListener(dplEvent);
1185 } Catch(Exception) {
1186 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1187 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1190 ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
1191 DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1192 ContactListenerManagerSingleton::Instance().unregisterListener(listenerItem);
1194 if (!dplEvent->getResult())
1196 switch (dplEvent->getExceptionCode())
1198 case ExceptionCodes::InvalidArgumentException:
1199 case ExceptionCodes::NotFoundException:
1200 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "Watch id not found");
1203 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1207 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1208 return JSValueMakeUndefined(context);
1211 JSValueRef JSAddressBook::getGroup(JSContextRef context,
1213 JSObjectRef thisObject,
1214 size_t argumentCount,
1215 const JSValueRef arguments[],
1216 JSValueRef* exception)
1219 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1220 AddressBookPtr addressBook;
1221 AddressBookController *controller;
1222 JSContextRef gContext;
1225 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1227 ThrowMsg(InvalidArgumentException, "No private object.");
1229 addressBook = controller->getObject();
1230 gContext = controller->getContext();
1231 } Catch(Exception) {
1232 LoggerE("No private object");
1233 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1236 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUP);
1237 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1241 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1243 ArgumentValidator validator(context, argumentCount, arguments);
1244 id = validator.toString(0, false);
1245 } catch (const TypeMismatchException& err ) {
1246 return JSWebAPIErrorFactory::postException(context, exception, err);
1247 } catch(const BasePlatformException& err) {
1248 return JSWebAPIErrorFactory::postException(context, exception, err);
1249 } catch(const ConversionException& err) {
1250 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1251 } catch(const NullPointerException& err) {
1252 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1255 EventAddressBookGetGroupPtr dplEvent(new EventAddressBookGetGroup());
1257 dplEvent->setId(id);
1258 dplEvent->setForSynchronousCall();
1261 addressBook->getGroup(dplEvent);
1262 } Catch(Exception) {
1263 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1264 return JSWebAPIErrorFactory::postException(context, exception,
1265 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1268 if (!dplEvent->getResult() || !dplEvent->getContactGroupIsSet())
1270 std::stringstream oss;
1271 switch (dplEvent->getExceptionCode())
1273 case ExceptionCodes::NotFoundException:
1274 case ExceptionCodes::InvalidArgumentException:
1275 LoggerE("Not Found error : " << id);
1276 oss << "No Group id '" << id << "'";
1277 return JSWebAPIErrorFactory::postException(context, exception,
1278 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1280 case ExceptionCodes::PlatformException:
1281 return JSWebAPIErrorFactory::postException(context, exception,
1282 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1285 return JSWebAPIErrorFactory::postException(context, exception,
1286 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1291 ContactGroupPtr group = dplEvent->getContactGroup();
1295 result = converter->toJSValueRef(group);
1296 } Catch(Exception) {
1297 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1298 return JSWebAPIErrorFactory::postException(context, exception,
1299 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1301 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1305 JSValueRef JSAddressBook::addGroup(JSContextRef context,
1307 JSObjectRef thisObject,
1308 size_t argumentCount,
1309 const JSValueRef arguments[],
1310 JSValueRef* exception)
1313 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1314 AddressBookPtr addressBook;
1315 AddressBookController *controller;
1316 JSContextRef gContext;
1319 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1321 ThrowMsg(InvalidArgumentException, "No private object.");
1323 addressBook = controller->getObject();
1324 gContext = controller->getContext();
1325 } Catch(Exception) {
1326 LoggerE("No private object");
1327 return JSWebAPIErrorFactory::postException(context, exception,
1328 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1331 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_GROUP);
1332 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1335 ArgumentValidator validator(context, argumentCount, arguments);
1336 validator.toObject(0, false);
1338 } catch (const TypeMismatchException& err ) {
1339 return JSWebAPIErrorFactory::postException(context, exception, err);
1340 } catch(const BasePlatformException& err) {
1341 return JSWebAPIErrorFactory::postException(context, exception, err);
1342 } catch(const ConversionException& err) {
1343 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1344 } catch(const NullPointerException& err) {
1345 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1348 ContactGroupPtr group(NULL);
1350 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1352 if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
1353 ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
1355 group = converter->toContactGroup(arguments[0]);
1356 } Catch(Exception) {
1357 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1358 return JSWebAPIErrorFactory::postException(context, exception,
1359 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactGroup object'");
1362 EventAddressBookAddGroupPtr dplEvent(new EventAddressBookAddGroup());
1364 dplEvent->setContactGroup(group);
1365 dplEvent->setForSynchronousCall();
1368 addressBook->addGroup(dplEvent);
1369 } Catch(Exception) {
1370 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1371 return JSWebAPIErrorFactory::postException(context, exception,
1372 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1375 if (!dplEvent->getResult())
1377 switch (dplEvent->getExceptionCode())
1379 case ExceptionCodes::PlatformException:
1380 return JSWebAPIErrorFactory::postException(context, exception,
1381 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1384 return JSWebAPIErrorFactory::postException(context, exception,
1385 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1389 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1390 return JSValueMakeUndefined(context);
1393 JSValueRef JSAddressBook::updateGroup(JSContextRef context,
1395 JSObjectRef thisObject,
1396 size_t argumentCount,
1397 const JSValueRef arguments[],
1398 JSValueRef* exception)
1401 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1402 AddressBookPtr addressBook;
1403 AddressBookController *controller;
1404 JSContextRef gContext;
1407 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1409 ThrowMsg(InvalidArgumentException, "No private object.");
1411 addressBook = controller->getObject();
1412 gContext = controller->getContext();
1413 } Catch(Exception) {
1414 LoggerE("No private object");
1415 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1418 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_GROUP);
1419 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1422 ArgumentValidator validator(context, argumentCount, arguments);
1423 validator.toObject(0, false);
1425 } catch (const TypeMismatchException& err ) {
1426 return JSWebAPIErrorFactory::postException(context, exception, err);
1427 } catch(const BasePlatformException& err) {
1428 return JSWebAPIErrorFactory::postException(context, exception, err);
1429 } catch(const ConversionException& err) {
1430 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1431 } catch(const NullPointerException& err) {
1432 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1435 ContactGroupPtr contact(NULL);
1437 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1439 if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
1440 ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
1441 contact = converter->toContactGroup(arguments[0]);
1442 } Catch(Exception) {
1443 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1444 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument is not a 'ContactGroup object'");
1447 EventAddressBookUpdateGroupPtr dplEvent(new EventAddressBookUpdateGroup());
1449 dplEvent->setContactGroup(contact);
1450 dplEvent->setForSynchronousCall();
1453 addressBook->updateGroup(dplEvent);
1454 } Catch(Exception) {
1455 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1456 return JSWebAPIErrorFactory::postException(context, exception,
1457 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1460 if (!dplEvent->getResult())
1462 std::stringstream oss;
1463 switch (dplEvent->getExceptionCode())
1465 case ExceptionCodes::NotFoundException:
1466 case ExceptionCodes::InvalidArgumentException:
1467 oss << "No Group id '" << contact->getId() << "'";
1468 return JSWebAPIErrorFactory::postException(context, exception,
1469 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1471 case ExceptionCodes::PlatformException:
1472 return JSWebAPIErrorFactory::postException(context, exception,
1473 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1476 return JSWebAPIErrorFactory::postException(context, exception,
1477 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1481 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1482 return JSValueMakeUndefined(context);
1485 JSValueRef JSAddressBook::removeGroup(JSContextRef context,
1487 JSObjectRef thisObject,
1488 size_t argumentCount,
1489 const JSValueRef arguments[],
1490 JSValueRef* exception)
1493 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1494 AddressBookPtr addressBook;
1495 AddressBookController *controller;
1498 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1500 ThrowMsg(InvalidArgumentException, "No private object.");
1502 addressBook = controller->getObject();
1503 } Catch(Exception) {
1504 LoggerE("No private object");
1505 return JSWebAPIErrorFactory::postException(context, exception,
1506 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1509 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_GROUP);
1510 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1515 ArgumentValidator validator(context, argumentCount, arguments);
1516 groupId = validator.toString(0, false);
1517 } catch (const TypeMismatchException& err ) {
1518 return JSWebAPIErrorFactory::postException(context, exception, err);
1519 } catch(const BasePlatformException& err) {
1520 return JSWebAPIErrorFactory::postException(context, exception, err);
1521 } catch(const ConversionException& err) {
1522 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1523 } catch(const NullPointerException& err) {
1524 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1527 EventAddressBookRemoveGroupPtr dplEvent(new EventAddressBookRemoveGroup());
1529 dplEvent->setContactGroupId(groupId);
1530 dplEvent->setForSynchronousCall();
1533 addressBook->removeGroup(dplEvent);
1534 } Catch(Exception) {
1535 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1536 return JSWebAPIErrorFactory::postException(context, exception,
1537 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1540 if (!dplEvent->getResult())
1542 std::stringstream oss;
1543 switch (dplEvent->getExceptionCode())
1545 case ExceptionCodes::NotFoundException:
1546 case ExceptionCodes::InvalidArgumentException:
1547 LoggerE("Not Found error : " << groupId);
1548 oss << "No Group id '" << groupId << "'";
1549 return JSWebAPIErrorFactory::postException(context, exception,
1550 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1552 case ExceptionCodes::PlatformException:
1553 return JSWebAPIErrorFactory::postException(context, exception,
1554 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1557 return JSWebAPIErrorFactory::postException(context, exception,
1558 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1562 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1563 return JSValueMakeUndefined(context);
1566 JSValueRef JSAddressBook::getGroups(JSContextRef context,
1568 JSObjectRef thisObject,
1569 size_t argumentCount,
1570 const JSValueRef arguments[],
1571 JSValueRef* exception)
1574 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1575 AddressBookPtr addressBook;
1576 AddressBookController *controller;
1577 JSContextRef gContext;
1580 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1582 ThrowMsg(InvalidArgumentException, "No private object.");
1584 addressBook = controller->getObject();
1585 gContext = controller->getContext();
1586 } Catch(Exception) {
1587 LoggerE("No private object");
1588 return JSWebAPIErrorFactory::postException(context, exception,
1589 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1592 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUPS);
1593 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1597 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1599 EventAddressBookGetGroupsPtr dplEvent(new EventAddressBookGetGroups());
1601 dplEvent->setForSynchronousCall();
1604 addressBook->getGroups(dplEvent);
1605 } Catch(Exception) {
1606 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1607 return JSWebAPIErrorFactory::postException(context, exception,
1608 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1611 if (!dplEvent->getResult() || !dplEvent->getContactGroupsIsSet())
1613 std::stringstream oss;
1614 switch (dplEvent->getExceptionCode())
1616 case ExceptionCodes::NotFoundException:
1617 case ExceptionCodes::InvalidArgumentException:
1618 LoggerE("Not Found error : " << id);
1619 oss << "No Group id '" << id << "'";
1620 return JSWebAPIErrorFactory::postException(context, exception,
1621 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1623 case ExceptionCodes::PlatformException:
1624 return JSWebAPIErrorFactory::postException(context, exception,
1625 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1628 return JSWebAPIErrorFactory::postException(context, exception,
1629 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1634 ContactGroupArrayPtr groups = dplEvent->getContactGroups();
1638 result = converter->toJSValueRef(groups);
1639 } Catch(Exception) {
1640 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1641 return JSWebAPIErrorFactory::postException(context, exception,
1642 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1644 TIME_TRACER_ITEM_END(__FUNCTION__, 0);