Update change log and spec for wrt-plugins-tizen_0.2.72
[framework/web/wrt-plugins-tizen.git] / src / standards / Tizen / LBS / JSLBS.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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. 
15  */
16  
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>
26 #include <dlog.h>
27 #include "LBS.h"
28
29
30 #include "JSLBS.h"
31
32 #include <dlog.h>
33
34 #undef LOG_TAG
35 #define LOG_TAG "TIZEN_LBS"
36
37 using namespace std;
38 using namespace WrtDeviceApis;
39 using namespace WrtDeviceApis::Commons;
40 using namespace WrtDeviceApis::PluginManager::Api;
41
42 bool initGeocoder = false;
43 bool initRoute = false;
44 bool initPOI = false;
45
46 namespace TizenApis {
47 namespace Tizen1_0 {
48 namespace LBS {
49
50 JSContextRef JSLBS::m_globalContextRef = NULL;
51 JSClassRef JSLBS::m_jsClassRef = NULL;
52
53 JSClassDefinition JSLBS::m_jsClassInfo = {
54         0,
55         kJSClassAttributeNone,
56         "LBS",
57         NULL,
58         m_properties,
59         NULL,
60         initialize,
61         finalize,
62     hasProperty,
63     getProperty,
64     setProperty,
65         NULL, //deleteProperty
66         getPropertyNames, //getPropertyNames
67         NULL,
68         NULL, // constructor
69         hasInstance,
70         NULL
71 };
72
73 JSStaticValue JSLBS::m_properties[] = {
74     { 0, 0, 0 }
75 };
76
77 const JSClassRef JSLBS::getClassRef() 
78 {
79         if (!m_jsClassRef) {
80                 m_jsClassRef = JSClassCreate(&m_jsClassInfo);
81         }
82         return m_jsClassRef;
83 }
84
85 const JSClassDefinition* JSLBS::getClassInfo() 
86 {
87         LOGE("%s", __func__);
88         return &m_jsClassInfo;
89 }
90
91 JSContextRef JSLBS::getGlobalContext()
92 {
93         return JSLBS::m_globalContextRef;
94 }
95
96 void JSLBS::initialize(JSContextRef ctx, JSObjectRef object)
97 {
98         LOGE("%s", __func__);
99         JSLBS::m_globalContextRef = ctx;
100
101     int widgetId = WrtAccessSingleton::Instance().getWidgetId();
102         LBS *priv = new LBS(PluginManagerFactory::getInstance().getPluginManager(widgetId, "tizen.lbs", object, ctx));
103         JSObjectSetPrivate(object, priv);
104 }
105
106 void JSLBS::finalize(JSObjectRef object)
107 {
108         LOGE("%s", __func__);
109
110         LBS *priv = (LBS*)JSObjectGetPrivate(object);
111         if( priv )
112                 delete priv;
113 }
114
115
116
117 bool JSLBS::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
118         LOGE("%s", __func__);
119         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
120 }
121
122 bool JSLBS::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
123 {
124         LOGE("%s", __func__);
125         LBS *priv = (LBS*)JSObjectGetPrivate(object);
126         return priv->getPluginManager()->hasChild(CommonsJavaScript::Converter(context).toString(propertyName));
127 }
128
129 JSValueRef JSLBS::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
130 {
131         LOGE("%s", __func__);
132         LBS *priv = (LBS*)JSObjectGetPrivate(object);
133         return priv->getPluginManager()->getProperty(CommonsJavaScript::Converter(context).toString(propertyName));
134 }
135
136 bool JSLBS::setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
137 {
138     LOGE("%s", __func__);
139         LBS *priv = (LBS*)JSObjectGetPrivate(object);
140
141         std::string name = CommonsJavaScript::Converter(context).toString(propertyName);
142
143         if((name == "geocoder" && initGeocoder) || (name == "route" && initRoute) || (name == "poi" && initPOI))
144         {
145                 LOGD("PluginManager::setProperty is done !! ");
146                 initGeocoder = false;
147                 initRoute = false;
148                 initPOI = false;
149                 return priv->getPluginManager()->setProperty(CommonsJavaScript::Converter(context).toString(propertyName),value);
150         }
151
152         return true;
153 }
154
155 void JSLBS::getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
156 {
157         LOGE("%s", __func__);
158         LBS *priv = (LBS*)JSObjectGetPrivate(object);
159         priv->getPluginManager()->addPropertiesToList(propertyNames);
160 }
161
162
163
164 } //LBS
165 } // Tizen1_0
166 } // TizenApis
167