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.
22 * @file JSAcceleration.cpp
30 #include <dpl/log/log.h>
31 #include <CommonsJavaScript/JSUtils.h>
32 #include <CommonsJavaScript/Converter.h>
33 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
34 #include "JSAddress.h"
39 using namespace WrtDeviceApis;
40 using namespace Api::Geocoder;
43 #define GEOCODER_COUNTRY "country"
44 #define GEOCODER_REGION "region"
45 #define GEOCODER_COUNTY "county"
46 #define GEOCODER_CITY "city"
47 #define GEOCODER_STREET "street"
48 #define GEOCODER_STREET_NUMBER "streetNumber"
49 #define GEOCODER_PREMISES "premises"
50 #define GEOCODER_ADDITIONAL_INFORMATION "additionalInformation"
51 #define GEOCODER_POSTAL_CODE "postalCode"
52 //} //private namespace
54 JSClassDefinition JSAddress::m_classInfo = {
56 kJSClassAttributeNone,
66 NULL, //DeleteProperty,
67 NULL, //GetPropertyNames,
68 NULL, //CallAsFunction,
69 NULL, //CallAsConstructor,
70 hasInstance, NULL, //ConvertToType
73 JSStaticValue JSAddress::m_property[] = {
74 { GEOCODER_COUNTRY, getProperty, NULL, kJSPropertyAttributeReadOnly },
75 { GEOCODER_REGION, getProperty, NULL, kJSPropertyAttributeReadOnly },
76 { GEOCODER_COUNTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
77 { GEOCODER_CITY, getProperty, NULL, kJSPropertyAttributeReadOnly },
78 { GEOCODER_STREET, getProperty, NULL, kJSPropertyAttributeReadOnly },
79 { GEOCODER_STREET_NUMBER, getProperty, NULL, kJSPropertyAttributeReadOnly },
80 { GEOCODER_PREMISES, getProperty, NULL, kJSPropertyAttributeReadOnly },
81 { GEOCODER_ADDITIONAL_INFORMATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
82 { GEOCODER_POSTAL_CODE, getProperty, NULL, kJSPropertyAttributeReadOnly },
86 const JSClassRef JSAddress::getClassRef() {
88 m_jsClassRef = JSClassCreate(&m_classInfo);
93 const JSClassDefinition* JSAddress::getClassInfo() {
97 JSClassRef JSAddress::m_jsClassRef = JSClassCreate(JSAddress::getClassInfo());
99 JSObjectRef JSAddress::createJSObject(JSContextRef context, const GeocoderProperties &geocoderProperties) {
100 LogDebug("<<< context:" << context);
102 std::auto_ptr<GeocoderProperties> accProps(new GeocoderProperties(geocoderProperties));
103 JSAddressPriv *priv = new JSAddressPriv(context, accProps.get());
106 ThrowMsg(Commons::NullPointerException, "Can not new an object");
110 return JSObjectMake(context, getClassRef(), priv);
113 void JSAddress::initialize(JSContextRef context, JSObjectRef object) {
114 LogDebug("Entered. Nothing to do.");
117 void JSAddress::finalize(JSObjectRef object) {
119 JSAddressPriv* priv = static_cast<JSAddressPriv*> (JSObjectGetPrivate(object));
120 JSObjectSetPrivate(object, NULL);
121 LogDebug("Deleting acceleration object");
125 JSValueRef JSAddress::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {
126 LogDebug("<<< object" << object);
128 JSAddressPriv *priv = static_cast<JSAddressPriv*> (JSObjectGetPrivate(object));
129 assert(priv && "Private object not set.");
132 GeocoderProperties *geocoderProperties = priv->getObject();
133 WrtDeviceApis::CommonsJavaScript::Converter convert(context);
136 //TODO Add checking NULL String 2011.09.15
138 if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_ADDITIONAL_INFORMATION)) {
139 LogDebug("propertyName: " << GEOCODER_ADDITIONAL_INFORMATION);
140 LogDebug("geocoderProperties->strAdditionalInformation:[" << geocoderProperties->strAdditionalInformation << "]");
141 retValue = convert.toJSValueRef(geocoderProperties->strAdditionalInformation);
142 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_CITY)) {
143 LogDebug("propertyName: " << GEOCODER_CITY);
144 LogDebug("geocoderProperties->strCity:[" << geocoderProperties->strCity << "]");
145 retValue = convert.toJSValueRef(geocoderProperties->strCity);
146 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_COUNTRY)) {
147 LogDebug("propertyName: " << GEOCODER_COUNTRY);
148 LogDebug("geocoderProperties->strCountryCode:[" << geocoderProperties->strCountry <<"]");
149 retValue = convert.toJSValueRef(geocoderProperties->strCountry);
150 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_COUNTY)) {
151 LogDebug("propertyName: " << GEOCODER_COUNTY);
152 LogDebug("geocoderProperties->strCounty:[" << geocoderProperties->strCounty << "]");
153 retValue = convert.toJSValueRef(geocoderProperties->strCounty);
154 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_POSTAL_CODE)) {
155 LogDebug("propertyName: " << GEOCODER_POSTAL_CODE);
156 LogDebug("geocoderProperties->strPostalCode:[" << geocoderProperties->strPostalCode << "]");
157 retValue = convert.toJSValueRef(geocoderProperties->strPostalCode);
158 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_PREMISES)) {
159 LogDebug("propertyName: " << GEOCODER_PREMISES);
160 LogDebug("geocoderProperties->strBuildingNumber:[" << geocoderProperties->strPremises << "]");
161 retValue = convert.toJSValueRef(geocoderProperties->strPremises);
162 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_REGION)) {
163 LogDebug("propertyName: " << GEOCODER_REGION);
164 LogDebug("geocoderProperties->strState:[" << geocoderProperties->strRegion << "]");
165 retValue = convert.toJSValueRef(geocoderProperties->strRegion);
166 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_STREET)) {
167 LogDebug("propertyName: " << GEOCODER_STREET);
168 LogDebug("geocoderProperties->strStreet:[" << geocoderProperties->strStreet << "]");
169 retValue = convert.toJSValueRef(geocoderProperties->strStreet);
170 } else if (JSStringIsEqualToUTF8CString(propertyName, GEOCODER_STREET_NUMBER)) {
171 LogDebug("propertyName: " << GEOCODER_STREET_NUMBER);
172 LogDebug("geocoderProperties->strStreetNumber:[" << geocoderProperties->strStreetNumber <<"]");
173 retValue = convert.toJSValueRef(geocoderProperties->strStreetNumber);
175 LogDebug(">>> make undefined");
176 return JSValueMakeUndefined(context);
181 }Catch (Commons::Exception){
182 LogError("Exception: " << _rethrown_exception.GetMessage());
188 bool JSAddress::hasInstance(JSContextRef context, JSObjectRef constructor,
189 JSValueRef possibleInstance, JSValueRef* exception) {
190 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());