3 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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.
21 #include "JSCpuInfo.h"
25 using namespace WrtDeviceApis::CommonsJavaScript;
26 using namespace WrtDeviceApis::Commons;
27 using namespace Api::Systeminfo;
30 const char* CPU_LOAD_PROPERTY = "load";
33 JSClassRef JSCpuInfo::m_classRef = NULL;
35 JSClassDefinition JSCpuInfo::m_classInfo = {
37 kJSClassAttributeNone,
55 JSStaticValue JSCpuInfo::m_properties[] = {
56 { CPU_LOAD_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
60 const JSClassRef JSCpuInfo::getClassRef()
63 m_classRef = JSClassCreate(&m_classInfo);
68 const JSClassDefinition* JSCpuInfo::getClassInfo()
73 void JSCpuInfo::Initialize(JSContextRef context, JSObjectRef object)
77 void JSCpuInfo::Finalize(JSObjectRef object)
80 JSCpuPriv* priv = static_cast<JSCpuPriv*>(JSObjectGetPrivate(object));
81 JSObjectSetPrivate(object, NULL);
82 LogDebug("Deleting CpuInfo object");
86 bool JSCpuInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
88 return JSUtils::hasProperty(m_properties, propertyName);
91 JSObjectRef JSCpuInfo::createJSObject(JSContextRef context, const Api::Systeminfo::CpuProperties &cpuInfo)
94 std::auto_ptr<Api::Systeminfo::CpuProperties> accProps(new Api::Systeminfo::CpuProperties(cpuInfo));
95 JSCpuPriv *priv = new JSCpuPriv(context, accProps.get());
97 return JSObjectMake(context, getClassRef(), priv);
100 JSValueRef JSCpuInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
103 JSCpuPriv *priv = static_cast<JSCpuPriv*>(JSObjectGetPrivate(object));
105 LogError("Private object not set.");
106 return JSValueMakeUndefined(context);
111 Api::Systeminfo::CpuProperties *cpuInfo = priv->getObject();
112 Converter convert(context);
114 if (JSStringIsEqualToUTF8CString(propertyName, CPU_LOAD_PROPERTY)) {
115 return convert.toJSValueRef(cpuInfo->load);
120 LogError("Exception: " << _rethrown_exception.GetMessage());
122 return JSValueMakeUndefined(context);