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>
22 #include <API/Calendar/IEventAddEvent.h>
23 #include <API/Calendar/IEventAddEvents.h>
24 #include <API/Calendar/IEventDeleteEvent.h>
25 #include <API/Calendar/IEventDeleteEvents.h>
26 #include <API/Calendar/IEventFindEvents.h>
27 #include <API/Calendar/IEventUpdateEvent.h>
28 #include <API/Calendar/IEventUpdateEvents.h>
29 #include <API/Calendar/IEventCreateEventFromString.h>
30 #include <API/Calendar/IEventExportEventToString.h>
31 #include <API/Calendar/OnAddEventsChanged.h>
32 #include <API/Calendar/OnUpdateEventsChanged.h>
33 #include <API/Calendar/OnDeleteEventsChanged.h>
34 #include <API/Calendar/OnEventsChanged.h>
36 #include <CommonsJavaScript/PrivateObject.h>
37 #include <CommonsJavaScript/Converter.h>
38 #include <CommonsJavaScript/JSUtils.h>
39 #include <CommonsJavaScript/Utils.h>
40 #include <CommonsJavaScript/Validator.h>
41 #include <CommonsJavaScript/ScopedJSStringRef.h>
42 #include <Tizen/Common/JSTizenException.h>
43 #include <Tizen/Common/JSTizenExceptionFactory.h>
44 #include <Tizen/Common/SecurityExceptions.h>
45 #include <Tizen/Tizen/FilterConverter.h>
46 #include <Tizen/TimeUtil/TimeUtilConverter.h>
48 #include "JSCalendarManager.h"
49 #include "CalendarConverter.h"
50 #include "JSCalendar.h"
51 #include "JSCalendarItem.h"
52 #include "JSCalendarEvent.h"
53 #include "JSCalendarTask.h"
54 #include "JSCalendarItemProperties.h"
55 #include "JSEventId.h"
56 #include "plugin_config.h"
57 #include "CalendarResponseDispatcher.h"
58 #include "CalendarMultiCallback.h"
60 using namespace TizenApis::Api::Calendar;
61 using namespace WrtDeviceApis::Commons;
62 using namespace WrtDeviceApis::CommonsJavaScript;
63 using namespace TizenApis::Commons;
67 * @throw InvalidArgumentException If not a callback nor JS null nor JS undefined.
69 JSValueRef getFunctionOrNull(JSContextRef ctx,
72 if (Validator(ctx).isCallback(arg)) {
74 } else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) {
75 ThrowMsg(InvalidArgumentException, "Not a function nor JS null.");
81 #define TIZEN_CALENDAR_ATTRIBUTENAME "Calendar"
87 JSClassDefinition JSCalendar::m_classInfo = {
89 kJSClassAttributeNone,
90 TIZEN_CALENDAR_ATTRIBUTENAME,
99 NULL, //DeleteProperty,
100 NULL, //GetPropertyNames,
101 NULL, //CallAsFunction,
102 NULL, //CallAsConstructor,
107 JSStaticValue JSCalendar::m_property[] = {
108 { TIZEN_CALENDAR_PROPERTY_NAME, JSCalendar::getPropertyName,
109 NULL, kJSPropertyAttributeReadOnly },
110 { TIZEN_CALENDAR_PROPERTY_ACCOUNT_ID, JSCalendar::getPropertyAccountId,
111 NULL, kJSPropertyAttributeReadOnly },
112 { TIZEN_CALENDAR_PROPERTY_ID, JSCalendar::getPropertyId,
113 NULL, kJSPropertyAttributeReadOnly },
117 JSStaticFunction JSCalendar::m_function[] = {
118 { "add", add, kJSPropertyAttributeNone },
119 { "addBatch", addBatch, kJSPropertyAttributeNone },
120 { "update", update, kJSPropertyAttributeNone },
121 { "updateBatch", updateBatch, kJSPropertyAttributeNone },
122 { "remove", remove, kJSPropertyAttributeNone },
123 { "removeBatch", removeBatch, kJSPropertyAttributeNone },
124 { "find", find, kJSPropertyAttributeNone },
125 { "convertFromString", convertFromString, kJSPropertyAttributeNone },
126 { "convertToString", convertToString, kJSPropertyAttributeNone },
127 { "addChangeListener", addChangeListener, kJSPropertyAttributeNone },
128 { "removeChangeListener", removeChangeListener, kJSPropertyAttributeNone },
129 { "expandEventRecurrence", expandEventRecurrence, kJSPropertyAttributeNone },
134 JSClassRef JSCalendar::m_jsClassRef = JSClassCreate(JSCalendar::getClassInfo());
136 void JSCalendar::initialize(JSContextRef context,
140 CalendarPrivObject *priv =
141 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
143 LogWarning("create default instance");
144 ICalendarPtr calendar =
145 Api::Calendar::CalendarFactory::getInstance().createCalendarObject();
146 priv = new CalendarPrivObject(context, calendar);
147 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
151 //can be set by JSMakeObject inside getCalendars method
152 LogDebug("private object alrerady exists");
156 void JSCalendar::finalize(JSObjectRef object)
159 CalendarPrivObject *priv =
160 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
164 const JSClassRef JSCalendar::getClassRef()
167 m_jsClassRef = JSClassCreate(&m_classInfo);
172 const JSClassDefinition* JSCalendar::getClassInfo()
177 JSValueRef JSCalendar::add(JSContextRef context,
179 JSObjectRef thisObject,
180 size_t argumentCount,
181 const JSValueRef arguments[],
182 JSValueRef* exception)
186 CalendarPrivObject *privateObject =
187 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
188 assert(privateObject);
190 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD);
192 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
196 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
198 if (argumentCount!=1) {
199 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
202 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
203 ThrowMsg(ConversionException, "Wrong parameter type.");
206 CalendarConverterFactory::ConverterType converter =
207 CalendarConverterFactory::getConverter(privateObject->getContext());
208 CalendarEventPtr event = converter->toEvent(arguments[0]);
210 ThrowMsg(ConversionException, "Parameter conversion failed.");
213 IEventAddEventPtr dplEvent(new IEventAddEvent());
214 dplEvent->setEvent(event);
215 dplEvent->setForSynchronousCall();
216 calendar->addEvent(dplEvent);
218 if (dplEvent->getResult()) {
219 return converter->toJSValueRefItem(dplEvent->getEvent());
221 ThrowMsg(UnknownException, "Adding failed by unkown reason.");
224 Catch(UnsupportedException)
226 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
227 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
229 Catch(InvalidArgumentException)
231 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
232 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
234 Catch(ConversionException)
236 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
237 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
241 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
242 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
245 return JSValueMakeNull(context);
248 JSValueRef JSCalendar::addBatch(JSContextRef context,
250 JSObjectRef thisObject,
251 size_t argumentCount,
252 const JSValueRef arguments[],
253 JSValueRef* exception)
257 CalendarPrivObject *privateObject =
258 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
259 assert(privateObject);
261 JSCallbackManagerPtr cbm(NULL);
263 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_BATCH);
265 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
269 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
271 if (argumentCount>3 || argumentCount<1) {
272 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
275 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
277 CalendarEventListPtr events;
278 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
279 ThrowMsg(ConversionException, "Wrong parameter type.");
281 events = converter->toVectorOfEventsFromProperty(arguments[0]);
283 LogError("Failed to create events.");
284 ThrowMsg(ConversionException, "Parameter conversion failed.");
287 JSValueRef onError = NULL;
288 if (argumentCount > 2) {
289 onError = getFunctionOrNull(context, arguments[2]);
291 JSContextRef globalContext = privateObject->getContext();
292 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
293 CalendarEventsSuccessCallback result;
294 if (argumentCount > 1) {
295 result.onSuccess = getFunctionOrNull(context, arguments[1]);
297 cbm->setOnSuccess(result.onSuccess);
299 LogDebug("Proceed the event to the platform.");
301 //CalendarEventsCallbackPrivateDataPtr privData(new CalendarEventsCallbackPrivateData(cbm, onAddEventCbm));
302 //OnAddEventsChangedEmitterPtr emitter(new OnAddEventsChangedEmitter());
303 //emitter->setListener(&CalendarResponseDispatcher::getInstance());
304 //emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
305 //calendar->setAddEmitter(emitter);
307 IEventAddEventsPtr dplEvent(new IEventAddEvents());
308 dplEvent->setEvents(events);
309 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
310 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
311 calendar->addEvents(dplEvent);
313 return JSValueMakeNull(context);
315 Catch(UnsupportedException)
317 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
318 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
320 Catch(InvalidArgumentException)
322 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
323 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
325 Catch(ConversionException)
327 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
328 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
332 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
333 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
336 return JSValueMakeNull(context);
339 JSValueRef JSCalendar::update(JSContextRef context,
341 JSObjectRef thisObject,
342 size_t argumentCount,
343 const JSValueRef arguments[],
344 JSValueRef* exception)
348 CalendarPrivObject *privateObject =
349 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
350 assert(privateObject);
352 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_UPDATE);
354 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
358 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
360 if (argumentCount>2 || argumentCount<1) {
361 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
364 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
365 ThrowMsg(ConversionException, "Wrong parameter type.");
366 } else if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarItem::getClassRef())) {
367 ThrowMsg(ConversionException, "Wrong parameter type.");
370 JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
371 CalendarEventPtr event = JSCalendarItem::getPrivateObject(arg);
372 if (!JSCalendarItem::validate(context, arg, exception)) {
373 ThrowMsg(InvalidArgumentException, "Wrong parameter value.");
376 ThrowMsg(ConversionException, "Parameter conversion failed.");
379 bool updateAllInstances = true;
380 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
381 if( argumentCount > 1 ) {
382 if (JSValueIsBoolean(context, arguments[1])) {
383 updateAllInstances = converter->toBool(arguments[1]);
385 ThrowMsg(ConversionException, "Wrong parameter type.");
389 IEventUpdateEventPtr dplEvent(new IEventUpdateEvent());
390 dplEvent->setEvent(event);
391 dplEvent->setUpdateAllInstances(updateAllInstances);
392 dplEvent->setForSynchronousCall();
393 calendar->updateEvent(dplEvent);
395 if (dplEvent->getResult()) {
396 return JSValueMakeNull(context);
398 ThrowMsg(UnknownException, "Updating failed by unkown reason.");
401 Catch(UnsupportedException)
403 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
404 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
406 Catch(InvalidArgumentException)
408 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
409 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
411 Catch(ConversionException)
413 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
414 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
416 Catch (NotFoundException)
418 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
419 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
423 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
424 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
427 return JSValueMakeNull(context);
430 JSValueRef JSCalendar::updateBatch(JSContextRef context,
432 JSObjectRef thisObject,
433 size_t argumentCount,
434 const JSValueRef arguments[],
435 JSValueRef* exception)
439 CalendarPrivObject *privateObject =
440 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
441 assert(privateObject);
443 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_UPDATE_BATCH);
445 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
447 JSCallbackManagerPtr cbm(NULL);
451 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
453 if (argumentCount>4 || argumentCount<1) {
454 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
457 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
459 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
460 ThrowMsg(ConversionException, "Wrong parameter type.");
463 CalendarEventListPtr events;
464 events = converter->toVectorOfEvents(arguments[0]);
466 ThrowMsg(ConversionException, "Parameter conversion failed.");
469 JSValueRef onError = NULL;
470 if (argumentCount > 2) {
471 onError = getFunctionOrNull(context, arguments[2]);
473 JSContextRef globalContext = privateObject->getContext();
474 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
475 CalendarEventsSuccessCallback result;
476 if (argumentCount > 1) {
477 result.onSuccess = getFunctionOrNull(context, arguments[1]);
479 cbm->setOnSuccess(result.onSuccess);
481 bool updateAllInstances = true;
482 if( argumentCount > 3 ) {
483 if (JSValueIsBoolean(context, arguments[3])) {
484 updateAllInstances = converter->toBool(arguments[3]);
486 ThrowMsg(ConversionException, "Wrong parameter type.");
490 LogDebug("Proceed the event to the platform.");
492 IEventUpdateEventsPtr dplEvent(new IEventUpdateEvents());
493 dplEvent->setEvents(events);
494 dplEvent->setUpdateAllInstances(updateAllInstances);
495 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
496 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
497 calendar->updateEvents(dplEvent);
499 return makePendingOperation(cbm->getContext(), dplEvent);
501 Catch(UnsupportedException)
503 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
504 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
506 Catch(InvalidArgumentException)
508 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
509 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
511 Catch(ConversionException)
513 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
514 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
516 Catch (NotFoundException)
518 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
519 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
523 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
524 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
527 return JSValueMakeNull(context);
530 JSValueRef JSCalendar::remove(JSContextRef context,
532 JSObjectRef thisObject,
533 size_t argumentCount,
534 const JSValueRef arguments[],
535 JSValueRef* exception)
538 CalendarPrivObject *privateObject =
539 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
540 assert(privateObject);
542 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE);
544 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
548 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
550 if (argumentCount!=1) {
551 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
554 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
555 ThrowMsg(ConversionException, "Wrong parameter type.");
558 if (!JSValueIsObjectOfClass(context, arguments[0], JSEventId::getClassRef())) {
559 ThrowMsg(ConversionException, "Wrong parameter type.");
563 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
564 itemId = converter->toEventId(arguments[0]);
566 ThrowMsg(ConversionException, "Parameter conversion failed.");
569 IEventDeleteEventPtr dplEvent(new IEventDeleteEvent());
570 dplEvent->setEventId(itemId);
571 dplEvent->setForSynchronousCall();
572 calendar->deleteEvent(dplEvent);
574 if (dplEvent->getResult()) {
575 LogInfo("Successfully deleted.");
576 return JSValueMakeNull(context);
578 if (dplEvent->getExceptionCode() == ExceptionCodes::NotFoundException) {
579 ThrowMsg(ConversionException, "Item not found.");
581 ThrowMsg(UnknownException, "Removing failed by unkown reason.");
585 Catch(UnsupportedException)
587 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
588 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
590 Catch(InvalidArgumentException)
592 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
593 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
595 Catch(ConversionException)
597 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
598 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
600 Catch (NotFoundException)
602 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
603 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
607 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
608 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
611 return JSValueMakeNull(context);
614 JSValueRef JSCalendar::removeBatch(JSContextRef context,
616 JSObjectRef thisObject,
617 size_t argumentCount,
618 const JSValueRef arguments[],
619 JSValueRef* exception)
622 CalendarPrivObject *privateObject =
623 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
624 assert(privateObject);
626 JSCallbackManagerPtr cbm(NULL);
628 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE_BATCH);
630 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
634 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
636 if (argumentCount>3 || argumentCount<1) {
637 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
640 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
642 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
643 ThrowMsg(ConversionException, "Wrong parameter type.");
646 EventIdListPtr itemIds;
647 itemIds = converter->toVectorOfEventIds(arguments[0]);
649 ThrowMsg(ConversionException, "Parameter conversion failed.");
652 JSValueRef onError = NULL;
653 if (argumentCount > 2) {
654 onError = getFunctionOrNull(context, arguments[2]);
656 JSContextRef globalContext = privateObject->getContext();
657 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
658 CalendarEventsSuccessCallback result;
659 if (argumentCount > 1) {
660 result.onSuccess = getFunctionOrNull(context, arguments[1]);
662 cbm->setOnSuccess(result.onSuccess);
664 LogDebug("Proceed the event to the platform.");
666 IEventDeleteEventsPtr dplEvent(new IEventDeleteEvents());
667 dplEvent->setEventIds(itemIds);
668 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
669 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
670 calendar->deleteEvents(dplEvent);
672 return makePendingOperation(cbm->getContext(), dplEvent);
674 Catch(UnsupportedException)
676 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
677 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
679 Catch(InvalidArgumentException)
681 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
682 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
684 Catch(ConversionException)
686 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
687 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
689 Catch (NotFoundException)
691 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
692 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
696 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
697 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
700 return JSValueMakeNull(context);
703 JSValueRef JSCalendar::findWithWACFilter(JSContextRef context,
705 JSObjectRef thisObject,
706 size_t argumentCount,
707 const JSValueRef arguments[],
708 JSValueRef* exception)
711 CalendarPrivObject *privateObject =
712 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
713 assert(privateObject);
715 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND);
717 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
719 JSCallbackManagerPtr cbm(NULL);
722 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
723 if (argumentCount<1 || argumentCount>4) {
724 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
726 JSValueRef onError = (argumentCount > 1 ? getFunctionOrNull(context, arguments[1]) : NULL);
727 JSContextRef globalContext = privateObject->getContext();
728 cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
730 Validator validator(context);
731 if (validator.isCallback(arguments[0])) {
732 cbm->setOnSuccess(arguments[0]);
733 } else if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) {
734 ThrowMsg(ConversionException, "Wrong parameter type.");
736 ThrowMsg(ConversionException, "Wrong parameter type.");
739 EventFilterPtr filter(NULL);
740 if (argumentCount >= 3) {
741 LogDebug("setting some filters");
742 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
743 if (!JSValueIsUndefined(context, arguments[2]) && !JSValueIsNull(context, arguments[2])) {
744 filter = converter->toEventFilter(arguments[2]);
747 IEventFindEventsPtr dplEvent(new IEventFindEvents());
748 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
749 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
750 dplEvent->setFilter(filter);
751 calendar->findEvents(dplEvent);
753 return JSValueMakeNull(context);
755 Catch(UnsupportedException)
757 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
758 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
760 Catch(InvalidArgumentException)
762 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
763 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
765 Catch(ConversionException)
767 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
768 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
770 Catch (NotFoundException)
772 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
773 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
777 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
778 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
781 return JSValueMakeNull(context);
784 JSValueRef JSCalendar::find(JSContextRef context,
786 JSObjectRef thisObject,
787 size_t argumentCount,
788 const JSValueRef arguments[],
789 JSValueRef* exception)
793 CalendarPrivObject *privateObject =
794 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
795 assert(privateObject);
797 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND);
799 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
803 if (argumentCount<1 || argumentCount>4) {
804 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
807 JSCallbackManagerPtr cbm(NULL);
809 Validator validator(context, exception);
810 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
811 TizenApis::Tizen1_0::Tizen::FilterConverterFactory::ConverterType filterConverter = TizenApis::Tizen1_0::Tizen::FilterConverterFactory::getConverter(context);
812 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
814 JSContextRef globalContext = privateObject->getContext();
815 cbm = JSCallbackManager::createObject(globalContext);
817 if ((!validator.isCallback(arguments[0])) ||
818 (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) ||
819 (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) && !validator.isNullOrUndefined(arguments[2]))) ||
820 (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) && !validator.isNullOrUndefined(arguments[3]))) ||
821 (argumentCount >= 5 && (!JSValueIsObject(context, arguments[4]) && !validator.isNullOrUndefined(arguments[4])))) {
822 ThrowMsg(ConversionException, "Wrong parameter type.");
826 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
827 onSuccessForCbm = arguments[0];
828 if (argumentCount >= 2) {
829 onErrorForCbm = arguments[1];
831 cbm->setOnSuccess(onSuccessForCbm);
832 cbm->setOnError(onErrorForCbm);
835 IEventFindEventsPtr dplEvent(new IEventFindEvents());
836 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
837 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
839 if (argumentCount >= 3 && !validator.isNullOrUndefined(arguments[2])) {
840 dplEvent->setGenericFilter(filterConverter->toFilter(arguments[2]));
842 if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) {
843 // Though the sortMode is a single type, we save it in an array internally.
844 TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
845 sortModes->push_back(filterConverter->toSortMode(arguments[3]));
846 dplEvent->setSortModes(sortModes);
848 /*if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) {
849 dplEvent->setAttributesOfInterest(converter->toVectorOfStrings(arguments[4]));
852 calendar->findEvents(dplEvent);
854 Catch(UnsupportedException)
856 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
857 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
859 Catch(InvalidArgumentException)
861 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
862 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
864 Catch(ConversionException)
866 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
867 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
869 Catch (NotFoundException)
871 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
872 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
876 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
877 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
880 return JSValueMakeNull(context);
883 JSValueRef JSCalendar::expandEventRecurrence(JSContextRef context,
885 JSObjectRef thisObject,
886 size_t argumentCount,
887 const JSValueRef arguments[],
888 JSValueRef* exception)
891 CalendarPrivObject *privateObject =
892 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
893 assert(privateObject);
895 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_EXPAND_EVENT_RECURRENCE);
897 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
899 JSCallbackManagerPtr cbm(NULL);
903 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
904 if (argumentCount>5 || argumentCount<4) {
905 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
908 JSValueRef onError =(argumentCount > 4 ? getFunctionOrNull(context, arguments[4]) : NULL);
909 JSContextRef globalContext = privateObject->getContext();
910 cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
912 Validator validator(context);
913 if (validator.isCallback(arguments[3])) {
914 cbm->setOnSuccess(arguments[3]);
915 } else if (JSValueIsNull(context, arguments[3]) || JSValueIsUndefined(context, arguments[3])) {
916 ThrowMsg(ConversionException, "Wrong parameter type.");
918 ThrowMsg(ConversionException, "Wrong parameter type.");
921 JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
922 CalendarEventPtr event = JSCalendarItem::getPrivateObject(arg);
924 ThrowMsg(ConversionException, "Parameter conversion failed.");
927 std::time_t startDate = 0;
928 std::time_t endDate = INT_MAX; // about 60 years in 4 bytes system.
929 Converter converter(context);
930 TimeUtilConverter timeConverter(context);
931 if (argumentCount>1 ) {
932 startDate = timeConverter.toTZDateTimeT(arguments[1]);
934 if (argumentCount>2 ) {
935 endDate = timeConverter.toDateTimeT(arguments[2]);
938 IEventExpandEventRecurrencePtr dplEvent(new IEventExpandEventRecurrence());
939 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
940 dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
941 dplEvent->setEvent(event);
942 dplEvent->setStartDate(startDate);
943 dplEvent->setEndDate(endDate);
944 calendar->expandEventRecurrence(dplEvent);
946 return JSValueMakeNull(context);
948 Catch(UnsupportedException)
950 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
951 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
953 Catch(InvalidArgumentException)
955 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
956 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
958 Catch(ConversionException)
960 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
961 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
963 Catch (NotFoundException)
965 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
966 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
970 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
971 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
974 return JSValueMakeNull(context);
977 JSValueRef JSCalendar::convertFromString(JSContextRef context,
979 JSObjectRef thisObject,
980 size_t argumentCount,
981 const JSValueRef arguments[],
982 JSValueRef* exception)
986 CalendarPrivObject *privateObject =
987 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
988 assert(privateObject);
990 JSContextRef globalContext = privateObject->getContext();
992 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(globalContext, CALENDAR_FUNCTION_API_CONVERT_FROM_STRING);
994 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
998 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
999 if (argumentCount!=2) {
1000 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1003 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
1004 ThrowMsg(ConversionException, "Wrong parameter type.");
1006 else if (!JSValueIsString(context, arguments[0])) {
1007 ThrowMsg(ConversionException, "First parameter is not a string type.");
1010 if (JSValueIsUndefined(context, arguments[1]) || JSValueIsNull(context, arguments[1])) {
1011 ThrowMsg(ConversionException, "Wrong parameter type.");
1013 else if (!JSValueIsString(context, arguments[1])) {
1014 ThrowMsg(ConversionException, "Second parameter is not a CalendarTextFormat type.");
1017 CalendarConverterFactory::ConverterType converter =
1018 CalendarConverterFactory::getConverter(globalContext);
1020 std::string eventStr;
1021 CalendarEvent::VObjectFormat format = CalendarEvent::ICALENDAR_20;
1023 eventStr = converter->toString(arguments[0]);
1025 if( argumentCount>1 )
1027 if (JSValueIsString(context, arguments[1])) {
1028 format = converter->toVObjectFormat(converter->toString(arguments[1]));
1030 ThrowMsg(ConversionException, "Second parameter is not a CalendarTextFormat type.");
1034 IEventCreateEventFromStringPtr dplEvent(new IEventCreateEventFromString());
1035 dplEvent->setEventString(eventStr);
1036 dplEvent->setFormat(format);
1037 dplEvent->setForSynchronousCall();
1038 calendar->createEventFromString(dplEvent);
1040 if (dplEvent->getResult()) {
1041 LogInfo("Successfully created an event.");
1042 return converter->toJSValueRefItemProperties(dplEvent->getEvent());
1044 ThrowMsg(UnknownException, "Converting from string failed by unkown reason.");
1047 Catch(UnsupportedException)
1049 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1050 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1052 Catch(InvalidArgumentException)
1054 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1055 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1057 Catch(ConversionException)
1059 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1060 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1064 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1065 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1068 return JSValueMakeNull(context);
1071 JSValueRef JSCalendar::convertToString(JSContextRef context,
1073 JSObjectRef thisObject,
1074 size_t argumentCount,
1075 const JSValueRef arguments[],
1076 JSValueRef* exception)
1078 LogDebug("entered");
1080 CalendarPrivObject *privateObject =
1081 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1082 assert(privateObject);
1084 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(),
1085 CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
1087 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1091 ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
1092 if (argumentCount!=2) {
1093 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1096 if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
1097 ThrowMsg(ConversionException, "Wrong parameter type.");
1100 if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
1101 if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarItem::getClassRef())) {
1102 ThrowMsg(ConversionException, "First parameter is not a CalendarItem type.");
1104 if (!JSCalendarEvent::validate(context, Converter(context).toJSObjectRef(arguments[0]), NULL)) {
1105 ThrowMsg(InvalidArgumentException, "Wrong parameter value.");
1107 } else if(CalendarEvent::TASK_TYPE==calendar->getType()) {
1108 if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarItem::getClassRef())) {
1109 ThrowMsg(ConversionException, "First parameter is not a CalendarItem type.");
1111 if (!JSCalendarTask::validate(context, Converter(context).toJSObjectRef(arguments[0]), NULL)) {
1112 ThrowMsg(InvalidArgumentException, "Wrong parameter value.");
1116 JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
1117 CalendarEventPtr event = JSCalendarItem::getPrivateObject(arg);
1119 ThrowMsg(ConversionException, "Parameter conversion failed.");
1122 CalendarEvent::VObjectFormat format = CalendarEvent::ICALENDAR_20;
1123 CalendarConverter converter(context);
1124 if( argumentCount>1 )
1126 if (JSValueIsString(context, arguments[1])) {
1127 format = converter.toVObjectFormat(converter.toString(arguments[1]));
1131 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
1132 dplEvent->setEvent(event);
1133 dplEvent->setFormat(format);
1134 dplEvent->setForSynchronousCall();
1135 calendar->exportEventToString(dplEvent);
1137 if (dplEvent->getResult()) {
1138 return converter.toJSValueRef(dplEvent->getEventString());
1140 ThrowMsg(UnknownException, "Converting to string failed by unkown reason.");
1143 Catch(UnsupportedException)
1145 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1146 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1148 Catch(InvalidArgumentException)
1150 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1151 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1153 Catch(ConversionException)
1155 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1156 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1158 Catch (NotFoundException)
1160 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1161 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
1165 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1166 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1169 return JSValueMakeNull(context);
1172 JSValueRef JSCalendar::addChangeListener(JSContextRef context,
1174 JSObjectRef thisObject,
1175 size_t argumentCount,
1176 const JSValueRef arguments[],
1177 JSValueRef* exception)
1179 LogDebug("entered");
1180 CalendarPrivObject *privateObject =
1181 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1182 assert(privateObject);
1184 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER);
1186 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1188 JSCallbackManagerPtr cbm(NULL);
1191 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
1192 if (argumentCount>2 || argumentCount<1) {
1193 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1196 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
1197 JSValueRef onError = NULL;
1198 if (argumentCount > 1) {
1199 onError = getFunctionOrNull(context, arguments[1]);
1201 JSContextRef globalContext = privateObject->getContext();
1202 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
1203 JSObjectRef objectCallbacks = converter->toJSObjectRef(arguments[0]);
1204 CalendarChangeCallback result;
1205 result.onAdded = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsAdded");
1206 result.onUpdated = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsUpdated");
1207 result.onDeleted = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onItemsRemoved");
1208 Validator validator(context);
1209 if ((!validator.isNullOrUndefined(result.onAdded) && !validator.isCallback(result.onAdded)) ||
1210 (!validator.isNullOrUndefined(result.onUpdated) && !validator.isCallback(result.onUpdated)) ||
1211 (!validator.isNullOrUndefined(result.onDeleted) && !validator.isCallback(result.onDeleted)))
1213 ThrowMsg(InvalidArgumentException, "Wrong successCallback parameter value.");
1215 JSCallbackManagerPtr onAddedCbm = JSCallbackManager::createObject(globalContext, result.onAdded, NULL);
1216 JSCallbackManagerPtr onUpdatedCbm = JSCallbackManager::createObject(globalContext, result.onUpdated, NULL);
1217 JSCallbackManagerPtr onDeletedCbm = JSCallbackManager::createObject(globalContext, result.onDeleted, NULL);
1219 /* The interested attributes are not supported in platform.
1220 AttributeListPtr attributes;
1221 if( argumentCount >= 3 ) {
1224 *attributes = converter->toVectorOfStrings(arguments[2]);
1226 LogError("watchChanges: Failed to get interested attributes");
1227 Throw(InvalidArgumentException);
1232 LogError("Error while converting the attributes");
1233 Throw(InvalidArgumentException);
1237 LogDebug("Make change emitter and sync operation");
1239 CalendarChangeCallbackPrivateDataPtr privData(new CalendarChangeCallbackPrivateData(
1240 onAddedCbm, onUpdatedCbm, onDeletedCbm));
1241 OnEventsChangedEmitterPtr emitter(new OnEventsChangedEmitter());
1242 emitter->setListener(&CalendarResponseDispatcher::getInstance());
1243 emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
1245 // return sync operation and process the events and emit results while processing them
1246 IEventWatchChangesPtr dplEvent(new IEventWatchChanges());
1247 dplEvent->setEmitter(emitter);
1248 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
1249 dplEvent->setForSynchronousCall();
1250 calendar->watchChanges(dplEvent);
1253 if (dplEvent->getResult()) {
1254 watchId = dplEvent->getWatchId();
1255 LogDebug("Returning the watchId "<<watchId);
1256 return converter->toJSValueRefLong(watchId);
1258 ThrowMsg(UnknownException, "Adding change listener failed by unkown reason.");
1260 return JSValueMakeNull(context);
1262 Catch(UnsupportedException)
1264 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1265 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1267 Catch(InvalidArgumentException)
1269 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1270 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1272 Catch(ConversionException)
1274 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1275 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1279 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1280 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1283 return JSValueMakeNull(context);
1286 JSValueRef JSCalendar::removeChangeListener(JSContextRef context,
1288 JSObjectRef thisObject,
1289 size_t argumentCount,
1290 const JSValueRef arguments[],
1291 JSValueRef* exception)
1293 LogDebug("entered");
1294 CalendarPrivObject *privateObject =
1295 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
1296 assert(privateObject);
1298 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER);
1300 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1304 ICalendarPtr calendar = getCalendar(context, thisObject, exception);
1305 if (argumentCount!=1) {
1306 ThrowMsg(InvalidArgumentException, "Wrong number of parameters.");
1310 CalendarConverterFactory::ConverterType converter = CalendarConverterFactory::getConverter(context);
1311 if (JSValueIsNumber(context, arguments[0])) {
1312 watchId = converter->toLong(arguments[0]);
1315 LogDebug("Make sync operation");
1317 IEventClearWatchPtr dplEvent(new IEventClearWatch());
1318 dplEvent->setWatchId(watchId);
1319 dplEvent->setForSynchronousCall();
1320 calendar->clearWatch(dplEvent);
1322 return JSValueMakeNull(context);
1324 Catch(UnsupportedException)
1326 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1327 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
1329 Catch(InvalidArgumentException)
1331 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1332 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
1334 Catch(ConversionException)
1336 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1337 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
1339 Catch (NotFoundException)
1341 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1342 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
1346 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1347 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
1350 return JSValueMakeNull(context);
1353 JSValueRef JSCalendar::getPropertyName(JSContextRef context,
1355 JSStringRef propertyName,
1356 JSValueRef* exception)
1360 ICalendarPtr calendar = getCalendar(context, object, exception);
1361 Converter converter(context);
1362 return converter.toJSValueRef(calendar->getName());
1366 LogError("error during executing a function");
1368 return JSValueMakeUndefined(context);
1371 JSValueRef JSCalendar::getPropertyAccountId(JSContextRef context,
1373 JSStringRef propertyName,
1374 JSValueRef* exception)
1378 ICalendarPtr calendar = getCalendar(context, object, exception);
1379 Converter converter(context);
1380 return converter.toJSValueRefLong(calendar->getAccountId());
1384 LogError("error during executing a function");
1386 return JSValueMakeUndefined(context);
1389 JSValueRef JSCalendar::getPropertyId(JSContextRef context,
1391 JSStringRef propertyName,
1392 JSValueRef* exception)
1396 ICalendarPtr calendar = getCalendar(context, object, exception);
1397 Converter converter(context);
1398 return converter.toJSValueRef(calendar->getId());
1402 LogError("error during executing a function");
1404 return JSValueMakeUndefined(context);
1407 ICalendarPtr JSCalendar::getCalendar(JSContextRef ctx,
1408 const JSObjectRef object,
1409 JSValueRef* exception)
1411 CalendarPrivObject *priv =
1412 static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
1414 return priv->getObject();
1416 ThrowMsg(NullPointerException, "Private object is NULL.");