2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dpl/log/log.h>
19 #include <API/Calendar/ICalendar.h>
20 #include <API/Calendar/EventId.h>
21 #include <API/Calendar/CalendarFactory.h>
23 #include <CommonsJavaScript/PrivateObject.h>
24 #include <CommonsJavaScript/Converter.h>
25 #include <CommonsJavaScript/JSUtils.h>
26 #include <CommonsJavaScript/Utils.h>
27 #include <CommonsJavaScript/Validator.h>
28 #include <CommonsJavaScript/ScopedJSStringRef.h>
29 #include <Tizen/Common/JSTizenException.h>
30 #include <Tizen/Common/JSTizenExceptionFactory.h>
31 #include <Tizen/Common/SecurityExceptions.h>
32 #include <Tizen/Tizen/FilterConverter.h>
33 #include <Tizen/TimeUtil/TimeUtilConverter.h>
35 #include "JSCalendarManager.h"
36 #include "CalendarConverter.h"
37 #include "JSCalendar.h"
38 #include "JSCalendarItem.h"
39 #include "JSCalendarEvent.h"
40 #include "JSCalendarTask.h"
41 #include "JSCalendarItemProperties.h"
42 #include "JSCalendarEventId.h"
43 #include "plugin_config.h"
44 #include "CalendarResponseDispatcher.h"
45 #include "CalendarMultiCallback.h"
47 using namespace TizenApis::Api::Calendar;
48 using namespace WrtDeviceApis::Commons;
49 using namespace WrtDeviceApis::CommonsJavaScript;
50 using namespace TizenApis::Commons;
54 * @throw InvalidArgumentException If not a callback nor JS null nor JS undefined.
56 JSValueRef getFunctionOrNull(JSContextRef ctx,
59 if (Validator(ctx).isCallback(arg)) {
61 } else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) {
62 ThrowMsg(InvalidArgumentException, "Not a function nor JS null.");
68 #define TIZEN_CALENDAR_ATTRIBUTENAME "Calendar"
74 JSClassDefinition JSCalendar::m_classInfo = {
76 kJSClassAttributeNone,
77 TIZEN_CALENDAR_ATTRIBUTENAME,
86 NULL, //DeleteProperty,
87 NULL, //GetPropertyNames,
88 NULL, //CallAsFunction,
89 NULL, //CallAsConstructor,
94 JSStaticValue JSCalendar::m_property[] = {
95 { TIZEN_CALENDAR_PROPERTY_NAME, JSCalendar::getPropertyName,
96 NULL, kJSPropertyAttributeReadOnly },
97 { TIZEN_CALENDAR_PROPERTY_ACCOUNT_ID, JSCalendar::getPropertyAccountId,
98 NULL, kJSPropertyAttributeReadOnly },
99 { TIZEN_CALENDAR_PROPERTY_ID, JSCalendar::getPropertyId,
100 NULL, kJSPropertyAttributeReadOnly },
104 JSStaticFunction JSCalendar::m_function[] = {
105 { CALENDAR_FUNCTION_API_ADD, add, kJSPropertyAttributeNone },
106 { CALENDAR_FUNCTION_API_ADD_BATCH, addBatch, kJSPropertyAttributeNone },
107 { CALENDAR_FUNCTION_API_UPDATE, update, kJSPropertyAttributeNone },
108 { CALENDAR_FUNCTION_API_UPDATE_BATCH, updateBatch, kJSPropertyAttributeNone },
109 { CALENDAR_FUNCTION_API_REMOVE, remove, kJSPropertyAttributeNone },
110 { CALENDAR_FUNCTION_API_REMOVE_BATCH, removeBatch, kJSPropertyAttributeNone },
111 { CALENDAR_FUNCTION_API_FIND, find, kJSPropertyAttributeNone },
112 //{ "convertFromString", convertFromString, kJSPropertyAttributeNone },
113 { CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER, addChangeListener, kJSPropertyAttributeNone },
114 { CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER, removeChangeListener, kJSPropertyAttributeNone },
115 { CALENDAR_FUNCTION_API_GET, get, kJSPropertyAttributeNone },
120 JSClassRef JSCalendar::m_jsClassRef = JSClassCreate(JSCalendar::getClassInfo());
122 void JSCalendar::initialize(JSContextRef context,
126 CalendarPrivObject *priv =
127 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
129 LogWarning("create default instance");
130 ICalendarPtr calendar =
131 Api::Calendar::CalendarFactory::getInstance().createCalendarObject();
132 priv = new CalendarPrivObject(context, calendar);
133 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
137 //can be set by JSMakeObject inside getCalendars method
138 LogDebug("private object alrerady exists");
142 void JSCalendar::finalize(JSObjectRef object)
145 CalendarPrivObject *priv =
146 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
150 const JSClassRef JSCalendar::getClassRef()
153 m_jsClassRef = JSClassCreate(&m_classInfo);
158 const JSClassDefinition* JSCalendar::getClassInfo()
163 JSValueRef JSCalendar::add(JSContextRef context,
165 JSObjectRef thisObject,
166 size_t argumentCount,
167 const JSValueRef arguments[],
168 JSValueRef* exception)
172 CalendarPrivObject *privateObject =
173 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
174 assert(privateObject);
176 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD);
178 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
182 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
184 if (argumentCount!=1) {
185 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
188 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
189 ThrowMsg(ConversionException, "Wrong parameter type.");
192 CalendarConverterFactory::ConverterType converter =
193 CalendarConverterFactory::getConverter(privateObject->getContext());
195 JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
196 CalendarEventPtr event = JSCalendarItem::getPrivateObject(arg);
197 if (!JSCalendarItem::validate(context, arg, exception)) {
198 ThrowMsg(InvalidArgumentException, "Wrong parameter value.");
201 ThrowMsg(ConversionException, "Parameter conversion failed.");
204 IEventAddEventPtr dplEvent(new IEventAddEvent());
205 dplEvent->setEvent(event);
206 dplEvent->setForSynchronousCall();
207 calendar->addEvent(dplEvent);
209 if (dplEvent->getResult()) {
210 return JSValueMakeUndefined(context);
212 ThrowMsg(UnknownException, "Adding failed by unkown reason.");
215 Catch(UnsupportedException)
217 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
218 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
220 Catch(InvalidArgumentException)
222 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
223 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
225 Catch(ConversionException)
227 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
228 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
232 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
233 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
236 return JSValueMakeUndefined(context);
239 JSValueRef JSCalendar::addBatch(JSContextRef context,
241 JSObjectRef thisObject,
242 size_t argumentCount,
243 const JSValueRef arguments[],
244 JSValueRef* exception)
248 CalendarPrivObject *privateObject =
249 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
250 assert(privateObject);
252 JSCallbackManagerPtr cbm(NULL);
254 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_BATCH);
256 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
260 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
262 if (argumentCount>3 || argumentCount<1) {
263 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
266 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
268 CalendarEventListPtr events;
269 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
270 ThrowMsg(ConversionException, "Wrong parameter type.");
272 events = converter->toVectorOfEvents(arguments[0]);
274 LogError("Failed to create events.");
275 ThrowMsg(ConversionException, "Parameter conversion failed.");
278 JSValueRef onError = NULL;
279 if (argumentCount > 2) {
280 onError = getFunctionOrNull(context, arguments[2]);
282 JSContextRef globalContext = privateObject->getContext();
283 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
284 CalendarEventsSuccessCallback result;
285 if (argumentCount > 1) {
286 result.onSuccess = getFunctionOrNull(context, arguments[1]);
288 cbm->setOnSuccess(result.onSuccess);
290 LogDebug("Proceed the event to the platform.");
292 //CalendarEventsCallbackPrivateDataPtr privData(new CalendarEventsCallbackPrivateData(cbm, onAddEventCbm));
293 //OnAddEventsChangedEmitterPtr emitter(new OnAddEventsChangedEmitter());
294 //emitter->setListener(&CalendarResponseDispatcher::getInstance());
295 //emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
296 //calendar->setAddEmitter(emitter);
298 IEventAddEventsPtr dplEvent(new IEventAddEvents());
299 dplEvent->setCalendarType(calendar->getType());
300 dplEvent->setEvents(events);
301 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
302 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
303 calendar->addEvents(dplEvent);
305 return JSValueMakeUndefined(context);
307 Catch(UnsupportedException)
309 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
310 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
312 Catch(InvalidArgumentException)
314 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
315 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
317 Catch(ConversionException)
319 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
320 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
324 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
325 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
328 return JSValueMakeUndefined(context);
331 JSValueRef JSCalendar::update(JSContextRef context,
333 JSObjectRef thisObject,
334 size_t argumentCount,
335 const JSValueRef arguments[],
336 JSValueRef* exception)
340 CalendarPrivObject *privateObject =
341 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
342 assert(privateObject);
344 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_UPDATE);
346 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
350 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
352 if (argumentCount>2 || argumentCount<1) {
353 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
356 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
357 ThrowMsg(ConversionException, "First parameter is undefined or null.");
358 } else if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarItem::getClassRef()) &&
359 !JSValueIsObjectOfClass(context, arguments[0], JSCalendarEvent::getClassRef()) &&
360 !JSValueIsObjectOfClass(context, arguments[0], JSCalendarTask::getClassRef())) {
361 ThrowMsg(ConversionException, "Wrong parameter type.");
364 JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
365 CalendarEventPtr event = JSCalendarItem::getPrivateObject(arg);
366 if (!JSCalendarItem::validate(context, arg, exception)) {
367 ThrowMsg(InvalidArgumentException, "Wrong parameter value.");
370 ThrowMsg(ConversionException, "Parameter conversion failed.");
373 bool updateAllInstances = true;
374 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
375 if( argumentCount > 1 ) {
376 if (JSValueIsBoolean(context, arguments[1])) {
377 updateAllInstances = converter->toBool(arguments[1]);
379 ThrowMsg(ConversionException, "Wrong parameter type.");
383 IEventUpdateEventPtr dplEvent(new IEventUpdateEvent());
384 dplEvent->setEvent(event);
385 dplEvent->setUpdateAllInstances(updateAllInstances);
386 dplEvent->setForSynchronousCall();
387 calendar->updateEvent(dplEvent);
389 if (dplEvent->getResult()) {
390 return JSValueMakeUndefined(context);
392 ThrowMsg(UnknownException, "Updating failed by unkown reason.");
395 Catch(UnsupportedException)
397 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
398 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
400 Catch(InvalidArgumentException)
402 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
403 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
405 Catch(ConversionException)
407 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
408 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
410 Catch (NotFoundException)
412 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
413 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
417 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
418 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
421 return JSValueMakeUndefined(context);
424 JSValueRef JSCalendar::updateBatch(JSContextRef context,
426 JSObjectRef thisObject,
427 size_t argumentCount,
428 const JSValueRef arguments[],
429 JSValueRef* exception)
433 CalendarPrivObject *privateObject =
434 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
435 assert(privateObject);
437 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_UPDATE_BATCH);
439 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
441 JSCallbackManagerPtr cbm(NULL);
445 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
447 if (argumentCount>4 || argumentCount<1) {
448 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
451 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
453 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
454 ThrowMsg(ConversionException, "Wrong parameter type.");
457 CalendarEventListPtr events;
458 events = converter->toVectorOfEvents(arguments[0]);
460 ThrowMsg(ConversionException, "Parameter conversion failed.");
463 JSValueRef onError = NULL;
464 if (argumentCount > 2) {
465 onError = getFunctionOrNull(context, arguments[2]);
467 JSContextRef globalContext = privateObject->getContext();
468 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
469 CalendarEventsSuccessCallback result;
470 if (argumentCount > 1) {
471 result.onSuccess = getFunctionOrNull(context, arguments[1]);
473 cbm->setOnSuccess(result.onSuccess);
475 bool updateAllInstances = true;
476 if( argumentCount > 3 ) {
477 if (JSValueIsBoolean(context, arguments[3])) {
478 updateAllInstances = converter->toBool(arguments[3]);
480 ThrowMsg(ConversionException, "Wrong parameter type.");
484 LogDebug("Proceed the event to the platform.");
486 IEventUpdateEventsPtr dplEvent(new IEventUpdateEvents());
487 dplEvent->setEvents(events);
488 dplEvent->setUpdateAllInstances(updateAllInstances);
489 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
490 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
491 calendar->updateEvents(dplEvent);
493 return JSValueMakeUndefined(context);
495 Catch(UnsupportedException)
497 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
498 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
500 Catch(InvalidArgumentException)
502 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
503 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
505 Catch(ConversionException)
507 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
508 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
510 Catch (NotFoundException)
512 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
513 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
517 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
518 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
521 return JSValueMakeUndefined(context);
524 JSValueRef JSCalendar::remove(JSContextRef context,
526 JSObjectRef thisObject,
527 size_t argumentCount,
528 const JSValueRef arguments[],
529 JSValueRef* exception)
532 CalendarPrivObject *privateObject =
533 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
534 assert(privateObject);
536 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE);
538 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
542 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
544 if (argumentCount!=1) {
545 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
548 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
549 ThrowMsg(ConversionException, "Wrong parameter type.");
552 if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
553 ThrowMsg(ConversionException, "Wrong parameter type.");
557 JSContextRef globalContext = privateObject->getContext();
558 CalendarConverter converter(globalContext);
559 if (JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
560 itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
562 ThrowMsg(ConversionException, "Parameter conversion failed.");
564 itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
565 } else if (JSValueIsString(context, arguments[0])) {
566 itemId->setUId(converter.toString(arguments[0]));
567 itemId->setCalendarType(CalendarEvent::TASK_TYPE);
569 ThrowMsg(ConversionException, "Wrong parameter type.");
572 IEventDeleteEventPtr dplEvent(new IEventDeleteEvent());
573 dplEvent->setEventId(itemId);
574 dplEvent->setForSynchronousCall();
575 calendar->deleteEvent(dplEvent);
577 if (dplEvent->getResult()) {
578 LogInfo("Successfully deleted.");
579 return JSValueMakeUndefined(context);
581 if (dplEvent->getExceptionCode() == ExceptionCodes::NotFoundException) {
582 ThrowMsg(ConversionException, "Item not found.");
584 ThrowMsg(UnknownException, "Removing failed by unkown reason.");
588 Catch(UnsupportedException)
590 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
591 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
593 Catch(InvalidArgumentException)
595 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
596 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
598 Catch(ConversionException)
600 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
601 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
603 Catch (NotFoundException)
605 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
606 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
610 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
611 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
614 return JSValueMakeUndefined(context);
617 JSValueRef JSCalendar::removeBatch(JSContextRef context,
619 JSObjectRef thisObject,
620 size_t argumentCount,
621 const JSValueRef arguments[],
622 JSValueRef* exception)
625 CalendarPrivObject *privateObject =
626 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
627 assert(privateObject);
629 JSCallbackManagerPtr cbm(NULL);
631 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE_BATCH);
633 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
637 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
639 if (argumentCount>3 || argumentCount<1) {
640 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
643 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
645 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
646 ThrowMsg(ConversionException, "Wrong parameter type.");
649 // Pick one array element to determine its type.
650 JSObjectRef objArg = converter->toJSObjectRef(arguments[0]);
652 if (JSGetArrayLength(context, objArg)>0) {
653 element = JSGetArrayElement(context, objArg, 0);
655 ThrowMsg(InvalidArgumentException, "Invalid length ID array length.");
658 EventIdListPtr itemIds;
659 if (JSValueIsObjectOfClass(context, element, JSCalendarEventId::getClassRef())) {
660 itemIds = converter->toVectorOfEventIds(arguments[0]);
662 ThrowMsg(ConversionException, "Parameter conversion failed.");
664 } else if (JSValueIsString(context, element)) {
665 std::vector<std::string> idStrings = converter->toVectorOfStrings(arguments[0]);
666 for (unsigned int i=0; i<idStrings.size(); i++) {
667 EventIdPtr idPtr( new EventId() );
668 idPtr->setUId(idStrings[i]);
669 idPtr->setCalendarType(CalendarEvent::TASK_TYPE);
670 itemIds->push_back(idPtr);
673 ThrowMsg(ConversionException, "Parameter conversion failed.");
676 ThrowMsg(ConversionException, "Wrong parameter type.");
679 JSValueRef onError = NULL;
680 if (argumentCount > 2) {
681 onError = getFunctionOrNull(context, arguments[2]);
683 JSContextRef globalContext = privateObject->getContext();
684 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
685 CalendarEventsSuccessCallback result;
686 if (argumentCount > 1) {
687 result.onSuccess = getFunctionOrNull(context, arguments[1]);
689 cbm->setOnSuccess(result.onSuccess);
691 LogDebug("Proceed the event to the platform.");
693 IEventDeleteEventsPtr dplEvent(new IEventDeleteEvents());
694 dplEvent->setEventIds(itemIds);
695 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
696 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
697 calendar->deleteEvents(dplEvent);
699 return JSValueMakeUndefined(context);
701 Catch(UnsupportedException)
703 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
704 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
706 Catch(InvalidArgumentException)
708 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
709 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
711 Catch(ConversionException)
713 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
714 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
716 Catch (NotFoundException)
718 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
719 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
723 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
724 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
727 return JSValueMakeUndefined(context);
730 JSValueRef JSCalendar::findWithWACFilter(JSContextRef context,
732 JSObjectRef thisObject,
733 size_t argumentCount,
734 const JSValueRef arguments[],
735 JSValueRef* exception)
738 CalendarPrivObject *privateObject =
739 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
740 assert(privateObject);
742 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND);
744 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
746 JSCallbackManagerPtr cbm(NULL);
749 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
750 if (argumentCount<1 || argumentCount>4) {
751 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
753 JSValueRef onError = (argumentCount > 1 ? getFunctionOrNull(context, arguments[1]) : NULL);
754 JSContextRef globalContext = privateObject->getContext();
755 cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
757 Validator validator(context);
758 if (validator.isCallback(arguments[0])) {
759 cbm->setOnSuccess(arguments[0]);
760 } else if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) {
761 ThrowMsg(ConversionException, "Wrong parameter type.");
763 ThrowMsg(ConversionException, "Wrong parameter type.");
766 EventFilterPtr filter(NULL);
767 if (argumentCount >= 3) {
768 LogDebug("setting some filters");
769 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
770 if (!JSValueIsUndefined(context, arguments[2]) && !JSValueIsNull(context, arguments[2])) {
771 filter = converter->toEventFilter(arguments[2]);
774 IEventFindEventsPtr dplEvent(new IEventFindEvents());
775 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
776 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
777 dplEvent->setFilter(filter);
778 calendar->findEvents(dplEvent);
780 return JSValueMakeUndefined(context);
782 Catch(UnsupportedException)
784 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
785 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
787 Catch(InvalidArgumentException)
789 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
790 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
792 Catch(ConversionException)
794 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
795 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
797 Catch (NotFoundException)
799 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
800 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
804 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
805 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
808 return JSValueMakeUndefined(context);
811 JSValueRef JSCalendar::find(JSContextRef context,
813 JSObjectRef thisObject,
814 size_t argumentCount,
815 const JSValueRef arguments[],
816 JSValueRef* exception)
820 CalendarPrivObject *privateObject =
821 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
822 assert(privateObject);
824 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND);
826 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
830 if (argumentCount<1 || argumentCount>4) {
831 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
834 JSCallbackManagerPtr cbm(NULL);
836 Validator validator(context, exception);
837 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
838 TizenApis::Tizen1_0::Tizen::FilterConverterFactory::ConverterType filterConverter = TizenApis::Tizen1_0::Tizen::FilterConverterFactory::getConverter(context);
839 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
841 JSContextRef globalContext = privateObject->getContext();
842 cbm = JSCallbackManager::createObject(globalContext);
844 if ((!validator.isCallback(arguments[0])) ||
845 (argumentCount >= 2 && (!validator.isCallback(arguments[1]) && !validator.isNullOrUndefined(arguments[1]))) ||
846 (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) && !validator.isNullOrUndefined(arguments[2]))) ||
847 (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) && !validator.isNullOrUndefined(arguments[3])))) {
848 ThrowMsg(ConversionException, "Wrong parameter type.");
852 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
853 onSuccessForCbm = arguments[0];
854 if (argumentCount >= 2) {
855 onErrorForCbm = arguments[1];
857 cbm->setOnSuccess(onSuccessForCbm);
858 cbm->setOnError(onErrorForCbm);
861 IEventFindEventsPtr dplEvent(new IEventFindEvents());
862 dplEvent->setCalendarType(calendar->getType());
863 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
864 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
866 if (argumentCount >= 3 && !validator.isNullOrUndefined(arguments[2])) {
867 dplEvent->setGenericFilter(filterConverter->toFilter(arguments[2]));
869 if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) {
870 // Though the sortMode is a single type, we save it in an array internally.
871 TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
872 sortModes->push_back(filterConverter->toSortMode(arguments[3]));
873 dplEvent->setSortModes(sortModes);
875 /*if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) {
876 dplEvent->setAttributesOfInterest(converter->toVectorOfStrings(arguments[4]));
879 calendar->findEvents(dplEvent);
881 Catch(UnsupportedException)
883 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
884 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
886 Catch(InvalidArgumentException)
888 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
889 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
891 Catch(ConversionException)
893 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
894 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
896 Catch (NotFoundException)
898 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
899 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
903 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
904 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
907 return JSValueMakeUndefined(context);
910 JSValueRef JSCalendar::get(JSContextRef context,
912 JSObjectRef thisObject,
913 size_t argumentCount,
914 const JSValueRef arguments[],
915 JSValueRef* exception)
919 CalendarPrivObject *privateObject =
920 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
921 assert(privateObject);
923 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_GET);
925 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
929 if (argumentCount!=1) {
930 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
933 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
934 JSContextRef globalContext = privateObject->getContext();
936 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
937 ThrowMsg(ConversionException, "Wrong parameter type.");
941 CalendarConverter converter(globalContext);
942 if (JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
943 itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
945 ThrowMsg(ConversionException, "Parameter conversion failed.");
947 itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
948 } else if (JSValueIsString(context, arguments[0])) {
949 itemId->setUId(converter.toString(arguments[0]));
950 itemId->setCalendarType(CalendarEvent::TASK_TYPE);
952 ThrowMsg(ConversionException, "Wrong parameter type.");
955 IEventGetPtr dplEvent(new IEventGet());
956 dplEvent->setForSynchronousCall();
957 dplEvent->setItemId(itemId);
958 calendar->get(dplEvent);
960 // Process the found item.
961 if (dplEvent->getResult()) {
962 LogInfo("Successfully found an item.");
963 return JSCalendarItem::createJSCalendarItem(globalContext, dplEvent->getItem());
965 ThrowMsg(UnknownException, "Getting an item failed by unkown reason.");
968 Catch(UnsupportedException)
970 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
971 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
973 Catch(InvalidArgumentException)
975 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
976 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
978 Catch(ConversionException)
980 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
981 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
983 Catch (NotFoundException)
985 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
986 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
990 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
991 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
994 return JSValueMakeUndefined(context);
997 JSValueRef JSCalendar::convertFromString(JSContextRef context,
999 JSObjectRef thisObject,
1000 size_t argumentCount,
1001 const JSValueRef arguments[],
1002 JSValueRef* exception)
1004 LogDebug("entered");
1006 CalendarPrivObject *privateObject =
1007 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1008 assert(privateObject);
1010 JSContextRef globalContext = privateObject->getContext();
1012 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(globalContext, CALENDAR_FUNCTION_API_CONVERT_FROM_STRING);
1014 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1018 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
1019 if (argumentCount!=2) {
1020 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1023 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
1024 ThrowMsg(ConversionException, "Wrong parameter type.");
1026 else if (!JSValueIsString(context, arguments[0])) {
1027 ThrowMsg(ConversionException, "First parameter is not a string type.");
1030 if (JSValueIsUndefined(context, arguments[1]) || JSValueIsNull(context, arguments[1])) {
1031 ThrowMsg(ConversionException, "Wrong parameter type.");
1033 else if (!JSValueIsString(context, arguments[1])) {
1034 ThrowMsg(ConversionException, "Second parameter is not a CalendarTextFormat type.");
1037 CalendarConverterFactory::ConverterType converter =
1038 CalendarConverterFactory::getConverter(globalContext);
1040 std::string eventStr;
1041 CalendarEvent::VObjectFormat format = CalendarEvent::ICALENDAR_20;
1043 eventStr = converter->toString(arguments[0]);
1045 if( argumentCount>1 )
1047 if (JSValueIsString(context, arguments[1])) {
1048 format = converter->toVObjectFormat(converter->toString(arguments[1]));
1050 ThrowMsg(ConversionException, "Second parameter is not a CalendarTextFormat type.");
1054 IEventCreateEventFromStringPtr dplEvent(new IEventCreateEventFromString());
1055 dplEvent->setEventString(eventStr);
1056 dplEvent->setFormat(format);
1057 dplEvent->setForSynchronousCall();
1058 calendar->createEventFromString(dplEvent);
1060 if (dplEvent->getResult()) {
1061 LogInfo("Successfully created an event.");
1062 return JSCalendarItemProperties::createJSCalendarItemProperties(globalContext, dplEvent->getEvent());
1064 ThrowMsg(UnknownException, "Converting from string failed by unkown reason.");
1067 Catch(UnsupportedException)
1069 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1070 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1072 Catch(InvalidArgumentException)
1074 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1075 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1077 Catch(ConversionException)
1079 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1080 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1084 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1085 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1088 return JSValueMakeUndefined(context);
1091 JSValueRef JSCalendar::addChangeListener(JSContextRef context,
1093 JSObjectRef thisObject,
1094 size_t argumentCount,
1095 const JSValueRef arguments[],
1096 JSValueRef* exception)
1098 LogDebug("entered");
1099 CalendarPrivObject *privateObject =
1100 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1101 assert(privateObject);
1103 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER);
1105 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1107 JSCallbackManagerPtr cbm(NULL);
1110 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
1111 if (argumentCount>2 || argumentCount<1) {
1112 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1115 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
1116 JSValueRef onError = NULL;
1117 if (argumentCount > 1) {
1118 onError = getFunctionOrNull(context, arguments[1]);
1120 JSContextRef globalContext = privateObject->getContext();
1121 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
1122 JSObjectRef objectCallbacks = converter->toJSObjectRef(arguments[0]);
1123 CalendarChangeCallback result;
1124 result.onAdded = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsAdded");
1125 result.onUpdated = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsUpdated");
1126 result.onDeleted = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsRemoved");
1127 Validator validator(context);
1128 if ((!validator.isNullOrUndefined(result.onAdded) && !validator.isCallback(result.onAdded)) ||
1129 (!validator.isNullOrUndefined(result.onUpdated) && !validator.isCallback(result.onUpdated)) ||
1130 (!validator.isNullOrUndefined(result.onDeleted) && !validator.isCallback(result.onDeleted)))
1132 ThrowMsg(InvalidArgumentException, "Wrong successCallback parameter value.");
1134 JSCallbackManagerPtr onAddedCbm = JSCallbackManager::createObject(globalContext, result.onAdded, NULL);
1135 JSCallbackManagerPtr onUpdatedCbm = JSCallbackManager::createObject(globalContext, result.onUpdated, NULL);
1136 JSCallbackManagerPtr onDeletedCbm = JSCallbackManager::createObject(globalContext, result.onDeleted, NULL);
1138 /* The interested attributes are not supported in platform.
1139 AttributeListPtr attributes;
1140 if( argumentCount >= 3 ) {
1143 *attributes = converter->toVectorOfStrings(arguments[2]);
1145 LogError("watchChanges: Failed to get interested attributes");
1146 Throw(InvalidArgumentException);
1151 LogError("Error while converting the attributes");
1152 Throw(InvalidArgumentException);
1156 LogDebug("Make change emitter and sync operation");
1158 CalendarChangeCallbackPrivateDataPtr privData(new CalendarChangeCallbackPrivateData(
1159 onAddedCbm, onUpdatedCbm, onDeletedCbm));
1160 OnEventsChangedEmitterPtr emitter(new OnEventsChangedEmitter());
1161 emitter->setListener(&CalendarResponseDispatcher::getInstance());
1162 emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
1164 // return sync operation and process the events and emit results while processing them
1165 IEventWatchChangesPtr dplEvent(new IEventWatchChanges());
1166 dplEvent->setEmitter(emitter);
1167 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
1168 dplEvent->setForSynchronousCall();
1169 calendar->watchChanges(dplEvent);
1172 if (dplEvent->getResult()) {
1173 watchId = dplEvent->getWatchId();
1174 LogDebug("Returning the watchId "<<watchId);
1175 return converter->toJSValueRefLong(watchId);
1177 ThrowMsg(UnknownException, "Adding change listener failed by unkown reason.");
1180 Catch(UnsupportedException)
1182 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1183 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1185 Catch(InvalidArgumentException)
1187 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1188 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1190 Catch(ConversionException)
1192 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1193 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1197 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1198 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1201 return JSValueMakeUndefined(context);
1204 JSValueRef JSCalendar::removeChangeListener(JSContextRef context,
1206 JSObjectRef thisObject,
1207 size_t argumentCount,
1208 const JSValueRef arguments[],
1209 JSValueRef* exception)
1211 LogDebug("entered");
1212 CalendarPrivObject *privateObject =
1213 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1214 assert(privateObject);
1216 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER);
1218 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1222 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
1223 if (argumentCount!=1) {
1224 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1228 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
1229 if (JSValueIsNumber(context, arguments[0])) {
1230 watchId = converter->toLong(arguments[0]);
1232 ThrowMsg(ConversionException, "Wrong watchId type.");
1235 LogDebug("Make sync operation");
1237 IEventClearWatchPtr dplEvent(new IEventClearWatch());
1238 dplEvent->setWatchId(watchId);
1239 dplEvent->setForSynchronousCall();
1240 calendar->clearWatch(dplEvent);
1242 return JSValueMakeUndefined(context);
1244 Catch(UnsupportedException)
1246 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1247 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1249 Catch(InvalidArgumentException)
1251 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1252 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1254 Catch(ConversionException)
1256 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1257 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1259 Catch (NotFoundException)
1261 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1262 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
1266 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1267 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1270 return JSValueMakeUndefined(context);
1273 JSValueRef JSCalendar::getPropertyName(JSContextRef context,
1275 JSStringRef propertyName,
1276 JSValueRef* exception)
1280 ICalendarPtr calendar = getCalendar(context, object, exception);
1281 Converter converter(context);
1282 return converter.toJSValueRef(calendar->getName());
1286 LogError("error during executing a function");
1288 return JSValueMakeUndefined(context);
1291 JSValueRef JSCalendar::getPropertyAccountId(JSContextRef context,
1293 JSStringRef propertyName,
1294 JSValueRef* exception)
1298 ICalendarPtr calendar = getCalendar(context, object, exception);
1299 Converter converter(context);
1300 return converter.toJSValueRefLong(calendar->getAccountId());
1304 LogError("error during executing a function");
1306 return JSValueMakeUndefined(context);
1309 JSValueRef JSCalendar::getPropertyId(JSContextRef context,
1311 JSStringRef propertyName,
1312 JSValueRef* exception)
1316 ICalendarPtr calendar = getCalendar(context, object, exception);
1317 Converter converter(context);
1318 return converter.toJSValueRef(calendar->getId());
1322 LogError("error during executing a function");
1324 return JSValueMakeUndefined(context);
1327 ICalendarPtr JSCalendar::getCalendar(JSContextRef ctx,
1328 const JSObjectRef object,
1329 JSValueRef* exception)
1331 CalendarPrivObject *priv =
1332 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
1334 return priv->getObject();
1336 ThrowMsg(NullPointerException, "Private object is NULL.");