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.
17 #include <CommonsJavaScript/Converter.h>
18 #include <CommonsJavaScript/Validator.h>
19 #include <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
21 #include <PluginManager/IPluginManager.h>
22 #include <Commons/WrtAccess/WrtAccess.h>
23 #include <WidgetDB/WidgetDBMgr.h>
24 #include <WidgetDB/IWidgetDB.h>
25 #include <PluginManager/PluginManagerFactory.h>
35 #define LOG_TAG "TIZEN_LBS"
38 using namespace WrtDeviceApis;
39 using namespace WrtDeviceApis::Commons;
40 using namespace WrtDeviceApis::PluginManager::Api;
42 bool initGeocoder = false;
43 bool initRoute = false;
50 JSContextRef JSLBS::m_globalContextRef = NULL;
51 JSClassRef JSLBS::m_jsClassRef = NULL;
53 JSClassDefinition JSLBS::m_jsClassInfo = {
55 kJSClassAttributeNone,
65 NULL, //deleteProperty
66 getPropertyNames, //getPropertyNames
73 JSStaticValue JSLBS::m_properties[] = {
77 const JSClassRef JSLBS::getClassRef()
80 m_jsClassRef = JSClassCreate(&m_jsClassInfo);
85 const JSClassDefinition* JSLBS::getClassInfo()
88 return &m_jsClassInfo;
91 JSContextRef JSLBS::getGlobalContext()
93 return JSLBS::m_globalContextRef;
96 void JSLBS::initialize(JSContextRef ctx, JSObjectRef object)
99 JSLBS::m_globalContextRef = ctx;
101 int widgetId = WrtAccessSingleton::Instance().getWidgetId();
102 LBS *priv = new LBS(PluginManagerFactory::getInstance().getPluginManager(widgetId, "tizen.lbs", object, ctx));
103 JSObjectSetPrivate(object, priv);
106 void JSLBS::finalize(JSObjectRef object)
108 LOGE("%s", __func__);
110 LBS *priv = (LBS*)JSObjectGetPrivate(object);
117 bool JSLBS::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
118 LOGE("%s", __func__);
119 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
122 bool JSLBS::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
124 LOGE("%s", __func__);
125 LBS *priv = (LBS*)JSObjectGetPrivate(object);
126 return priv->getPluginManager()->hasChild(CommonsJavaScript::Converter(context).toString(propertyName));
129 JSValueRef JSLBS::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
131 LOGE("%s", __func__);
132 LBS *priv = (LBS*)JSObjectGetPrivate(object);
133 return priv->getPluginManager()->getProperty(CommonsJavaScript::Converter(context).toString(propertyName));
136 bool JSLBS::setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
138 LOGE("%s", __func__);
139 LBS *priv = (LBS*)JSObjectGetPrivate(object);
141 std::string name = CommonsJavaScript::Converter(context).toString(propertyName);
143 if((name == "geocoder" && initGeocoder) || (name == "route" && initRoute) || (name == "poi" && initPOI))
145 LOGD("PluginManager::setProperty is done !! ");
146 initGeocoder = false;
149 return priv->getPluginManager()->setProperty(CommonsJavaScript::Converter(context).toString(propertyName),value);
155 void JSLBS::getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
157 LOGE("%s", __func__);
158 LBS *priv = (LBS*)JSObjectGetPrivate(object);
159 priv->getPluginManager()->addPropertiesToList(propertyNames);