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 "JSCalendarItemGeo.h"
19 #include <dpl/log/log.h>
20 #include <Tizen/Common/JSTizenExceptionFactory.h>
21 #include <Tizen/Common/JSTizenException.h>
22 #include <CommonsJavaScript/Converter.h>
24 using namespace TizenApis::Api::Calendar;
25 using namespace WrtDeviceApis::Commons;
26 using namespace WrtDeviceApis::CommonsJavaScript;
32 #define TIZEN_CALENDAR_ITEM_GEO_ATTRIBUTENAME "CalendarItemGeo"
34 JSClassDefinition JSCalendarItemGeo::m_classInfo = {
36 kJSClassAttributeNone,
37 TIZEN_CALENDAR_ITEM_GEO_ATTRIBUTENAME,
46 NULL, //deleteProperty,
47 NULL, //getPropertyNames,
48 NULL, //callAsFunction,
49 NULL, //callAsConstructor,
51 NULL, //convertToType,
54 JSStaticValue JSCalendarItemGeo::m_property[] = {
55 { TIZEN_CALENDAR_ITEM_GEO_LATITUDE, getProperty, setProperty, kJSPropertyAttributeNone },
56 { TIZEN_CALENDAR_ITEM_GEO_LONGITUDE, getProperty, setProperty, kJSPropertyAttributeNone },
60 JSClassRef JSCalendarItemGeo::m_jsClassRef = JSClassCreate(
61 JSCalendarItemGeo::getClassInfo());
63 const JSClassDefinition* JSCalendarItemGeo::getClassInfo()
65 return &(m_classInfo);
68 JSClassRef JSCalendarItemGeo::getClassRef()
71 m_jsClassRef = JSClassCreate(&m_classInfo);
76 CalendarItemGeoPtr JSCalendarItemGeo::getPrivateObject(JSObjectRef object)
79 CalendarItemGeoPrivateObject *priv =
80 static_cast<CalendarItemGeoPrivateObject*>(JSObjectGetPrivate(object));
82 ThrowMsg(NullPointerException, "Private object is null");
84 CalendarItemGeoPtr result = priv->getObject();
86 ThrowMsg(NullPointerException, "Private object is null");
91 void JSCalendarItemGeo::initialize(JSContextRef context,
97 void JSCalendarItemGeo::finalize(JSObjectRef object)
100 CalendarItemGeoPrivateObject* priv =
101 static_cast<CalendarItemGeoPrivateObject*>(JSObjectGetPrivate(object));
103 JSObjectSetPrivate(object, NULL);
106 JSValueRef JSCalendarItemGeo::getProperty(JSContextRef context,
108 JSStringRef propertyName,
109 JSValueRef* exception)
112 Converter converter(context);
115 CalendarItemGeoPrivateObject* priv =
116 static_cast<CalendarItemGeoPrivateObject*>(JSObjectGetPrivate(object));
118 Throw(NullPointerException);
120 CalendarItemGeoPtr geoInfo = priv->getObject();
122 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ITEM_GEO_LATITUDE)) {
123 double latitude = geoInfo->getLatitude();
124 if( latitude==CalendarItemGeo::GEO_UNDEFINED ) {
125 return JSValueMakeUndefined(context);
127 return converter.toJSValueRef(geoInfo->getLatitude());
129 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ITEM_GEO_LONGITUDE)) {
130 double longitude = geoInfo->getLongitude();
131 if( longitude==CalendarItemGeo::GEO_UNDEFINED ) {
132 return JSValueMakeUndefined(context);
134 return converter.toJSValueRef(geoInfo->getLongitude());
140 LogError("invalid property");
143 return JSValueMakeUndefined(context);
146 bool JSCalendarItemGeo::setProperty(JSContextRef context,
148 JSStringRef propertyName,
150 JSValueRef* exception)
153 Converter converter(context);
156 CalendarItemGeoPrivateObject* priv =
157 static_cast<CalendarItemGeoPrivateObject*>(JSObjectGetPrivate(object));
159 Throw(NullPointerException);
161 CalendarItemGeoPtr geoInfo = priv->getObject();
163 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ITEM_GEO_LATITUDE)) {
164 if (!JSValueIsNumber(context, value)) {
165 Throw(InvalidArgumentException);
167 double latitude = converter.toDouble(value);
168 if( latitude>CalendarItemGeo::GEO_LATITUDE_MAX ) {
169 geoInfo->setLatitude(CalendarItemGeo::GEO_LATITUDE_MAX);
170 } else if( latitude<CalendarItemGeo::GEO_LATITUDE_MIN ) {
171 geoInfo->setLatitude(CalendarItemGeo::GEO_LATITUDE_MIN);
173 geoInfo->setLatitude(latitude);
176 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ITEM_GEO_LONGITUDE)) {
177 if (!JSValueIsNumber(context, value)) {
178 Throw(InvalidArgumentException);
180 double longitude = converter.toDouble(value);
181 if( longitude>CalendarItemGeo::GEO_LONGITUDE_MAX ) {
182 geoInfo->setLongitude(CalendarItemGeo::GEO_LONGITUDE_MAX);
183 } else if( longitude<CalendarItemGeo::GEO_LONGITUDE_MIN ) {
184 geoInfo->setLongitude(CalendarItemGeo::GEO_LONGITUDE_MIN);
186 geoInfo->setLongitude(longitude);
193 LogWarning("trying to set incorrect value");
196 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);