wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Contact / JSAddressBook.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        JSAddressBook.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief       Implementation of the JSAddressBook class
23  */
24
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 <JSTizenExceptionFactory.h>
31 #include <JSTizenException.h>
32 #include <SecurityExceptions.h>
33 #include <FilterConverter.h>
34 #include "ContactFactory.h"
35 #include "EventAddressBookAddBatch.h"
36 #include "EventAddressBookUpdateBatch.h"
37 #include "EventAddressBookRemoveBatch.h"
38 #include "EventAddressBookFind.h"
39 #include "EventAddressBookChangeListener.h"
40 #include "EventAddressBookRemoveBatch.h"
41 #include "plugin_config.h"
42 #include "JSAddressBook.h"
43 #include "JSContact.h"
44 #include "JSContactGroup.h"
45 #include "ContactConverter.h"
46 #include "AddressBookController.h"
47 #include "JSAddressBookChangeCallbackManager.h"
48 #include "ContactAsyncCallbackManager.h"
49 #include "ContactListenerManager.h"
50 #include "ContactFilterConverter.h"
51 #include <ArgumentValidator.h>
52 #include <JSWebAPIError.h>
53 #include <JSUtil.h>
54 #include <TimeTracer.h>
55 #include <Logger.h>
56
57 using namespace std;
58
59 #define TIZEN_ADDRESS_BOOK_ID           "id"
60 #define TIZEN_ADDRESS_BOOK_NAME         "name"
61 #define TIZEN_ADDRESS_BOOK_READ_ONLY    "readOnly"
62 #define TIZEN_ADDRESS_BOOK_ACCOUNT_ID   "accountId"
63
64 #define TIZEN_ADDRESS_BOOK              "AddressBook"
65
66 namespace DeviceAPI {
67 namespace Contact {
68
69 using namespace DeviceAPI::Common;
70 using namespace DeviceAPI::Tizen;\rusing namespace WrtDeviceApis::Commons;
71 using namespace WrtDeviceApis::CommonsJavaScript;
72
73 JSClassRef JSAddressBook::m_jsClassRef = NULL;
74
75 JSClassDefinition JSAddressBook::m_classInfo = {
76         0,
77         kJSClassAttributeNone,
78         TIZEN_ADDRESS_BOOK,
79         0,
80         m_property,
81         m_function,
82         Initialize,
83         Finalize,
84         NULL, //HasProperty,
85         NULL, //GetProperty,
86         NULL, //SetProperty,
87         NULL, //DeleteProperty,
88         NULL, //GetPropertyNames,
89         NULL, //CallAsFunction,
90         NULL, //CallAsConstructor,
91         NULL, //HasInstance,
92         NULL, //ConvertToType,
93 };
94
95 JSStaticValue JSAddressBook::m_property[] = {
96         { TIZEN_ADDRESS_BOOK_ID, getId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
97         { TIZEN_ADDRESS_BOOK_NAME, getName, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
98         { TIZEN_ADDRESS_BOOK_READ_ONLY, getReadOnly, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
99 //      { TIZEN_ADDRESS_BOOK_ACCOUNT_ID, getAccountId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
100         { 0, 0, 0, 0 }
101 };
102
103 JSStaticFunction JSAddressBook::m_function[] = {
104         { "get", get, kJSPropertyAttributeNone },
105         { "add", add, kJSPropertyAttributeNone },
106         { "addBatch", addBatch, kJSPropertyAttributeNone },
107         { "update", update, kJSPropertyAttributeNone },
108         { "updateBatch", updateBatch, kJSPropertyAttributeNone },
109         { "remove", remove, kJSPropertyAttributeNone },
110         { "removeBatch", removeBatch, kJSPropertyAttributeNone },
111         { "find", find, kJSPropertyAttributeNone },
112         { "addChangeListener", addChangeListener, kJSPropertyAttributeNone },
113         { "removeChangeListener", removeChangeListener, kJSPropertyAttributeNone },
114         { "getGroup", getGroup, kJSPropertyAttributeNone },
115         { "addGroup", addGroup, kJSPropertyAttributeNone },
116         { "updateGroup", updateGroup, kJSPropertyAttributeNone },
117         { "removeGroup", removeGroup, kJSPropertyAttributeNone },
118         { "getGroups", getGroups, kJSPropertyAttributeNone },
119         { 0, 0, 0 }
120 };
121
122 const JSClassDefinition* JSAddressBook::getClassInfo()
123 {
124         return &m_classInfo;
125 }
126
127 const JSClassRef JSAddressBook::getClassRef()
128 {
129         LoggerI("entered");
130         if (!m_jsClassRef) {
131                 m_jsClassRef = JSClassCreate(&m_classInfo);
132         }
133         return m_jsClassRef;
134 }
135
136 void JSAddressBook::Initialize(JSContextRef context,
137                 JSObjectRef object)
138 {
139 //      AddressBookController *priv =
140 //              static_cast<AddressBookController*>(JSObjectGetPrivate(object));
141 }
142
143 void JSAddressBook::Finalize(JSObjectRef object)
144 {
145         AddressBookController *priv =
146                 static_cast<AddressBookController*>(JSObjectGetPrivate(object));
147
148         delete priv;
149 }
150
151 bool JSAddressBook::isObjectOfClass(JSContextRef context, JSValueRef value)
152 {
153         return JSValueIsObjectOfClass(context, value, getClassRef());
154 }
155
156 AddressBookPtr JSAddressBook::getAddressBook(JSContextRef context, JSValueRef value)
157 {
158         if (!isObjectOfClass(context, value)) {
159                 Throw(InvalidArgumentException);
160         }
161         JSObjectRef object = JSValueToObject(context, value, NULL);
162         if (!object) {
163                 Throw(InvalidArgumentException);
164         }
165         AddressBookController *priv = static_cast<AddressBookController*>(JSObjectGetPrivate(object));
166         if (!priv) {
167                 Throw(NullPointerException);
168         }
169         return priv->getObject();
170 }
171
172 AddressBookPtr JSAddressBook::getPrivData(JSObjectRef object)
173 {
174         AddressBookController *priv =
175                 static_cast<AddressBookController*>(JSObjectGetPrivate(object));
176         if (priv) {
177                 return priv->getObject();
178         }
179         Throw(NullPointerException);
180 }
181
182 JSValueRef JSAddressBook::getId(JSContextRef context,
183                 JSObjectRef object,
184                 JSStringRef propertyName,
185                 JSValueRef* exception)
186 {
187         Try
188         {
189                 ContactConverterFactory::ConverterType converter =
190                                 ContactConverterFactory::getConverter(context);
191                 AddressBookPtr addressBook = getPrivData(object);
192                 string id = addressBook->getId();
193                 if(id != "")
194                         return converter->toJSValueRef(id);
195                 else
196                         return JSValueMakeNull(context);
197         }
198         Catch(WrtDeviceApis::Commons::Exception)
199         {
200                 LoggerW("trying to get incorrect value");
201         }
202         return JSValueMakeUndefined(context);
203 }
204
205 JSValueRef JSAddressBook::getName(JSContextRef context,
206                 JSObjectRef object,
207                 JSStringRef propertyName,
208                 JSValueRef* exception)
209 {
210         Try
211         {
212                 ContactConverterFactory::ConverterType converter =
213                                 ContactConverterFactory::getConverter(context);
214                 AddressBookPtr addressBook = getPrivData(object);
215                 return converter->toJSValueRef(addressBook->getName());
216         }
217         Catch(WrtDeviceApis::Commons::Exception)
218         {
219                 LoggerW("trying to get incorrect value");
220         }
221
222         return JSValueMakeUndefined(context);
223 }
224
225 JSValueRef JSAddressBook::getReadOnly(JSContextRef context,
226                 JSObjectRef object,
227                 JSStringRef propertyName,
228                 JSValueRef* exception)
229 {
230         Try
231         {
232                 ContactConverterFactory::ConverterType converter =
233                                 ContactConverterFactory::getConverter(context);
234                 AddressBookPtr addressBook = getPrivData(object);
235                 return converter->toJSValueRef(addressBook->getReadOnly());
236         }
237         Catch(WrtDeviceApis::Commons::Exception)
238         {
239                 LoggerW("trying to get incorrect value");
240         }
241
242         return JSValueMakeUndefined(context);
243 }
244
245 JSValueRef JSAddressBook::getAccountId(JSContextRef context,
246                 JSObjectRef object,
247                 JSStringRef propertyName,
248                 JSValueRef* exception)
249 {
250         Try
251         {
252                 ContactConverterFactory::ConverterType converter =
253                                 ContactConverterFactory::getConverter(context);
254                 AddressBookPtr addressBook = getPrivData(object);
255                 string accountId = addressBook->getAccountId();
256                 if(accountId != "")
257                         return converter->toJSValueRef(accountId);
258                 else
259                         return JSValueMakeNull(context);
260         }
261         Catch(WrtDeviceApis::Commons::Exception)
262         {
263                 LoggerW("trying to get incorrect value");
264         }
265         return JSValueMakeUndefined(context);
266 }
267
268 JSValueRef JSAddressBook::get(JSContextRef context,
269                 JSObjectRef object,
270                 JSObjectRef thisObject,
271                 size_t argumentCount,
272                 const JSValueRef arguments[],
273                 JSValueRef* exception)
274 {
275         LoggerD("entered");
276         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
277         AddressBookPtr addressBook;
278         AddressBookController *controller;
279         JSContextRef gContext;
280
281         Try     {
282                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
283                 if (!controller) {
284                         ThrowMsg(InvalidArgumentException, "No private object.");
285                 }
286                 addressBook = controller->getObject();
287                 gContext = controller->getContext();
288
289         } Catch(Exception) {
290                 LoggerE("No private object");
291                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
292         }
293
294         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET);
295         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
296
297         string id;
298
299         try     {
300                 ArgumentValidator validator(context, argumentCount, arguments);
301                 id = validator.toString(0, false);
302         } catch (const TypeMismatchException& err ) {
303                 return JSWebAPIError::throwException(context, exception, err);
304         } catch(const BasePlatformException& err) {
305                 return JSWebAPIError::throwException(context, exception, err);
306         } catch(const ConversionException& err) {
307                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
308         } catch(const NullPointerException& err) {
309                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
310         }
311
312         EventAddressBookGetPtr dplEvent(new EventAddressBookGet());
313
314         dplEvent->setId(id);
315     dplEvent->setForSynchronousCall();
316
317         Try {
318                 addressBook->get(dplEvent);
319         } Catch(Exception) {
320                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
321                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
322         }
323
324         if (!dplEvent->getResult() || !dplEvent->getContactIsSet())
325         {
326                 std::stringstream oss;
327                 switch (dplEvent->getExceptionCode())
328                 {
329                 case ExceptionCodes::NotFoundException:
330                 case ExceptionCodes::InvalidArgumentException:
331                         LoggerE("Not Found error : " << id);
332                         oss << "No Contact id '" << id << "'";
333                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
334                         break;
335                 case ExceptionCodes::PlatformException:
336                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
337                         break;
338                 default:
339                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
340                         break;
341                 }
342         }
343
344         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
345
346         ContactPtr contact = dplEvent->getContact();
347         JSValueRef result;
348         Try {
349                 result = converter->toJSValueRef(contact);
350         } Catch(Exception) {
351                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
352                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
353         }
354
355         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
356         return result;
357 }
358
359 JSValueRef JSAddressBook::add(JSContextRef context,
360                 JSObjectRef object,
361                 JSObjectRef thisObject,
362                 size_t argumentCount,
363                 const JSValueRef arguments[],
364                 JSValueRef* exception)
365 {
366         LoggerD("entered");
367         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
368         AddressBookPtr addressBook;
369         AddressBookController *controller;
370         JSContextRef gContext;
371
372         Try     {
373                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
374                 if (!controller) {
375                         ThrowMsg(InvalidArgumentException, "No private object.");
376                 }
377                 addressBook = controller->getObject();
378                 gContext = controller->getContext();
379         } Catch(Exception) {
380                 LoggerE("No private object");
381                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
382         }
383
384         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD);
385         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
386
387         try {
388                 ArgumentValidator validator(context, argumentCount, arguments);
389                 validator.toObject(0, false);
390         } catch (const TypeMismatchException& err ) {
391                 return JSWebAPIError::throwException(context, exception, err);
392         } catch(const BasePlatformException& err) {
393                 return JSWebAPIError::throwException(context, exception, err);
394         } catch(const ConversionException& err) {
395                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
396         } catch(const NullPointerException& err) {
397                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
398         }
399
400         ContactPtr contact(NULL);
401
402         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
403         Try     {
404                 if (!JSContact::isObjectOfClass(context, arguments[0]))
405                         ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
406                 contact = converter->toContact(arguments[0]);
407         } Catch(Exception) {
408                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
409                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Contact object'");
410         }
411
412         EventAddressBookAddPtr dplEvent(new EventAddressBookAdd());
413
414         dplEvent->setContact(contact);
415     dplEvent->setForSynchronousCall();
416
417         Try {
418                 addressBook->add(dplEvent);
419         } Catch(Exception) {
420                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
421                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
422         }
423
424         if (!dplEvent->getResult())
425         {
426                 switch (dplEvent->getExceptionCode())
427                 {
428                 case ExceptionCodes::PlatformException:
429                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
430                         break;
431                 case ExceptionCodes::InvalidArgumentException:
432                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "There is Invalid input value");
433                         break;
434                 default:
435                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
436                         break;
437                 }
438         }
439
440         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
441         return JSValueMakeUndefined(context);
442 }
443
444 JSValueRef JSAddressBook::addBatch(JSContextRef context,
445                 JSObjectRef object,
446                 JSObjectRef thisObject,
447                 size_t argumentCount,
448                 const JSValueRef arguments[],
449                 JSValueRef* exception)
450 {
451         LoggerD("entered");
452         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
453         AddressBookPtr addressBook;
454         JSContextRef gContext;
455         AddressBookController *controller;
456
457         bool js2ndParamIsFunction = false;
458         bool js3rdParamIsFunction = false;
459
460         Try     {
461                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
462                 if (!controller) {
463                         ThrowMsg(InvalidArgumentException, "No private object.");
464                 }
465                 addressBook = controller->getObject();
466                 gContext = controller->getContext();
467         } Catch(Exception) {
468                 LoggerE("No private object");
469                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
470         }
471
472         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_BATCH);
473         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
474
475         try {
476                 ArgumentValidator validator(context, argumentCount, arguments);
477
478                 validator.toObject(0, false);
479                 JSObjectRef successObj = validator.toFunction(1, true);
480                 if(successObj)
481                         js2ndParamIsFunction = true;
482
483                 JSObjectRef errorObj = validator.toFunction(2, true);
484                 if(errorObj)
485                         js3rdParamIsFunction = true;
486
487         } catch (const TypeMismatchException& err ) {
488                 return JSWebAPIError::throwException(context, exception, err);
489         } catch(const BasePlatformException& err) {
490                 return JSWebAPIError::throwException(context, exception, err);
491         } catch(const ConversionException& err) {
492                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
493         } catch(const NullPointerException& err) {
494                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
495         }
496
497         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
498
499         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
500
501         if(js2ndParamIsFunction)
502                 callbackManager->setOnSuccess(arguments[1]);
503
504         if(js3rdParamIsFunction)
505                 callbackManager->setOnError(arguments[2]);
506
507         callbackManager->setObject(thisObject);
508
509         EventAddressBookAddBatchPtr dplEvent(new EventAddressBookAddBatch());
510         Try {
511                 dplEvent->setContacts(converter->toContactArray(arguments[0]));
512         } Catch(ConversionException) {
513                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
514                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be an array of 'Contact object'");
515         }
516
517         // set event handler's data
518         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
519         dplEvent->setForAsynchronousCall(controller);
520
521 //      DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
522 //      IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
523
524         Try {
525                 addressBook->addBatch(dplEvent);
526                 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
527         } Catch(Exception) {
528                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
529                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
530         }
531
532         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
533 //      return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
534         return JSValueMakeUndefined(context);
535 }
536
537 JSValueRef JSAddressBook::update(JSContextRef context,
538                 JSObjectRef object,
539                 JSObjectRef thisObject,
540                 size_t argumentCount,
541                 const JSValueRef arguments[],
542                 JSValueRef* exception)
543 {
544         LoggerD("entered");
545         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
546         AddressBookPtr addressBook;
547         AddressBookController *controller;
548         JSContextRef gContext;
549
550         Try     {
551                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
552                 if (!controller) {
553                         ThrowMsg(InvalidArgumentException, "No private object.");
554                 }
555                 addressBook = controller->getObject();
556                 gContext = controller->getContext();
557         } Catch(Exception) {
558                 LoggerE("No private object");
559                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
560         }
561
562         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE);
563         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
564
565         try {
566                 ArgumentValidator validator(context, argumentCount, arguments);
567                 validator.toObject(0, false);
568
569         } catch (const TypeMismatchException& err ) {
570                 return JSWebAPIError::throwException(context, exception, err);
571         } catch(const BasePlatformException& err) {
572                 return JSWebAPIError::throwException(context, exception, err);
573         } catch(const ConversionException& err) {
574                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
575         } catch(const NullPointerException& err) {
576                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
577         }
578
579         ContactPtr contact(NULL);
580
581         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
582         Try     {
583                 if (!JSContact::isObjectOfClass(context, arguments[0]))
584                         ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
585                 contact = converter->toContact(arguments[0]);
586         } Catch(Exception) {
587                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
588                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument is not a 'Contact object'");
589         }
590
591         EventAddressBookUpdatePtr dplEvent(new EventAddressBookUpdate());
592
593         dplEvent->setContact(contact);
594     dplEvent->setForSynchronousCall();
595
596         Try {
597                 addressBook->update(dplEvent);
598         } Catch(Exception) {
599                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
600                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
601         }
602
603         if (!dplEvent->getResult())
604         {
605                 std::stringstream oss;
606                 switch (dplEvent->getExceptionCode())
607                 {
608                 case ExceptionCodes::NotFoundException:
609                 case ExceptionCodes::InvalidArgumentException:
610                         oss << "No Contact id '" << contact->getId() << "'";
611                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
612                         break;
613                 case ExceptionCodes::PlatformException:
614                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
615                         break;
616                 default:
617                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
618                         break;
619                 }
620         }
621
622         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
623         return JSValueMakeUndefined(context);
624 }
625
626 JSValueRef JSAddressBook::updateBatch(JSContextRef context,
627                 JSObjectRef object,
628                 JSObjectRef thisObject,
629                 size_t argumentCount,
630                 const JSValueRef arguments[],
631                 JSValueRef* exception)
632 {
633         LoggerD("entered");
634         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
635         AddressBookPtr addressBook;
636         JSContextRef gContext;
637         AddressBookController *controller;
638
639         bool js2ndParamIsFunction = false;
640         bool js3rdParamIsFunction = false;
641
642         Try     {
643                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
644                 if (!controller) {
645                         ThrowMsg(InvalidArgumentException, "No private object.");
646                 }
647                 addressBook = controller->getObject();
648                 gContext = controller->getContext();
649         } Catch(Exception) {
650                 LoggerE("No private object");
651                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
652         }
653
654         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_BATCH);
655         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
656
657         try {
658                 ArgumentValidator validator(context, argumentCount, arguments);
659
660                 validator.toObject(0, false);
661
662                 JSObjectRef successObj = validator.toFunction(1, true);
663                 if(successObj)
664                         js2ndParamIsFunction = true;
665
666                 JSObjectRef errorObj = validator.toFunction(2, true);
667                 if(errorObj)
668                         js3rdParamIsFunction = true;
669
670         } catch (const TypeMismatchException& err ) {
671                 return JSWebAPIError::throwException(context, exception, err);
672         } catch(const BasePlatformException& err) {
673                 return JSWebAPIError::throwException(context, exception, err);
674         } catch(const ConversionException& err) {
675                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
676         } catch(const NullPointerException& err) {
677                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
678         }
679
680         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
681
682         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
683
684         if(js2ndParamIsFunction)
685                 callbackManager->setOnSuccess(arguments[1]);
686
687         if(js3rdParamIsFunction)
688                 callbackManager->setOnError(arguments[2]);
689
690         callbackManager->setObject(thisObject);
691
692         EventAddressBookUpdateBatchPtr dplEvent(new EventAddressBookUpdateBatch());
693         Try {
694                 dplEvent->setContacts(converter->toContactArray(arguments[0]));
695         } Catch(ConversionException) {
696                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
697                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact object'");
698         }
699
700         // set event handler's data
701         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
702         dplEvent->setForAsynchronousCall(controller);
703
704 //      DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
705 //      IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
706
707         Try {
708                 addressBook->updateBatch(dplEvent);
709                 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
710         } Catch(Exception) {
711                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
712                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
713         }
714
715         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
716 //      return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
717         return JSValueMakeUndefined(context);
718 }
719
720 JSValueRef JSAddressBook::remove(JSContextRef context,
721                 JSObjectRef object,
722                 JSObjectRef thisObject,
723                 size_t argumentCount,
724                 const JSValueRef arguments[],
725                 JSValueRef* exception)
726 {
727         LoggerD("entered");
728         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
729         AddressBookPtr addressBook;
730         AddressBookController *controller;
731
732         Try     {
733                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
734                 if (!controller) {
735                         ThrowMsg(InvalidArgumentException, "No private object.");
736                 }
737                 addressBook = controller->getObject();
738         } Catch(Exception) {
739                 LoggerE("No private object");
740                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
741         }
742
743         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE);
744         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
745
746         ArgumentValidator validator(context, argumentCount, arguments);
747         string contactId;
748         try     {
749                 contactId = validator.toString(0, false);
750         } catch (const TypeMismatchException& err ) {
751                 return JSWebAPIError::throwException(context, exception, err);
752         } catch(const BasePlatformException& err) {
753                 return JSWebAPIError::throwException(context, exception, err);
754         } catch(const ConversionException& err) {
755                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
756         } catch(const NullPointerException& err) {
757                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
758         }
759
760         EventAddressBookRemovePtr dplEvent(new EventAddressBookRemove());
761
762         dplEvent->setContactId(contactId);
763     dplEvent->setForSynchronousCall();
764
765         Try {
766                 addressBook->remove(dplEvent);
767         } Catch(Exception) {
768                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
769                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
770         }
771
772         if (!dplEvent->getResult())
773         {
774                 std::stringstream oss;
775                 switch (dplEvent->getExceptionCode())
776                 {
777                 case ExceptionCodes::NotFoundException:
778                 case ExceptionCodes::InvalidArgumentException:
779                         LoggerE("Not Found error : " << contactId);
780                         oss << "No Contact id '" << contactId << "'";
781                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
782                         break;
783                 case ExceptionCodes::PlatformException:
784                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
785                         break;
786                 default:
787                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
788                         break;
789                 }
790         }
791         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
792         return JSValueMakeUndefined(context);
793 }
794
795 JSValueRef JSAddressBook::removeBatch(JSContextRef context,
796                 JSObjectRef object,
797                 JSObjectRef thisObject,
798                 size_t argumentCount,
799                 const JSValueRef arguments[],
800                 JSValueRef* exception)
801 {
802         LoggerD("entered");
803         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
804         AddressBookPtr addressBook;
805         JSContextRef gContext;
806         AddressBookController *controller;
807
808         bool js2ndParamIsFunction = false;
809         bool js3rdParamIsFunction = false;
810
811         Try     {
812                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
813                 if (!controller) {
814                         ThrowMsg(InvalidArgumentException, "No private object.");
815                 }
816                 addressBook = controller->getObject();
817                 gContext = controller->getContext();
818         } Catch(Exception) {
819                 LoggerE("No private object");
820                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
821         }
822
823         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_BATCH);
824         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
825
826         try {
827                 ArgumentValidator validator(context, argumentCount, arguments);
828
829                 validator.toObject(0, false);
830                 JSObjectRef successObj = validator.toFunction(1, true);
831                 if(successObj)
832                         js2ndParamIsFunction = true;
833
834                 JSObjectRef errorObj = validator.toFunction(2, true);
835                 if(errorObj)
836                         js3rdParamIsFunction = true;
837
838         } catch (const TypeMismatchException& err ) {
839                 return JSWebAPIError::throwException(context, exception, err);
840         } catch(const BasePlatformException& err) {
841                 return JSWebAPIError::throwException(context, exception, err);
842         } catch(const ConversionException& err) {
843                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
844         } catch(const NullPointerException& err) {
845                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
846         }
847
848         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
849
850         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
851
852         if(js2ndParamIsFunction)
853                 callbackManager->setOnSuccess(arguments[1]);
854
855         if(js3rdParamIsFunction)
856                 callbackManager->setOnError(arguments[2]);
857
858         callbackManager->setObject(thisObject);
859
860         EventAddressBookRemoveBatchPtr dplEvent(new EventAddressBookRemoveBatch());
861         Try {
862                 dplEvent->setContactIds(converter->toStringArray(arguments[0]));
863         } Catch(ConversionException) {
864                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
865                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact id'");
866         }
867
868         // set event handler's data
869         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
870         dplEvent->setForAsynchronousCall(controller);
871
872 //      DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
873 //      IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
874
875         Try {
876                 addressBook->removeBatch(dplEvent);
877                 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
878         } Catch(Exception) {
879                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
880                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
881         }
882
883         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
884 //      return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
885         return JSValueMakeUndefined(context);
886 }
887
888 JSValueRef JSAddressBook::find(JSContextRef context,
889                 JSObjectRef object,
890                 JSObjectRef thisObject,
891                 size_t argumentCount,
892                 const JSValueRef arguments[],
893                 JSValueRef* exception)
894 {
895         LoggerD("entered");
896         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
897         AddressBookPtr addressBook;
898         JSContextRef gContext;
899         AddressBookController *controller;
900
901         bool js2ndParamIsFunction = false;
902         bool js3rdParamIsObject = false;
903         bool js4thParamIsObject = false;
904
905         Try     {
906                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
907                 if (!controller) {
908                         ThrowMsg(InvalidArgumentException, "No private object.");
909                 }
910                 addressBook = controller->getObject();
911                 gContext = controller->getContext();
912         } Catch(Exception) {
913                 LoggerE("No private object");
914                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
915         }
916
917         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_FIND);
918         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
919
920         try {
921                 ArgumentValidator validator(context, argumentCount, arguments);
922
923                 validator.toFunction(0, false);
924                 JSObjectRef errorObj = validator.toFunction(1, true);
925                 if(errorObj)
926                         js2ndParamIsFunction = true;
927
928                 JSObjectRef filterObj = validator.toObject(2, true);
929                 if(filterObj)
930                         js3rdParamIsObject = true;
931
932                 JSObjectRef sortObj = validator.toObject(3, true);
933                 if(sortObj)
934                         js4thParamIsObject = true;
935
936         } catch (const TypeMismatchException& err ) {
937                 return JSWebAPIError::throwException(context, exception, err);
938         } catch(const BasePlatformException& err) {
939                 return JSWebAPIError::throwException(context, exception, err);
940         } catch(const ConversionException& err) {
941                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
942         } catch(const NullPointerException& err) {
943                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
944         }
945
946         JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
947
948         callbackManager->setOnSuccess(arguments[0]);
949
950         if (js2ndParamIsFunction)
951                 callbackManager->setOnError(arguments[1]);
952
953         callbackManager->setObject(thisObject);
954
955         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
956         ContactFilterConverterFactory::ConverterType filterConverter = ContactFilterConverterFactory::getConverter(context);
957
958         EventAddressBookFindPtr dplEvent(new EventAddressBookFind());
959         Try {
960                 if (js3rdParamIsObject)
961                         dplEvent->setFilter(filterConverter->toFilter(arguments[2]));
962         } Catch(Exception) {
963                 LoggerE("Error on 3rd parameter conversion : " << _rethrown_exception.GetMessage());
964                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an 'Filter object' or 'null'");
965         }
966
967         Try {
968                 if (js4thParamIsObject)
969                         dplEvent->setSortMode(filterConverter->toSortMode(arguments[3]));
970         } Catch(Exception) {
971                 LoggerE("Error on 4th parameter conversion : " << _rethrown_exception.GetMessage());
972                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "4th argument must be an 'SortMode object' or 'null'");
973         }
974
975         // set event handler's data
976         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
977         dplEvent->setForAsynchronousCall(controller);
978
979 //      DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
980 //      IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
981
982         Try {
983                 addressBook->find(dplEvent);
984                 ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
985         } Catch(Exception) {
986                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
987                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
988         }
989
990         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
991 //      return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
992         return JSValueMakeUndefined(context);
993 }
994
995 JSValueRef JSAddressBook::addChangeListener(JSContextRef context,
996                 JSObjectRef object,
997                 JSObjectRef thisObject,
998                 size_t argumentCount,
999                 const JSValueRef arguments[],
1000                 JSValueRef* exception)
1001 {
1002         LoggerD("entered");
1003         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1004         AddressBookPtr addressBook;
1005         JSContextRef gContext;
1006         AddressBookController *controller;
1007
1008         bool js2ndParamIsFunction = false;
1009
1010         Try     {
1011                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1012                 if (!controller) {
1013                         ThrowMsg(InvalidArgumentException, "No private object.");
1014                 }
1015                 addressBook = controller->getObject();
1016                 gContext = controller->getContext();
1017         } Catch(Exception) {
1018                 LoggerE("No private object");
1019                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1020         }
1021
1022         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_CHANGE_LISTENER);
1023         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1024
1025         BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
1026         try {
1027                 ArgumentValidator Argvalidator(context, argumentCount, arguments);
1028                 Argvalidator.toObject(0, false);
1029                 JSObjectRef errorObj = Argvalidator.toFunction(1, true);
1030                 if(errorObj)
1031                         js2ndParamIsFunction = true;
1032         } catch (const TypeMismatchException& err ) {
1033                 return JSWebAPIError::throwException(context, exception, err);
1034         } catch(const BasePlatformException& err) {
1035                 return JSWebAPIError::throwException(context, exception, err);
1036         } catch(const ConversionException& err) {
1037                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1038         } catch(const NullPointerException& err) {
1039                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1040         }
1041
1042         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
1043
1044         JSValueRef oncontactsadded;
1045         JSValueRef oncontactsupdated;
1046         JSValueRef oncontactsdeleted;
1047         Try {
1048                 JSObjectRef callbackObject = converter->toJSObjectRef(arguments[0]);
1049
1050                 oncontactsadded = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsadded");
1051                 if (validator->isNullOrUndefined(oncontactsadded))
1052                         oncontactsadded = NULL;
1053                 else if (!validator->isCallback(oncontactsadded)) {
1054                         ThrowMsg(ConversionException, "2nd argument's oncontactsadded attribute is not a 'function'");
1055                 }
1056
1057                 oncontactsupdated = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsupdated");
1058                 if (validator->isNullOrUndefined(oncontactsupdated))
1059                         oncontactsupdated = NULL;
1060                 else if (!validator->isCallback(oncontactsupdated)) {
1061                         ThrowMsg(ConversionException, "2nd argument's oncontactsupdated attribute is not a 'function'");
1062                 }
1063
1064                 oncontactsdeleted = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsremoved");
1065                 if (validator->isNullOrUndefined(oncontactsdeleted))
1066                         oncontactsdeleted = NULL;
1067                 else if (!validator->isCallback(oncontactsdeleted)) {
1068                         ThrowMsg(ConversionException, "2nd argument's oncontactsremoved attribute is not a 'function'");
1069                 }
1070
1071                 if (oncontactsadded == NULL && oncontactsupdated == NULL && oncontactsdeleted == NULL)
1072                         ThrowMsg(ConversionException, "2nd argument must have at least one function");
1073
1074         } Catch(ConversionException) {
1075                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1076                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1077         }
1078
1079         JSAddressBookChangeCallbackManagerPtr callbackManager = JSAddressBookChangeCallbackManager::createObject(gContext);
1080
1081         callbackManager->setOnContactsAdded(oncontactsadded);
1082         callbackManager->setOnContactsUpdated(oncontactsupdated);
1083         callbackManager->setOnContactsDeleted(oncontactsdeleted);
1084         if(js2ndParamIsFunction)
1085                 callbackManager->setOnError(arguments[1]);
1086
1087         EventAddressBookChangeListenerEmitterPtr emitter(new EventAddressBookChangeListenerEmitter());
1088
1089         emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
1090         emitter->setListener(controller);
1091
1092         EventAddressBookAddChangeListenerPtr dplEvent(new EventAddressBookAddChangeListener());
1093
1094         dplEvent->setEmitter(emitter);
1095     dplEvent->setForSynchronousCall();
1096
1097         Try {
1098                 addressBook->addChangeListener(dplEvent);
1099         } Catch(Exception) {
1100                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1101                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1102         }
1103
1104         if (!dplEvent->getResult() || !dplEvent->getIdIsSet())
1105         {
1106                 switch (dplEvent->getExceptionCode())
1107                 {
1108                 case ExceptionCodes::InvalidArgumentException:
1109                 case ExceptionCodes::PlatformException:
1110                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1111                         break;
1112                 default:
1113                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1114                         break;
1115                 }
1116         }
1117
1118         long watchId = dplEvent->getId();
1119
1120         ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
1121         DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1122         ContactListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
1123
1124         JSValueRef result;
1125         Try {
1126                 result = JSUtil::toJSValueRef(context, watchId);
1127 //              result = converter->toJSValueRefLong(watchId);
1128         } Catch(Exception) {
1129                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1130                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1131         }
1132         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1133         return result;
1134 }
1135
1136 JSValueRef JSAddressBook::removeChangeListener(JSContextRef context,
1137                 JSObjectRef object,
1138                 JSObjectRef thisObject,
1139                 size_t argumentCount,
1140                 const JSValueRef arguments[],
1141                 JSValueRef* exception)
1142 {
1143         LoggerD("entered");
1144         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1145         AddressBookPtr addressBook;
1146         JSContextRef gContext;
1147         AddressBookController *controller;
1148
1149         Try     {
1150                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1151                 if (!controller) {
1152                         ThrowMsg(InvalidArgumentException, "No private object.");
1153                 }
1154                 addressBook = controller->getObject();
1155                 gContext = controller->getContext();
1156         } Catch(Exception) {
1157                 LoggerE("No private object");
1158                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1159         }
1160
1161         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER);
1162         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1163
1164         long watchId = 0;
1165
1166         try {
1167                 ArgumentValidator validator(context, argumentCount, arguments);
1168                 watchId = validator.toLong(0, false);
1169         } catch (const TypeMismatchException& err ) {
1170                 return JSWebAPIError::throwException(context, exception, err);
1171         } catch(const BasePlatformException& err) {
1172                 return JSWebAPIError::throwException(context, exception, err);
1173         } catch(const ConversionException& err) {
1174                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1175         } catch(const NullPointerException& err) {
1176                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1177         }
1178
1179         EventAddressBookRemoveChangeListenerPtr dplEvent(new EventAddressBookRemoveChangeListener());
1180
1181         dplEvent->setId(watchId);
1182     dplEvent->setForSynchronousCall();
1183
1184         Try {
1185                 addressBook->removeChangeListener(dplEvent);
1186         } Catch(Exception) {
1187                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1188                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1189         }
1190
1191         ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
1192         DeviceAPI::Common::IListenerItemPtr listenerItem = DPL::StaticPointerCast<DeviceAPI::Common::IListenerItem>(canceller);
1193         ContactListenerManagerSingleton::Instance().unregisterListener(listenerItem);
1194
1195         if (!dplEvent->getResult())
1196         {
1197                 switch (dplEvent->getExceptionCode())
1198                 {
1199                 case ExceptionCodes::InvalidArgumentException:
1200                 case ExceptionCodes::NotFoundException:
1201                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Watch id not found");
1202                         break;
1203                 default:
1204                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
1205                         break;
1206                 }
1207         }
1208         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1209         return JSValueMakeUndefined(context);
1210 }
1211
1212 JSValueRef JSAddressBook::getGroup(JSContextRef context,
1213                 JSObjectRef object,
1214                 JSObjectRef thisObject,
1215                 size_t argumentCount,
1216                 const JSValueRef arguments[],
1217                 JSValueRef* exception)
1218 {
1219         LoggerD("entered");
1220         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1221         AddressBookPtr addressBook;
1222         AddressBookController *controller;
1223         JSContextRef gContext;
1224
1225         Try     {
1226                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1227                 if (!controller) {
1228                         ThrowMsg(InvalidArgumentException, "No private object.");
1229                 }
1230                 addressBook = controller->getObject();
1231                 gContext = controller->getContext();
1232         } Catch(Exception) {
1233                 LoggerE("No private object");
1234                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1235         }
1236
1237         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUP);
1238         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1239
1240         string id;
1241
1242         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1243         try     {
1244                 ArgumentValidator validator(context, argumentCount, arguments);
1245                 id = validator.toString(0, false);
1246         } catch (const TypeMismatchException& err ) {
1247                 return JSWebAPIError::throwException(context, exception, err);
1248         } catch(const BasePlatformException& err) {
1249                 return JSWebAPIError::throwException(context, exception, err);
1250         } catch(const ConversionException& err) {
1251                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1252         } catch(const NullPointerException& err) {
1253                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1254         }
1255
1256         EventAddressBookGetGroupPtr dplEvent(new EventAddressBookGetGroup());
1257
1258         dplEvent->setId(id);
1259     dplEvent->setForSynchronousCall();
1260
1261         Try {
1262                 addressBook->getGroup(dplEvent);
1263         } Catch(Exception) {
1264                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1265                 return JSTizenExceptionFactory::postException(context, exception,
1266                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
1267         }
1268
1269         if (!dplEvent->getResult() || !dplEvent->getContactGroupIsSet())
1270         {
1271                 std::stringstream oss;
1272                 switch (dplEvent->getExceptionCode())
1273                 {
1274                 case ExceptionCodes::NotFoundException:
1275                 case ExceptionCodes::InvalidArgumentException:
1276                         LoggerE("Not Found error : " << id);
1277                         oss << "No Contact id '" << id << "'";
1278                         return JSTizenExceptionFactory::postException(context, exception,
1279                                         JSTizenException::NOT_FOUND_ERROR, oss.str());
1280                         break;
1281                 case ExceptionCodes::PlatformException:
1282                         return JSTizenExceptionFactory::postException(context, exception,
1283                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1284                         break;
1285                 default:
1286                         return JSTizenExceptionFactory::postException(context, exception,
1287                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1288                         break;
1289                 }
1290         }
1291
1292         ContactGroupPtr group = dplEvent->getContactGroup();
1293
1294         JSValueRef result;
1295         Try {
1296                 result = converter->toJSValueRef(group);
1297         } Catch(Exception) {
1298                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1299                 return JSTizenExceptionFactory::postException(context, exception,
1300                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
1301         }
1302         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1303         return result;
1304 }
1305
1306 JSValueRef JSAddressBook::addGroup(JSContextRef context,
1307                 JSObjectRef object,
1308                 JSObjectRef thisObject,
1309                 size_t argumentCount,
1310                 const JSValueRef arguments[],
1311                 JSValueRef* exception)
1312 {
1313         LoggerD("entered");
1314         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1315         AddressBookPtr addressBook;
1316         AddressBookController *controller;
1317         JSContextRef gContext;
1318
1319         Try     {
1320                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1321                 if (!controller) {
1322                         ThrowMsg(InvalidArgumentException, "No private object.");
1323                 }
1324                 addressBook = controller->getObject();
1325                 gContext = controller->getContext();
1326         } Catch(Exception) {
1327                 LoggerE("No private object");
1328                 return JSTizenExceptionFactory::postException(context, exception,
1329                                 JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1330         }
1331
1332         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_GROUP);
1333         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1334
1335         try {
1336                 ArgumentValidator validator(context, argumentCount, arguments);
1337                 validator.toObject(0, false);
1338
1339         } catch (const TypeMismatchException& err ) {
1340                 return JSWebAPIError::throwException(context, exception, err);
1341         } catch(const BasePlatformException& err) {
1342                 return JSWebAPIError::throwException(context, exception, err);
1343         } catch(const ConversionException& err) {
1344                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1345         } catch(const NullPointerException& err) {
1346                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1347         }
1348
1349         ContactGroupPtr group(NULL);
1350
1351         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1352         Try     {
1353                 if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
1354                         ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
1355
1356                 group = converter->toContactGroup(arguments[0]);
1357         } Catch(Exception) {
1358                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1359                 return JSTizenExceptionFactory::postException(context, exception,
1360                                 JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactGroup object'");
1361         }
1362
1363         EventAddressBookAddGroupPtr dplEvent(new EventAddressBookAddGroup());
1364
1365         dplEvent->setContactGroup(group);
1366     dplEvent->setForSynchronousCall();
1367
1368         Try {
1369                 addressBook->addGroup(dplEvent);
1370         } Catch(Exception) {
1371                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1372                 return JSTizenExceptionFactory::postException(context, exception,
1373                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
1374         }
1375
1376         if (!dplEvent->getResult())
1377         {
1378                 switch (dplEvent->getExceptionCode())
1379                 {
1380                 case ExceptionCodes::PlatformException:
1381                         return JSTizenExceptionFactory::postException(context, exception,
1382                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1383                         break;
1384                 default:
1385                         return JSTizenExceptionFactory::postException(context, exception,
1386                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1387                         break;
1388                 }
1389         }
1390         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1391         return JSValueMakeUndefined(context);
1392 }
1393
1394 JSValueRef JSAddressBook::updateGroup(JSContextRef context,
1395                 JSObjectRef object,
1396                 JSObjectRef thisObject,
1397                 size_t argumentCount,
1398                 const JSValueRef arguments[],
1399                 JSValueRef* exception)
1400 {
1401         LoggerD("entered");
1402         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1403         AddressBookPtr addressBook;
1404         AddressBookController *controller;
1405         JSContextRef gContext;
1406
1407         Try     {
1408                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1409                 if (!controller) {
1410                         ThrowMsg(InvalidArgumentException, "No private object.");
1411                 }
1412                 addressBook = controller->getObject();
1413                 gContext = controller->getContext();
1414         } Catch(Exception) {
1415                 LoggerE("No private object");
1416                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1417         }
1418
1419         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_GROUP);
1420         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1421
1422         try {
1423                 ArgumentValidator validator(context, argumentCount, arguments);
1424                 validator.toObject(0, false);
1425
1426         } catch (const TypeMismatchException& err ) {
1427                 return JSWebAPIError::throwException(context, exception, err);
1428         } catch(const BasePlatformException& err) {
1429                 return JSWebAPIError::throwException(context, exception, err);
1430         } catch(const ConversionException& err) {
1431                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1432         } catch(const NullPointerException& err) {
1433                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1434         }
1435
1436         ContactGroupPtr contact(NULL);
1437
1438         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1439         Try     {
1440                 if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
1441                         ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
1442                 contact = converter->toContactGroup(arguments[0]);
1443         } Catch(Exception) {
1444                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1445                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument is not a 'ContactGroup object'");
1446         }
1447
1448         EventAddressBookUpdateGroupPtr dplEvent(new EventAddressBookUpdateGroup());
1449
1450         dplEvent->setContactGroup(contact);
1451     dplEvent->setForSynchronousCall();
1452
1453         Try {
1454                 addressBook->updateGroup(dplEvent);
1455         } Catch(Exception) {
1456                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1457                 return JSTizenExceptionFactory::postException(context, exception,
1458                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
1459         }
1460
1461         if (!dplEvent->getResult())
1462         {
1463                 std::stringstream oss;
1464                 switch (dplEvent->getExceptionCode())
1465                 {
1466                 case ExceptionCodes::NotFoundException:
1467                 case ExceptionCodes::InvalidArgumentException:
1468                         oss << "No Contact id '" << contact->getId() << "'";
1469                         return JSTizenExceptionFactory::postException(context, exception,
1470                                         JSTizenException::NOT_FOUND_ERROR, oss.str());
1471                         break;
1472                 case ExceptionCodes::PlatformException:
1473                         return JSTizenExceptionFactory::postException(context, exception,
1474                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1475                         break;
1476                 default:
1477                         return JSTizenExceptionFactory::postException(context, exception,
1478                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1479                         break;
1480                 }
1481         }
1482         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1483         return JSValueMakeUndefined(context);
1484 }
1485
1486 JSValueRef JSAddressBook::removeGroup(JSContextRef context,
1487                 JSObjectRef object,
1488                 JSObjectRef thisObject,
1489                 size_t argumentCount,
1490                 const JSValueRef arguments[],
1491                 JSValueRef* exception)
1492 {
1493         LoggerD("entered");
1494         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1495         AddressBookPtr addressBook;
1496         AddressBookController *controller;
1497
1498         Try     {
1499                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1500                 if (!controller) {
1501                         ThrowMsg(InvalidArgumentException, "No private object.");
1502                 }
1503                 addressBook = controller->getObject();
1504         } Catch(Exception) {
1505                 LoggerE("No private object");
1506                 return JSTizenExceptionFactory::postException(context, exception,
1507                                 JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1508         }
1509
1510         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_GROUP);
1511         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1512
1513         string groupId;
1514
1515         try     {
1516                 ArgumentValidator validator(context, argumentCount, arguments);
1517                 groupId = validator.toString(0, false);
1518         } catch (const TypeMismatchException& err ) {
1519                 return JSWebAPIError::throwException(context, exception, err);
1520         } catch(const BasePlatformException& err) {
1521                 return JSWebAPIError::throwException(context, exception, err);
1522         } catch(const ConversionException& err) {
1523                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1524         } catch(const NullPointerException& err) {
1525                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
1526         }
1527
1528         EventAddressBookRemoveGroupPtr dplEvent(new EventAddressBookRemoveGroup());
1529
1530         dplEvent->setContactGroupId(groupId);
1531     dplEvent->setForSynchronousCall();
1532
1533         Try {
1534                 addressBook->removeGroup(dplEvent);
1535         } Catch(Exception) {
1536                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1537                 return JSTizenExceptionFactory::postException(context, exception,
1538                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
1539         }
1540
1541         if (!dplEvent->getResult())
1542         {
1543                 std::stringstream oss;
1544                 switch (dplEvent->getExceptionCode())
1545                 {
1546                 case ExceptionCodes::NotFoundException:
1547                 case ExceptionCodes::InvalidArgumentException:
1548                         LoggerE("Not Found error : " << groupId);
1549                         oss << "No Contact id '" << groupId << "'";
1550                         return JSTizenExceptionFactory::postException(context, exception,
1551                                         JSTizenException::NOT_FOUND_ERROR, oss.str());
1552                         break;
1553                 case ExceptionCodes::PlatformException:
1554                         return JSTizenExceptionFactory::postException(context, exception,
1555                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1556                         break;
1557                 default:
1558                         return JSTizenExceptionFactory::postException(context, exception,
1559                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1560                         break;
1561                 }
1562         }
1563         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1564         return JSValueMakeUndefined(context);
1565 }
1566
1567 JSValueRef JSAddressBook::getGroups(JSContextRef context,
1568                 JSObjectRef object,
1569                 JSObjectRef thisObject,
1570                 size_t argumentCount,
1571                 const JSValueRef arguments[],
1572                 JSValueRef* exception)
1573 {
1574         LoggerD("entered");
1575         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1576         AddressBookPtr addressBook;
1577         AddressBookController *controller;
1578         JSContextRef gContext;
1579
1580         Try     {
1581                 controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
1582                 if (!controller) {
1583                         ThrowMsg(InvalidArgumentException, "No private object.");
1584                 }
1585                 addressBook = controller->getObject();
1586                 gContext = controller->getContext();
1587         } Catch(Exception) {
1588                 LoggerE("No private object");
1589                 return JSTizenExceptionFactory::postException(context, exception,
1590                                 JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
1591         }
1592
1593         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUPS);
1594         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1595
1596         string id;
1597
1598         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
1599
1600         EventAddressBookGetGroupsPtr dplEvent(new EventAddressBookGetGroups());
1601
1602     dplEvent->setForSynchronousCall();
1603
1604         Try {
1605                 addressBook->getGroups(dplEvent);
1606         } Catch(Exception) {
1607                 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
1608                 return JSTizenExceptionFactory::postException(context, exception,
1609                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
1610         }
1611
1612         if (!dplEvent->getResult() || !dplEvent->getContactGroupsIsSet())
1613         {
1614                 std::stringstream oss;
1615                 switch (dplEvent->getExceptionCode())
1616                 {
1617                 case ExceptionCodes::NotFoundException:
1618                 case ExceptionCodes::InvalidArgumentException:
1619                         LoggerE("Not Found error : " << id);
1620                         oss << "No Contact id '" << id << "'";
1621                         return JSTizenExceptionFactory::postException(context, exception,
1622                                         JSTizenException::NOT_FOUND_ERROR, oss.str());
1623                         break;
1624                 case ExceptionCodes::PlatformException:
1625                         return JSTizenExceptionFactory::postException(context, exception,
1626                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1627                         break;
1628                 default:
1629                         return JSTizenExceptionFactory::postException(context, exception,
1630                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
1631                         break;
1632                 }
1633         }
1634
1635         ContactGroupArrayPtr groups = dplEvent->getContactGroups();
1636
1637         JSValueRef result;
1638         Try {
1639                 result = converter->toJSValueRef(groups);
1640         } Catch(Exception) {
1641                 LoggerE("Error on conversion : " << _rethrown_exception.GetMessage());
1642                 return JSTizenExceptionFactory::postException(context, exception,
1643                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
1644         }
1645         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1646         return result;
1647 }
1648
1649 } // Contact
1650 } // DeviceAPI