summaryrefslogtreecommitdiff
path: root/mobile_src/Calendar/JSCalendarManager.cpp
diff options
context:
space:
mode:
authorSehong Na <sehong.na@samsung.com>2014-05-31 13:20:25 +0900
committerSehong Na <sehong.na@samsung.com>2014-05-31 13:20:25 +0900
commit59c401dcb6127a3ca74995bd3b3a7864a95fc418 (patch)
tree1d621db3eb1506f2fa42f1c38e143b90e1c3984f /mobile_src/Calendar/JSCalendarManager.cpp
downloadwrt-plugins-tizen-59c401dcb6127a3ca74995bd3b3a7864a95fc418.tar.gz
wrt-plugins-tizen-59c401dcb6127a3ca74995bd3b3a7864a95fc418.tar.bz2
wrt-plugins-tizen-59c401dcb6127a3ca74995bd3b3a7864a95fc418.zip
Diffstat (limited to 'mobile_src/Calendar/JSCalendarManager.cpp')
-rwxr-xr-xmobile_src/Calendar/JSCalendarManager.cpp421
1 files changed, 421 insertions, 0 deletions
diff --git a/mobile_src/Calendar/JSCalendarManager.cpp b/mobile_src/Calendar/JSCalendarManager.cpp
new file mode 100755
index 0000000..8d6ebfc
--- /dev/null
+++ b/mobile_src/Calendar/JSCalendarManager.cpp
@@ -0,0 +1,421 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+
+#include <string>
+#include "ICalendar.h"
+#include "ICalendarManager.h"
+#include "CalendarFactory.h"
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <JSWebAPIErrorFactory.h>
+#include <SecurityExceptions.h>
+#include <TimeTracer.h>
+#include <Export.h>
+#include <Logger.h>
+#include <GlobalContextManager.h>
+
+#include "JSCalendarManager.h"
+#include "JSCalendar.h"
+#include "CalendarConverter.h"
+#include "CalendarResponseDispatcher.h"
+#include "plugin_config.h"
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DeviceAPI::Common;
+
+#define TIZEN_CALENDAR_MANAGER_ATTRIBUTENAME "calendar"
+
+namespace DeviceAPI {
+namespace Calendar {
+
+using WrtDeviceApis::Commons::UnknownException;
+using WrtDeviceApis::Commons::NotFoundException;
+
+JSClassDefinition JSCalendarManager::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ TIZEN_CALENDAR_MANAGER_ATTRIBUTENAME,
+ 0,
+ NULL,
+ m_function,
+ initialize,
+ finalize,
+ NULL, //HasProperty,
+ NULL, //GetProperty,
+ NULL, //SetProperty,
+ NULL, //DeleteProperty,
+ NULL, //GetPropertyNames,
+ NULL, //CallAsFunction,
+ NULL, //CallAsConstructor,
+ NULL, //HasInstance,
+ NULL //ConvertToType
+};
+
+JSStaticFunction JSCalendarManager::m_function[] = {
+ { CALENDAR_FUNCTION_API_GET_CALENDARS, getCalendars, kJSPropertyAttributeNone },
+ { CALENDAR_FUNCTION_API_GET_DEFAULT_CALENDAR, getDefaultCalendar, kJSPropertyAttributeNone },
+ { CALENDAR_FUNCTION_API_GET_UNIFIED_CALENDAR, getUnifiedCalendar, kJSPropertyAttributeNone },
+ { CALENDAR_FUNCTION_API_GET_CALENDAR, getCalendar, kJSPropertyAttributeNone },
+
+ { 0, 0, 0 }
+};
+
+JSClassRef JSCalendarManager::m_jsClassRef = JSClassCreate(
+ JSCalendarManager::getClassInfo());
+
+void JSCalendarManager::initialize(JSContextRef context,
+ JSObjectRef object)
+{
+ if (!JSObjectGetPrivate(object)) {
+ LoggerD("Create calendar manager private object.");
+ ICalendarManagerPtr calendarManager = CalendarFactory::getInstance().createCalendarManagerObject();
+ CalendarManagerPrivObject *privateObject = new CalendarManagerPrivObject(context, calendarManager);
+ if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject))) {
+ delete privateObject;
+ }
+ } else {
+ LoggerD("Private object already set.");
+ }
+}
+
+void JSCalendarManager::finalize(JSObjectRef object)
+{
+ CalendarManagerPrivObject *priv = static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(object));
+ if (priv) {
+ delete priv;
+ JSObjectSetPrivate(object, NULL);
+ }
+}
+
+JSValueRef JSCalendarManager::getCalendars(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ CalendarManagerPrivObject *privateObject = static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+ Try {
+ if (!privateObject) {
+ ThrowMsg(ConversionException, "Object is null.");
+ }
+
+ TIZEN_CHECK_ACCESS(context, exception, privateObject, CALENDAR_FUNCTION_API_GET_CALENDARS);
+
+ CalendarConverter converter(context);
+
+ JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+ CalendarEvent::CalendarType calendarType = CalendarEvent::UNDEFINED_TYPE;
+ if (argumentCount>=1) {
+ calendarType = converter.toCalendarType(converter.toString(arguments[0]));
+ }
+
+ if (argumentCount>=2) {
+ cbm->setOnSuccess(converter.toFunction(arguments[1]));
+ } else {
+ ThrowMsg(ConversionException, "Wrong parameter count.");
+ }
+
+ if (argumentCount>=3) {
+ cbm->setOnError(converter.toFunctionOrNull(arguments[2]));
+ }
+
+ cbm->setObject(thisObject);
+
+ IEventGetCalendarsPtr dplEvent(new IEventGetCalendars());
+ dplEvent->setType(calendarType);
+ dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+ dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
+ dplEvent->copyAceCheckAccessFunction(privateObject);
+ privateObject->getObject()->getCalendars(dplEvent);
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+ }
+ Catch(UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+}
+
+JSValueRef JSCalendarManager::getDefaultCalendar(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ CalendarManagerPrivObject *privateObject = static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+ Try {
+ if (!privateObject) {
+ ThrowMsg(ConversionException, "Object is null.");
+ }
+
+ TIZEN_CHECK_ACCESS(context, exception, privateObject, CALENDAR_FUNCTION_API_GET_DEFAULT_CALENDAR);
+
+ // Global context should be passed to the calendar object.
+ JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+
+ CalendarConverter converter(globalContext, privateObject);
+ CalendarEvent::CalendarType calendarType = CalendarEvent::UNDEFINED_TYPE;
+ if (argumentCount>=1) {
+ calendarType = converter.toCalendarType(converter.toString(arguments[0]));
+ } else {
+ ThrowMsg(ConversionException, "Wrong parameter type.");
+ }
+
+ IEventGetDefaultCalendarPtr dplEvent(new IEventGetDefaultCalendar());
+ dplEvent->setForSynchronousCall();
+ dplEvent->setType(calendarType);
+ privateObject->getObject()->getDefaultCalendar(dplEvent);
+
+ if (dplEvent->getResult()) {
+ if( dplEvent->getCalendar() ) {
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return converter.toJSValueRefCalendar(dplEvent->getCalendar());
+ } else {
+ LoggerE("Default calendar not found.");
+ }
+ } else {
+ ThrowMsg(UnknownException, "Getting a default calendar failed by unknown reason.");
+ }
+ }
+ Catch(UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch (NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCalendarManager::getUnifiedCalendar(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ CalendarManagerPrivObject *privateObject = static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+ Try {
+ if (!privateObject) {
+ ThrowMsg(ConversionException, "Object is null.");
+ }
+
+ TIZEN_CHECK_ACCESS(context, exception, privateObject, CALENDAR_FUNCTION_API_GET_UNIFIED_CALENDAR);
+
+ // Global context should be passed to the calendar object.
+ JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+
+ CalendarConverter converter(globalContext, privateObject);
+ CalendarEvent::CalendarType calendarType = CalendarEvent::UNDEFINED_TYPE;
+ if (argumentCount>=1) {
+ calendarType = converter.toCalendarType(converter.toString(arguments[0]));
+ } else {
+ ThrowMsg(ConversionException, "Wrong parameter type.");
+ }
+
+ IEventGetUnifiedCalendarPtr dplEvent(new IEventGetUnifiedCalendar());
+ dplEvent->setForSynchronousCall();
+ dplEvent->setType(calendarType);
+ privateObject->getObject()->getUnifiedCalendar(dplEvent);
+
+ if (dplEvent->getResult()) {
+ if( dplEvent->getCalendar() ) {
+ LoggerD("Successfully got a unified calendar.");
+ return converter.toJSValueRefCalendar(dplEvent->getCalendar());
+ } else {
+ LoggerE("Unified calendar not found.");
+ }
+ } else {
+ ThrowMsg(UnknownException, "Getting a unified calendar failed by unknown reason.");
+ }
+ }
+ Catch(UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch (NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCalendarManager::getCalendar(JSContextRef context,
+ JSObjectRef object,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
+{
+ TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+ CalendarManagerPrivObject *privateObject = static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+ Try {
+ if (!privateObject) {
+ ThrowMsg(ConversionException, "Object is null.");
+ }
+
+ TIZEN_CHECK_ACCESS(context, exception, privateObject, CALENDAR_FUNCTION_API_GET_CALENDAR);
+
+ // Global context should be passed to the calendar object.
+ JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+
+ CalendarConverter converter(globalContext, privateObject);
+
+ CalendarEvent::CalendarType calendarType = CalendarEvent::UNDEFINED_TYPE;
+ if (argumentCount>=1) {
+ calendarType = converter.toCalendarType(converter.toString(arguments[0]));
+ } else {
+ ThrowMsg(ConversionException, "Wrong parameter count.");
+ }
+
+ std::string calendarId;
+ if (argumentCount>=2) {
+ calendarId = converter.toString(arguments[1]);
+ }
+
+ IEventGetCalendarPtr dplEvent(new IEventGetCalendar());
+ dplEvent->setForSynchronousCall();
+ dplEvent->setId(calendarId);
+ dplEvent->setType(calendarType);
+ privateObject->getObject()->getCalendar(dplEvent);
+
+ // Process the result.
+ if (dplEvent->getResult()) {
+ if( dplEvent->getCalendar() ) {
+ TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+ return converter.toJSValueRefCalendar(dplEvent->getCalendar());
+ } else {
+ ThrowMsg(NotFoundException, "Calendar not found.");
+ }
+ } else {
+ ThrowMsg(UnknownException, "Getting a calendar failed by unknown reason.");
+ }
+ }
+ Catch(UnsupportedException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(InvalidArgumentException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(ConversionException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch (NotFoundException)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+ }
+ Catch(Exception)
+ {
+ LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+ return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+ }
+}
+
+const JSClassRef DLL_EXPORT JSCalendarManager::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCalendarManager::getClassInfo()
+{
+ return &m_classInfo;
+}
+
+}
+}