2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "JSBuildInfo.h"
23 namespace Systeminfo {
24 using namespace WrtDeviceApis::CommonsJavaScript;
25 using namespace WrtDeviceApis::Commons;
28 const char* BUILD_MODEL_PROPERTY = "model";
29 const char* BUILD_MANUFACTURER_PROPERTY = "manufacturer";
33 JSClassRef JSBuildInfo::m_classRef = NULL;
35 JSClassDefinition JSBuildInfo::m_classInfo = {
37 kJSClassAttributeNone,
55 JSStaticValue JSBuildInfo::m_properties[] = {
56 { BUILD_MODEL_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
57 { BUILD_MANUFACTURER_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
61 const JSClassRef JSBuildInfo::getClassRef()
64 m_classRef = JSClassCreate(&m_classInfo);
69 const JSClassDefinition* JSBuildInfo::getClassInfo()
74 void JSBuildInfo::Initialize(JSContextRef context, JSObjectRef object)
78 void JSBuildInfo::Finalize(JSObjectRef object)
81 JSBuildPriv* priv = static_cast<JSBuildPriv*>(JSObjectGetPrivate(object));
82 JSObjectSetPrivate(object, NULL);
83 LoggerD("Deleting buildInfo object");
87 bool JSBuildInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
89 return JSUtils::hasProperty(m_properties, propertyName);
92 JSObjectRef JSBuildInfo::createJSObject(JSContextRef context, const BuildPropertiesPtr buildInfo)
94 JSBuildPriv *priv = new JSBuildPriv(context, buildInfo);
95 return JSObjectMake(context, getClassRef(), priv);
98 JSValueRef JSBuildInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
101 JSBuildPriv *priv = static_cast<JSBuildPriv*>(JSObjectGetPrivate(object));
103 LoggerE("Private object not set.");
104 return JSValueMakeUndefined(context);
109 BuildPropertiesPtr buildInfo = priv->getObject();
110 Converter convert(context);
112 if (JSStringIsEqualToUTF8CString(propertyName, BUILD_MODEL_PROPERTY)) {
113 return convert.toJSValueRef(buildInfo->model);
114 } else if (JSStringIsEqualToUTF8CString(propertyName, BUILD_MANUFACTURER_PROPERTY)) {
115 return convert.toJSValueRef(buildInfo->manufacturer);
120 LoggerE("Exception: " << _rethrown_exception.GetMessage());
122 return JSValueMakeUndefined(context);