Update change log and spec for wrt-plugins-tizen_0.4.13
[framework/web/wrt-plugins-tizen.git] / src / Tizen / JSFeature.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        JSFeature.cpp
20  * @author
21  * @version     0.1
22  * @brief
23  */
24
25 #include <dpl/log/log.h>
26 #include <CommonsJavaScript/PrivateObject.h>
27 #include <CommonsJavaScript/Converter.h>
28 #include "JSFeature.h"
29 #include "JSFeatureParam.h"
30
31
32 namespace DeviceAPI {
33 namespace Tizen {
34
35 namespace {
36     const char* PLUGIN_NAME = "Feature";
37     const char* ATTRIBUTE_URI = "uri";
38 }
39
40 JSClassDefinition JSFeature::m_classInfo =
41 {
42     0,
43     kJSClassAttributeNone,
44     PLUGIN_NAME,
45     0,
46     m_properties,
47     NULL, //m_functions,
48     initialize,
49     finalize,
50     NULL, //hasProperty,
51     NULL, //getProperty,
52     NULL, //setProperty,
53     NULL, //deleteProperty,
54     NULL, //getPropertyNames,
55     NULL,
56     NULL,
57     NULL, //hasInstance,
58     NULL  //convertToType
59 };
60
61 JSStaticValue JSFeature::m_properties[] = {
62     { ATTRIBUTE_URI, getProperty, NULL, kJSPropertyAttributeReadOnly },
63     { 0, 0, 0, 0 }
64 };
65
66 const JSClassDefinition* JSFeature::getClassInfo()
67 {
68     return &m_classInfo;
69 }
70
71 JSClassRef JSFeature::m_classRef = JSClassCreate(JSFeature::getClassInfo());
72
73 void JSFeature::initialize(JSContextRef context, JSObjectRef object)
74 {
75     //LogDebug("entered");
76     //private object should be passed to JSObjectMake function.
77     //Nothing to do here.
78 }
79
80 void JSFeature::finalize(JSObjectRef object)
81 {
82     LogDebug("entered");
83     JSFeaturePrivateObject* priv =
84             static_cast<JSFeaturePrivateObject*>(JSObjectGetPrivate(object));
85     delete priv;
86 }
87
88 JSClassRef JSFeature::getClassRef()
89 {
90     if (!m_classRef) {
91         m_classRef = JSClassCreate(&m_classInfo);
92     }
93     return m_classRef;
94 }
95
96 JSValueRef JSFeature::getProperty(JSContextRef context, JSObjectRef object,
97         JSStringRef propertyName, JSValueRef* exception)
98 {
99     LogDebug("entered");
100     JSFeaturePrivateObject* priv =
101         static_cast<JSFeaturePrivateObject*>(JSObjectGetPrivate(object));
102     if (!priv) {
103         LogError("no private object");
104         return JSValueMakeUndefined(context);
105     }
106     Try
107     {
108         WrtDeviceApis::CommonsJavaScript::Converter converter(context);
109         if (JSStringIsEqualToUTF8CString(propertyName, ATTRIBUTE_URI)) {
110             return converter.toJSValueRef(priv->getObject()->getName() );
111         }
112     }
113     Catch(WrtDeviceApis::Commons::Exception)
114     {
115         LogError("error during conversion");
116     }
117     return JSValueMakeUndefined(context);
118 }
119
120 } // Tizen
121 } // DeviceAPI
122