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 FilterPtr filter = filterConverter->toFilter(arguments[2]);
962 dplEvent->setFilter(filter);
964 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an Correct 'Filter object' or 'null'");
967 LoggerE("Error on 3rd parameter conversion : " << _rethrown_exception.GetMessage());
968 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "3rd argument must be an 'Filter object' or 'null'");
972 if (js4thParamIsObject){
973 SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
974 dplEvent->setSortMode(sortMode);
977 LoggerE("Error on 4th parameter conversion : " << _rethrown_exception.GetMessage());
978 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "4th argument must be an 'SortMode object' or 'null'");
981 // set event handler's data
982 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
983 dplEvent->setForAsynchronousCall(controller);
985 // DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
986 // IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
989 addressBook->find(dplEvent);
990 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
992 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
993 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
996 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
997 // return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
998 return JSValueMakeUndefined(context);
1001 JSValueRef JSAddressBook::addChangeListener(JSContextRef context,
1003 JSObjectRef thisObject,
1004 size_t argumentCount,
1005 const JSValueRef arguments[],
1006 JSValueRef* exception)
1009 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1010 AddressBookPtr addressBook;
1011 JSContextRef gContext;
1012 AddressBookController *controller;
1014 bool js2ndParamIsFunction = false;
1017 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1019 ThrowMsg(InvalidArgumentException, "No private object.");
1021 addressBook = controller->getObject();
1022 gContext = controller->getContext();
1023 } Catch(Exception) {
1024 LoggerE("No private object");
1025 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1028 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_CHANGE_LISTENER);
1029 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1031 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
1033 ArgumentValidator Argvalidator(context, argumentCount, arguments);
1034 Argvalidator.toObject(0, false);
1035 JSObjectRef errorObj = Argvalidator.toFunction(1, true);
1037 js2ndParamIsFunction = true;
1038 } catch (const TypeMismatchException& err ) {
1039 return JSWebAPIErrorFactory::postException(context, exception, err);
1040 } catch(const BasePlatformException& err) {
1041 return JSWebAPIErrorFactory::postException(context, exception, err);
1042 } catch(const ConversionException& err) {
1043 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1044 } catch(const NullPointerException& err) {
1045 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1048 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1050 JSValueRef oncontactsadded;
1051 JSValueRef oncontactsupdated;
1052 JSValueRef oncontactsdeleted;
1054 JSObjectRef callbackObject = converter->toJSObjectRef(arguments[0]);
1056 oncontactsadded = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsadded");
1057 if (validator->isNullOrUndefined(oncontactsadded))
1058 oncontactsadded = NULL;
1059 else if (!validator->isCallback(oncontactsadded)) {
1060 ThrowMsg(ConversionException, "2nd argument's oncontactsadded attribute is not a 'function'");
1063 oncontactsupdated = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsupdated");
1064 if (validator->isNullOrUndefined(oncontactsupdated))
1065 oncontactsupdated = NULL;
1066 else if (!validator->isCallback(oncontactsupdated)) {
1067 ThrowMsg(ConversionException, "2nd argument's oncontactsupdated attribute is not a 'function'");
1070 oncontactsdeleted = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsremoved");
1071 if (validator->isNullOrUndefined(oncontactsdeleted))
1072 oncontactsdeleted = NULL;
1073 else if (!validator->isCallback(oncontactsdeleted)) {
1074 ThrowMsg(ConversionException, "2nd argument's oncontactsremoved attribute is not a 'function'");
1077 if (oncontactsadded == NULL && oncontactsupdated == NULL && oncontactsdeleted == NULL)
1078 ThrowMsg(ConversionException, "2nd argument must have at least one function");
1080 } Catch(ConversionException) {
1081 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1082 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1085 JSAddressBookChangeCallbackManagerPtr callbackManager = JSAddressBookChangeCallbackManager::createObject(gContext);
1087 callbackManager->setOnContactsAdded(oncontactsadded);
1088 callbackManager->setOnContactsUpdated(oncontactsupdated);
1089 callbackManager->setOnContactsDeleted(oncontactsdeleted);
1090 if(js2ndParamIsFunction)
1091 callbackManager->setOnError(arguments[1]);
1093 EventAddressBookChangeListenerEmitterPtr emitter(new EventAddressBookChangeListenerEmitter());
1095 emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
1096 emitter->setListener(controller);
1098 EventAddressBookAddChangeListenerPtr dplEvent(new EventAddressBookAddChangeListener());
1100 dplEvent->setEmitter(emitter);
1101 dplEvent->setForSynchronousCall();
1104 addressBook->addChangeListener(dplEvent);
1105 } Catch(Exception) {
1106 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1107 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1110 if (!dplEvent->getResult() || !dplEvent->getIdIsSet())
1112 switch (dplEvent->getExceptionCode())
1114 case ExceptionCodes::InvalidArgumentException:
1115 case ExceptionCodes::PlatformException:
1116 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1119 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1124 long watchId = dplEvent->getId();
1126 ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
1127 DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1128 ContactListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
1132 result = JSUtil::toJSValueRef(context, watchId);
1133 // result = converter->toJSValueRefLong(watchId);
1134 } Catch(Exception) {
1135 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1136 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1138 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1142 JSValueRef JSAddressBook::removeChangeListener(JSContextRef context,
1144 JSObjectRef thisObject,
1145 size_t argumentCount,
1146 const JSValueRef arguments[],
1147 JSValueRef* exception)
1150 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1151 AddressBookPtr addressBook;
1152 JSContextRef gContext;
1153 AddressBookController *controller;
1156 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1158 ThrowMsg(InvalidArgumentException, "No private object.");
1160 addressBook = controller->getObject();
1161 gContext = controller->getContext();
1162 } Catch(Exception) {
1163 LoggerE("No private object");
1164 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1167 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER);
1168 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1173 ArgumentValidator validator(context, argumentCount, arguments);
1174 watchId = validator.toLong(0, false);
1175 } catch (const TypeMismatchException& err ) {
1176 return JSWebAPIErrorFactory::postException(context, exception, err);
1177 } catch(const BasePlatformException& err) {
1178 return JSWebAPIErrorFactory::postException(context, exception, err);
1179 } catch(const ConversionException& err) {
1180 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1181 } catch(const NullPointerException& err) {
1182 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1185 EventAddressBookRemoveChangeListenerPtr dplEvent(new EventAddressBookRemoveChangeListener());
1187 dplEvent->setId(watchId);
1188 dplEvent->setForSynchronousCall();
1191 addressBook->removeChangeListener(dplEvent);
1192 } Catch(Exception) {
1193 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1194 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1197 ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
1198 DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1199 ContactListenerManagerSingleton::Instance().unregisterListener(listenerItem);
1201 if (!dplEvent->getResult())
1203 switch (dplEvent->getExceptionCode())
1205 case ExceptionCodes::InvalidArgumentException:
1206 case ExceptionCodes::NotFoundException:
1207 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "Watch id not found");
1210 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1214 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1215 return JSValueMakeUndefined(context);
1218 JSValueRef JSAddressBook::getGroup(JSContextRef context,
1220 JSObjectRef thisObject,
1221 size_t argumentCount,
1222 const JSValueRef arguments[],
1223 JSValueRef* exception)
1226 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1227 AddressBookPtr addressBook;
1228 AddressBookController *controller;
1229 JSContextRef gContext;
1232 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1234 ThrowMsg(InvalidArgumentException, "No private object.");
1236 addressBook = controller->getObject();
1237 gContext = controller->getContext();
1238 } Catch(Exception) {
1239 LoggerE("No private object");
1240 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1243 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUP);
1244 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1248 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1250 ArgumentValidator validator(context, argumentCount, arguments);
1251 id = validator.toString(0, false);
1252 } catch (const TypeMismatchException& err ) {
1253 return JSWebAPIErrorFactory::postException(context, exception, err);
1254 } catch(const BasePlatformException& err) {
1255 return JSWebAPIErrorFactory::postException(context, exception, err);
1256 } catch(const ConversionException& err) {
1257 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1258 } catch(const NullPointerException& err) {
1259 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1262 EventAddressBookGetGroupPtr dplEvent(new EventAddressBookGetGroup());
1264 dplEvent->setId(id);
1265 dplEvent->setForSynchronousCall();
1268 addressBook->getGroup(dplEvent);
1269 } Catch(Exception) {
1270 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1271 return JSWebAPIErrorFactory::postException(context, exception,
1272 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1275 if (!dplEvent->getResult() || !dplEvent->getContactGroupIsSet())
1277 std::stringstream oss;
1278 switch (dplEvent->getExceptionCode())
1280 case ExceptionCodes::NotFoundException:
1281 case ExceptionCodes::InvalidArgumentException:
1282 LoggerE("Not Found error : " << id);
1283 oss << "No Group id '" << id << "'";
1284 return JSWebAPIErrorFactory::postException(context, exception,
1285 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1287 case ExceptionCodes::PlatformException:
1288 return JSWebAPIErrorFactory::postException(context, exception,
1289 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1292 return JSWebAPIErrorFactory::postException(context, exception,
1293 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1298 ContactGroupPtr group = dplEvent->getContactGroup();
1302 result = converter->toJSValueRef(group);
1303 } Catch(Exception) {
1304 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1305 return JSWebAPIErrorFactory::postException(context, exception,
1306 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1308 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1312 JSValueRef JSAddressBook::addGroup(JSContextRef context,
1314 JSObjectRef thisObject,
1315 size_t argumentCount,
1316 const JSValueRef arguments[],
1317 JSValueRef* exception)
1320 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1321 AddressBookPtr addressBook;
1322 AddressBookController *controller;
1323 JSContextRef gContext;
1326 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1328 ThrowMsg(InvalidArgumentException, "No private object.");
1330 addressBook = controller->getObject();
1331 gContext = controller->getContext();
1332 } Catch(Exception) {
1333 LoggerE("No private object");
1334 return JSWebAPIErrorFactory::postException(context, exception,
1335 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1338 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_GROUP);
1339 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1342 ArgumentValidator validator(context, argumentCount, arguments);
1343 validator.toObject(0, false);
1345 } catch (const TypeMismatchException& err ) {
1346 return JSWebAPIErrorFactory::postException(context, exception, err);
1347 } catch(const BasePlatformException& err) {
1348 return JSWebAPIErrorFactory::postException(context, exception, err);
1349 } catch(const ConversionException& err) {
1350 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1351 } catch(const NullPointerException& err) {
1352 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1355 ContactGroupPtr group(NULL);
1357 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1359 if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
1360 ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
1362 group = converter->toContactGroup(arguments[0]);
1363 } Catch(Exception) {
1364 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1365 return JSWebAPIErrorFactory::postException(context, exception,
1366 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactGroup object'");
1369 EventAddressBookAddGroupPtr dplEvent(new EventAddressBookAddGroup());
1371 dplEvent->setContactGroup(group);
1372 dplEvent->setForSynchronousCall();
1375 addressBook->addGroup(dplEvent);
1376 } Catch(Exception) {
1377 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1378 return JSWebAPIErrorFactory::postException(context, exception,
1379 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1382 if (!dplEvent->getResult())
1384 switch (dplEvent->getExceptionCode())
1386 case ExceptionCodes::PlatformException:
1387 return JSWebAPIErrorFactory::postException(context, exception,
1388 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1391 return JSWebAPIErrorFactory::postException(context, exception,
1392 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1396 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1397 return JSValueMakeUndefined(context);
1400 JSValueRef JSAddressBook::updateGroup(JSContextRef context,
1402 JSObjectRef thisObject,
1403 size_t argumentCount,
1404 const JSValueRef arguments[],
1405 JSValueRef* exception)
1408 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1409 AddressBookPtr addressBook;
1410 AddressBookController *controller;
1411 JSContextRef gContext;
1414 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1416 ThrowMsg(InvalidArgumentException, "No private object.");
1418 addressBook = controller->getObject();
1419 gContext = controller->getContext();
1420 } Catch(Exception) {
1421 LoggerE("No private object");
1422 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1425 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_GROUP);
1426 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1429 ArgumentValidator validator(context, argumentCount, arguments);
1430 validator.toObject(0, false);
1432 } catch (const TypeMismatchException& err ) {
1433 return JSWebAPIErrorFactory::postException(context, exception, err);
1434 } catch(const BasePlatformException& err) {
1435 return JSWebAPIErrorFactory::postException(context, exception, err);
1436 } catch(const ConversionException& err) {
1437 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1438 } catch(const NullPointerException& err) {
1439 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1442 ContactGroupPtr contact(NULL);
1444 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1446 if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
1447 ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
1448 contact = converter->toContactGroup(arguments[0]);
1449 } Catch(Exception) {
1450 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1451 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "1st argument is not a 'ContactGroup object'");
1454 EventAddressBookUpdateGroupPtr dplEvent(new EventAddressBookUpdateGroup());
1456 dplEvent->setContactGroup(contact);
1457 dplEvent->setForSynchronousCall();
1460 addressBook->updateGroup(dplEvent);
1461 } Catch(Exception) {
1462 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1463 return JSWebAPIErrorFactory::postException(context, exception,
1464 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1467 if (!dplEvent->getResult())
1469 std::stringstream oss;
1470 switch (dplEvent->getExceptionCode())
1472 case ExceptionCodes::NotFoundException:
1473 case ExceptionCodes::InvalidArgumentException:
1474 oss << "No Group id '" << contact->getId() << "'";
1475 return JSWebAPIErrorFactory::postException(context, exception,
1476 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1478 case ExceptionCodes::PlatformException:
1479 return JSWebAPIErrorFactory::postException(context, exception,
1480 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1483 return JSWebAPIErrorFactory::postException(context, exception,
1484 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1488 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1489 return JSValueMakeUndefined(context);
1492 JSValueRef JSAddressBook::removeGroup(JSContextRef context,
1494 JSObjectRef thisObject,
1495 size_t argumentCount,
1496 const JSValueRef arguments[],
1497 JSValueRef* exception)
1500 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1501 AddressBookPtr addressBook;
1502 AddressBookController *controller;
1505 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1507 ThrowMsg(InvalidArgumentException, "No private object.");
1509 addressBook = controller->getObject();
1510 } Catch(Exception) {
1511 LoggerE("No private object");
1512 return JSWebAPIErrorFactory::postException(context, exception,
1513 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1516 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_GROUP);
1517 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1522 ArgumentValidator validator(context, argumentCount, arguments);
1523 groupId = validator.toString(0, false);
1524 } catch (const TypeMismatchException& err ) {
1525 return JSWebAPIErrorFactory::postException(context, exception, err);
1526 } catch(const BasePlatformException& err) {
1527 return JSWebAPIErrorFactory::postException(context, exception, err);
1528 } catch(const ConversionException& err) {
1529 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1530 } catch(const NullPointerException& err) {
1531 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "");
1534 EventAddressBookRemoveGroupPtr dplEvent(new EventAddressBookRemoveGroup());
1536 dplEvent->setContactGroupId(groupId);
1537 dplEvent->setForSynchronousCall();
1540 addressBook->removeGroup(dplEvent);
1541 } Catch(Exception) {
1542 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1543 return JSWebAPIErrorFactory::postException(context, exception,
1544 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1547 if (!dplEvent->getResult())
1549 std::stringstream oss;
1550 switch (dplEvent->getExceptionCode())
1552 case ExceptionCodes::NotFoundException:
1553 case ExceptionCodes::InvalidArgumentException:
1554 LoggerE("Not Found error : " << groupId);
1555 oss << "No Group id '" << groupId << "'";
1556 return JSWebAPIErrorFactory::postException(context, exception,
1557 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1559 case ExceptionCodes::PlatformException:
1560 return JSWebAPIErrorFactory::postException(context, exception,
1561 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1564 return JSWebAPIErrorFactory::postException(context, exception,
1565 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1569 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1570 return JSValueMakeUndefined(context);
1573 JSValueRef JSAddressBook::getGroups(JSContextRef context,
1575 JSObjectRef thisObject,
1576 size_t argumentCount,
1577 const JSValueRef arguments[],
1578 JSValueRef* exception)
1581 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1582 AddressBookPtr addressBook;
1583 AddressBookController *controller;
1584 JSContextRef gContext;
1587 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1589 ThrowMsg(InvalidArgumentException, "No private object.");
1591 addressBook = controller->getObject();
1592 gContext = controller->getContext();
1593 } Catch(Exception) {
1594 LoggerE("No private object");
1595 return JSWebAPIErrorFactory::postException(context, exception,
1596 JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Wrong object");
1599 AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUPS);
1600 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1604 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1606 EventAddressBookGetGroupsPtr dplEvent(new EventAddressBookGetGroups());
1608 dplEvent->setForSynchronousCall();
1611 addressBook->getGroups(dplEvent);
1612 } Catch(Exception) {
1613 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1614 return JSWebAPIErrorFactory::postException(context, exception,
1615 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1618 if (!dplEvent->getResult() || !dplEvent->getContactGroupsIsSet())
1620 std::stringstream oss;
1621 switch (dplEvent->getExceptionCode())
1623 case ExceptionCodes::NotFoundException:
1624 case ExceptionCodes::InvalidArgumentException:
1625 LoggerE("Not Found error : " << id);
1626 oss << "No Group id '" << id << "'";
1627 return JSWebAPIErrorFactory::postException(context, exception,
1628 JSWebAPIErrorFactory::NOT_FOUND_ERROR, oss.str());
1630 case ExceptionCodes::PlatformException:
1631 return JSWebAPIErrorFactory::postException(context, exception,
1632 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1635 return JSWebAPIErrorFactory::postException(context, exception,
1636 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1641 ContactGroupArrayPtr groups = dplEvent->getContactGroups();
1645 result = converter->toJSValueRef(groups);
1646 } Catch(Exception) {
1647 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1648 return JSWebAPIErrorFactory::postException(context, exception,
1649 JSWebAPIErrorFactory::UNKNOWN_ERROR, "Internal error");
1651 TIME_TRACER_ITEM_END(__FUNCTION__, 0);