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()) {
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());
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->setEvents(events);
300 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
301 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
302 calendar->addEvents(dplEvent);
304 return JSValueMakeNull(context);
306 Catch(UnsupportedException)
308 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
309 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
311 Catch(InvalidArgumentException)
313 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
314 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
316 Catch(ConversionException)
318 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
319 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
323 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
324 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
330 JSValueRef JSCalendar::update(JSContextRef context,
332 JSObjectRef thisObject,
333 size_t argumentCount,
334 const JSValueRef arguments[],
335 JSValueRef* exception)
339 CalendarPrivObject *privateObject =
340 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
341 assert(privateObject);
343 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_UPDATE);
345 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
349 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
351 if (argumentCount>2 || argumentCount<1) {
352 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
355 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
356 ThrowMsg(ConversionException, "First parameter is undefined or null.");
357 } else if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarItem::getClassRef()) &&
358 JSValueIsObjectOfClass(context, arguments[0], JSCalendarEvent::getClassRef()) &&
359 JSValueIsObjectOfClass(context, arguments[0], JSCalendarTask::getClassRef())) {
360 ThrowMsg(ConversionException, "Wrong parameter type.");
363 JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
364 CalendarEventPtr event = JSCalendarItem::getPrivateObject(arg);
365 if (!JSCalendarItem::validate(context, arg, exception)) {
366 ThrowMsg(InvalidArgumentException, "Wrong parameter value.");
369 ThrowMsg(ConversionException, "Parameter conversion failed.");
372 bool updateAllInstances = true;
373 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
374 if( argumentCount > 1 ) {
375 if (JSValueIsBoolean(context, arguments[1])) {
376 updateAllInstances = converter->toBool(arguments[1]);
378 ThrowMsg(ConversionException, "Wrong parameter type.");
382 IEventUpdateEventPtr dplEvent(new IEventUpdateEvent());
383 dplEvent->setEvent(event);
384 dplEvent->setUpdateAllInstances(updateAllInstances);
385 dplEvent->setForSynchronousCall();
386 calendar->updateEvent(dplEvent);
388 if (dplEvent->getResult()) {
389 return JSValueMakeNull(context);
391 ThrowMsg(UnknownException, "Updating failed by unkown reason.");
394 Catch(UnsupportedException)
396 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
397 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
399 Catch(InvalidArgumentException)
401 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
402 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
404 Catch(ConversionException)
406 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
407 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
409 Catch (NotFoundException)
411 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
412 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
416 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
417 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
420 return JSValueMakeNull(context);
423 JSValueRef JSCalendar::updateBatch(JSContextRef context,
425 JSObjectRef thisObject,
426 size_t argumentCount,
427 const JSValueRef arguments[],
428 JSValueRef* exception)
432 CalendarPrivObject *privateObject =
433 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
434 assert(privateObject);
436 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_UPDATE_BATCH);
438 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
440 JSCallbackManagerPtr cbm(NULL);
444 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
446 if (argumentCount>4 || argumentCount<1) {
447 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
450 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
452 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
453 ThrowMsg(ConversionException, "Wrong parameter type.");
456 CalendarEventListPtr events;
457 events = converter->toVectorOfEvents(arguments[0]);
459 ThrowMsg(ConversionException, "Parameter conversion failed.");
462 JSValueRef onError = NULL;
463 if (argumentCount > 2) {
464 onError = getFunctionOrNull(context, arguments[2]);
466 JSContextRef globalContext = privateObject->getContext();
467 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
468 CalendarEventsSuccessCallback result;
469 if (argumentCount > 1) {
470 result.onSuccess = getFunctionOrNull(context, arguments[1]);
472 cbm->setOnSuccess(result.onSuccess);
474 bool updateAllInstances = true;
475 if( argumentCount > 3 ) {
476 if (JSValueIsBoolean(context, arguments[3])) {
477 updateAllInstances = converter->toBool(arguments[3]);
479 ThrowMsg(ConversionException, "Wrong parameter type.");
483 LogDebug("Proceed the event to the platform.");
485 IEventUpdateEventsPtr dplEvent(new IEventUpdateEvents());
486 dplEvent->setEvents(events);
487 dplEvent->setUpdateAllInstances(updateAllInstances);
488 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
489 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
490 calendar->updateEvents(dplEvent);
492 return makePendingOperation(cbm->getContext(), dplEvent);
494 Catch(UnsupportedException)
496 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
497 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
499 Catch(InvalidArgumentException)
501 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
502 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
504 Catch(ConversionException)
506 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
507 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
509 Catch (NotFoundException)
511 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
512 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
516 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
517 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
520 return JSValueMakeNull(context);
523 JSValueRef JSCalendar::remove(JSContextRef context,
525 JSObjectRef thisObject,
526 size_t argumentCount,
527 const JSValueRef arguments[],
528 JSValueRef* exception)
531 CalendarPrivObject *privateObject =
532 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
533 assert(privateObject);
535 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE);
537 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
541 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
543 if (argumentCount!=1) {
544 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
547 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
548 ThrowMsg(ConversionException, "Wrong parameter type.");
551 if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
552 ThrowMsg(ConversionException, "Wrong parameter type.");
556 JSContextRef globalContext = privateObject->getContext();
557 CalendarConverter converter(globalContext);
558 if (JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
559 itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
561 ThrowMsg(ConversionException, "Parameter conversion failed.");
563 itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
564 } else if (JSValueIsString(context, arguments[0])) {
565 itemId->setUId(converter.toString(arguments[0]));
566 itemId->setCalendarType(CalendarEvent::TASK_TYPE);
568 ThrowMsg(ConversionException, "Wrong parameter type.");
571 IEventDeleteEventPtr dplEvent(new IEventDeleteEvent());
572 dplEvent->setEventId(itemId);
573 dplEvent->setForSynchronousCall();
574 calendar->deleteEvent(dplEvent);
576 if (dplEvent->getResult()) {
577 LogInfo("Successfully deleted.");
578 return JSValueMakeNull(context);
580 if (dplEvent->getExceptionCode() == ExceptionCodes::NotFoundException) {
581 ThrowMsg(ConversionException, "Item not found.");
583 ThrowMsg(UnknownException, "Removing failed by unkown reason.");
587 Catch(UnsupportedException)
589 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
590 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
592 Catch(InvalidArgumentException)
594 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
595 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
597 Catch(ConversionException)
599 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
600 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
602 Catch (NotFoundException)
604 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
605 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
609 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
610 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
613 return JSValueMakeNull(context);
616 JSValueRef JSCalendar::removeBatch(JSContextRef context,
618 JSObjectRef thisObject,
619 size_t argumentCount,
620 const JSValueRef arguments[],
621 JSValueRef* exception)
624 CalendarPrivObject *privateObject =
625 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
626 assert(privateObject);
628 JSCallbackManagerPtr cbm(NULL);
630 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE_BATCH);
632 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
636 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
638 if (argumentCount>3 || argumentCount<1) {
639 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
642 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
644 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
645 ThrowMsg(ConversionException, "Wrong parameter type.");
648 // Pick one array element to determine its type.
649 JSObjectRef objArg = converter->toJSObjectRef(arguments[0]);
651 if (JSGetArrayLength(context, objArg)>0) {
652 element = JSGetArrayElement(context, objArg, 0);
654 ThrowMsg(InvalidArgumentException, "Invalid length ID array length.");
657 EventIdListPtr itemIds;
658 if (JSValueIsObjectOfClass(context, element, JSCalendarEventId::getClassRef())) {
659 itemIds = converter->toVectorOfEventIds(arguments[0]);
661 ThrowMsg(ConversionException, "Parameter conversion failed.");
663 } else if (JSValueIsString(context, element)) {
664 std::vector<std::string> idStrings = converter->toVectorOfStrings(arguments[0]);
665 for (unsigned int i=0; i<idStrings.size(); i++) {
666 EventIdPtr idPtr( new EventId() );
667 idPtr->setUId(idStrings[i]);
668 idPtr->setCalendarType(CalendarEvent::TASK_TYPE);
669 itemIds->push_back(idPtr);
672 ThrowMsg(ConversionException, "Parameter conversion failed.");
675 ThrowMsg(ConversionException, "Wrong parameter type.");
678 JSValueRef onError = NULL;
679 if (argumentCount > 2) {
680 onError = getFunctionOrNull(context, arguments[2]);
682 JSContextRef globalContext = privateObject->getContext();
683 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
684 CalendarEventsSuccessCallback result;
685 if (argumentCount > 1) {
686 result.onSuccess = getFunctionOrNull(context, arguments[1]);
688 cbm->setOnSuccess(result.onSuccess);
690 LogDebug("Proceed the event to the platform.");
692 IEventDeleteEventsPtr dplEvent(new IEventDeleteEvents());
693 dplEvent->setEventIds(itemIds);
694 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
695 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
696 calendar->deleteEvents(dplEvent);
698 return makePendingOperation(cbm->getContext(), dplEvent);
700 Catch(UnsupportedException)
702 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
703 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
705 Catch(InvalidArgumentException)
707 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
708 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
710 Catch(ConversionException)
712 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
713 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
715 Catch (NotFoundException)
717 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
718 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
722 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
723 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
726 return JSValueMakeNull(context);
729 JSValueRef JSCalendar::findWithWACFilter(JSContextRef context,
731 JSObjectRef thisObject,
732 size_t argumentCount,
733 const JSValueRef arguments[],
734 JSValueRef* exception)
737 CalendarPrivObject *privateObject =
738 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
739 assert(privateObject);
741 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND);
743 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
745 JSCallbackManagerPtr cbm(NULL);
748 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
749 if (argumentCount<1 || argumentCount>4) {
750 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
752 JSValueRef onError = (argumentCount > 1 ? getFunctionOrNull(context, arguments[1]) : NULL);
753 JSContextRef globalContext = privateObject->getContext();
754 cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
756 Validator validator(context);
757 if (validator.isCallback(arguments[0])) {
758 cbm->setOnSuccess(arguments[0]);
759 } else if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) {
760 ThrowMsg(ConversionException, "Wrong parameter type.");
762 ThrowMsg(ConversionException, "Wrong parameter type.");
765 EventFilterPtr filter(NULL);
766 if (argumentCount >= 3) {
767 LogDebug("setting some filters");
768 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
769 if (!JSValueIsUndefined(context, arguments[2]) && !JSValueIsNull(context, arguments[2])) {
770 filter = converter->toEventFilter(arguments[2]);
773 IEventFindEventsPtr dplEvent(new IEventFindEvents());
774 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
775 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
776 dplEvent->setFilter(filter);
777 calendar->findEvents(dplEvent);
779 return JSValueMakeNull(context);
781 Catch(UnsupportedException)
783 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
784 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
786 Catch(InvalidArgumentException)
788 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
789 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
791 Catch(ConversionException)
793 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
794 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
796 Catch (NotFoundException)
798 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
799 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
803 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
804 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
807 return JSValueMakeNull(context);
810 JSValueRef JSCalendar::find(JSContextRef context,
812 JSObjectRef thisObject,
813 size_t argumentCount,
814 const JSValueRef arguments[],
815 JSValueRef* exception)
819 CalendarPrivObject *privateObject =
820 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
821 assert(privateObject);
823 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND);
825 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
829 if (argumentCount<1 || argumentCount>4) {
830 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
833 JSCallbackManagerPtr cbm(NULL);
835 Validator validator(context, exception);
836 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
837 TizenApis::Tizen1_0::Tizen::FilterConverterFactory::ConverterType filterConverter = TizenApis::Tizen1_0::Tizen::FilterConverterFactory::getConverter(context);
838 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
840 JSContextRef globalContext = privateObject->getContext();
841 cbm = JSCallbackManager::createObject(globalContext);
843 if ((!validator.isCallback(arguments[0])) ||
844 (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) ||
845 (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) && !validator.isNullOrUndefined(arguments[2]))) ||
846 (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) && !validator.isNullOrUndefined(arguments[3]))) ||
847 (argumentCount >= 5 && (!JSValueIsObject(context, arguments[4]) && !validator.isNullOrUndefined(arguments[4])))) {
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->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
863 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
865 if (argumentCount >= 3 && !validator.isNullOrUndefined(arguments[2])) {
866 dplEvent->setGenericFilter(filterConverter->toFilter(arguments[2]));
868 if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) {
869 // Though the sortMode is a single type, we save it in an array internally.
870 TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
871 sortModes->push_back(filterConverter->toSortMode(arguments[3]));
872 dplEvent->setSortModes(sortModes);
874 /*if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) {
875 dplEvent->setAttributesOfInterest(converter->toVectorOfStrings(arguments[4]));
878 calendar->findEvents(dplEvent);
880 Catch(UnsupportedException)
882 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
883 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
885 Catch(InvalidArgumentException)
887 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
888 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
890 Catch(ConversionException)
892 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
893 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
895 Catch (NotFoundException)
897 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
898 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
902 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
903 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
906 return JSValueMakeNull(context);
909 JSValueRef JSCalendar::get(JSContextRef context,
911 JSObjectRef thisObject,
912 size_t argumentCount,
913 const JSValueRef arguments[],
914 JSValueRef* exception)
918 CalendarPrivObject *privateObject =
919 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
920 assert(privateObject);
922 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_GET);
924 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
928 if (argumentCount!=1) {
929 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
932 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
933 JSContextRef globalContext = privateObject->getContext();
935 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
936 ThrowMsg(ConversionException, "Wrong parameter type.");
940 CalendarConverter converter(globalContext);
941 if (JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
942 itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
944 ThrowMsg(ConversionException, "Parameter conversion failed.");
946 itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
947 } else if (JSValueIsString(context, arguments[0])) {
948 itemId->setUId(converter.toString(arguments[0]));
949 itemId->setCalendarType(CalendarEvent::TASK_TYPE);
951 ThrowMsg(ConversionException, "Wrong parameter type.");
954 IEventGetPtr dplEvent(new IEventGet());
955 dplEvent->setForSynchronousCall();
956 dplEvent->setItemId(itemId);
957 calendar->get(dplEvent);
959 // Process the found item.
960 if (dplEvent->getResult()) {
961 LogInfo("Successfully found an item.");
962 return JSCalendarItem::createJSCalendarItem(globalContext, dplEvent->getItem());
964 ThrowMsg(UnknownException, "Getting an item failed by unkown reason.");
967 Catch(UnsupportedException)
969 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
970 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
972 Catch(InvalidArgumentException)
974 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
975 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
977 Catch(ConversionException)
979 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
980 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
982 Catch (NotFoundException)
984 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
985 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
989 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
990 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
993 return JSValueMakeNull(context);
996 JSValueRef JSCalendar::convertFromString(JSContextRef context,
998 JSObjectRef thisObject,
999 size_t argumentCount,
1000 const JSValueRef arguments[],
1001 JSValueRef* exception)
1003 LogDebug("entered");
1005 CalendarPrivObject *privateObject =
1006 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1007 assert(privateObject);
1009 JSContextRef globalContext = privateObject->getContext();
1011 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(globalContext, CALENDAR_FUNCTION_API_CONVERT_FROM_STRING);
1013 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1017 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
1018 if (argumentCount!=2) {
1019 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1022 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
1023 ThrowMsg(ConversionException, "Wrong parameter type.");
1025 else if (!JSValueIsString(context, arguments[0])) {
1026 ThrowMsg(ConversionException, "First parameter is not a string type.");
1029 if (JSValueIsUndefined(context, arguments[1]) || JSValueIsNull(context, arguments[1])) {
1030 ThrowMsg(ConversionException, "Wrong parameter type.");
1032 else if (!JSValueIsString(context, arguments[1])) {
1033 ThrowMsg(ConversionException, "Second parameter is not a CalendarTextFormat type.");
1036 CalendarConverterFactory::ConverterType converter =
1037 CalendarConverterFactory::getConverter(globalContext);
1039 std::string eventStr;
1040 CalendarEvent::VObjectFormat format = CalendarEvent::ICALENDAR_20;
1042 eventStr = converter->toString(arguments[0]);
1044 if( argumentCount>1 )
1046 if (JSValueIsString(context, arguments[1])) {
1047 format = converter->toVObjectFormat(converter->toString(arguments[1]));
1049 ThrowMsg(ConversionException, "Second parameter is not a CalendarTextFormat type.");
1053 IEventCreateEventFromStringPtr dplEvent(new IEventCreateEventFromString());
1054 dplEvent->setEventString(eventStr);
1055 dplEvent->setFormat(format);
1056 dplEvent->setForSynchronousCall();
1057 calendar->createEventFromString(dplEvent);
1059 if (dplEvent->getResult()) {
1060 LogInfo("Successfully created an event.");
1061 return JSCalendarItemProperties::createJSCalendarItemProperties(globalContext, dplEvent->getEvent());
1063 ThrowMsg(UnknownException, "Converting from string failed by unkown reason.");
1066 Catch(UnsupportedException)
1068 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1069 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1071 Catch(InvalidArgumentException)
1073 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1074 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1076 Catch(ConversionException)
1078 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1079 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1083 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1084 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1087 return JSValueMakeNull(context);
1090 JSValueRef JSCalendar::addChangeListener(JSContextRef context,
1092 JSObjectRef thisObject,
1093 size_t argumentCount,
1094 const JSValueRef arguments[],
1095 JSValueRef* exception)
1097 LogDebug("entered");
1098 CalendarPrivObject *privateObject =
1099 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1100 assert(privateObject);
1102 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER);
1104 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1106 JSCallbackManagerPtr cbm(NULL);
1109 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
1110 if (argumentCount>2 || argumentCount<1) {
1111 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1114 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
1115 JSValueRef onError = NULL;
1116 if (argumentCount > 1) {
1117 onError = getFunctionOrNull(context, arguments[1]);
1119 JSContextRef globalContext = privateObject->getContext();
1120 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
1121 JSObjectRef objectCallbacks = converter->toJSObjectRef(arguments[0]);
1122 CalendarChangeCallback result;
1123 result.onAdded = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsAdded");
1124 result.onUpdated = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsUpdated");
1125 result.onDeleted = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsRemoved");
1126 Validator validator(context);
1127 if ((!validator.isNullOrUndefined(result.onAdded) && !validator.isCallback(result.onAdded)) ||
1128 (!validator.isNullOrUndefined(result.onUpdated) && !validator.isCallback(result.onUpdated)) ||
1129 (!validator.isNullOrUndefined(result.onDeleted) && !validator.isCallback(result.onDeleted)))
1131 ThrowMsg(InvalidArgumentException, "Wrong successCallback parameter value.");
1133 JSCallbackManagerPtr onAddedCbm = JSCallbackManager::createObject(globalContext, result.onAdded, NULL);
1134 JSCallbackManagerPtr onUpdatedCbm = JSCallbackManager::createObject(globalContext, result.onUpdated, NULL);
1135 JSCallbackManagerPtr onDeletedCbm = JSCallbackManager::createObject(globalContext, result.onDeleted, NULL);
1137 /* The interested attributes are not supported in platform.
1138 AttributeListPtr attributes;
1139 if( argumentCount >= 3 ) {
1142 *attributes = converter->toVectorOfStrings(arguments[2]);
1144 LogError("watchChanges: Failed to get interested attributes");
1145 Throw(InvalidArgumentException);
1150 LogError("Error while converting the attributes");
1151 Throw(InvalidArgumentException);
1155 LogDebug("Make change emitter and sync operation");
1157 CalendarChangeCallbackPrivateDataPtr privData(new CalendarChangeCallbackPrivateData(
1158 onAddedCbm, onUpdatedCbm, onDeletedCbm));
1159 OnEventsChangedEmitterPtr emitter(new OnEventsChangedEmitter());
1160 emitter->setListener(&CalendarResponseDispatcher::getInstance());
1161 emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
1163 // return sync operation and process the events and emit results while processing them
1164 IEventWatchChangesPtr dplEvent(new IEventWatchChanges());
1165 dplEvent->setEmitter(emitter);
1166 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
1167 dplEvent->setForSynchronousCall();
1168 calendar->watchChanges(dplEvent);
1171 if (dplEvent->getResult()) {
1172 watchId = dplEvent->getWatchId();
1173 LogDebug("Returning the watchId "<<watchId);
1174 return converter->toJSValueRefLong(watchId);
1176 ThrowMsg(UnknownException, "Adding change listener failed by unkown reason.");
1178 return JSValueMakeNull(context);
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 JSValueMakeNull(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]);
1233 LogDebug("Make sync operation");
1235 IEventClearWatchPtr dplEvent(new IEventClearWatch());
1236 dplEvent->setWatchId(watchId);
1237 dplEvent->setForSynchronousCall();
1238 calendar->clearWatch(dplEvent);
1240 return JSValueMakeNull(context);
1242 Catch(UnsupportedException)
1244 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1245 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1247 Catch(InvalidArgumentException)
1249 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1250 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1252 Catch(ConversionException)
1254 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1255 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1257 Catch (NotFoundException)
1259 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1260 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
1264 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1265 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1268 return JSValueMakeNull(context);
1271 JSValueRef JSCalendar::getPropertyName(JSContextRef context,
1273 JSStringRef propertyName,
1274 JSValueRef* exception)
1278 ICalendarPtr calendar = getCalendar(context, object, exception);
1279 Converter converter(context);
1280 return converter.toJSValueRef(calendar->getName());
1284 LogError("error during executing a function");
1286 return JSValueMakeUndefined(context);
1289 JSValueRef JSCalendar::getPropertyAccountId(JSContextRef context,
1291 JSStringRef propertyName,
1292 JSValueRef* exception)
1296 ICalendarPtr calendar = getCalendar(context, object, exception);
1297 Converter converter(context);
1298 return converter.toJSValueRefLong(calendar->getAccountId());
1302 LogError("error during executing a function");
1304 return JSValueMakeUndefined(context);
1307 JSValueRef JSCalendar::getPropertyId(JSContextRef context,
1309 JSStringRef propertyName,
1310 JSValueRef* exception)
1314 ICalendarPtr calendar = getCalendar(context, object, exception);
1315 Converter converter(context);
1316 return converter.toJSValueRef(calendar->getId());
1320 LogError("error during executing a function");
1322 return JSValueMakeUndefined(context);
1325 ICalendarPtr JSCalendar::getCalendar(JSContextRef ctx,
1326 const JSObjectRef object,
1327 JSValueRef* exception)
1329 CalendarPrivObject *priv =
1330 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
1332 return priv->getObject();
1334 ThrowMsg(NullPointerException, "Private object is NULL.");