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 "JSDisplayInfo.h"
25 using namespace WrtDeviceApis::CommonsJavaScript;
26 using namespace WrtDeviceApis::Commons;
27 using namespace Api::Systeminfo;
30 const char* DISPLAY_RESOLUTIONW_PROPERTY = "resolutionWidth";
31 const char* DISPLAY_RESOLUTIONH_PROPERTY = "resolutionHeight";
32 const char* DISPLAY_INCHW_PROPERTY = "dotsPerInchWidth";
33 const char* DISPLAY_INCHH_PROPERTY = "dotsPerInchHeight";
34 const char* DISPLAY_PHYSICALW_PROPERTY = "physicalWidth";
35 const char* DISPLAY_PHYSICALH_PROPERTY = "physicalHeight";
36 const char* DISPLAY_BRIGHTNESS_PROPERTY = "brightness";
39 JSClassRef JSDisplayInfo::m_classRef = NULL;
41 JSClassDefinition JSDisplayInfo::m_classInfo = {
43 kJSClassAttributeNone,
61 JSStaticValue JSDisplayInfo::m_properties[] = {
62 { DISPLAY_RESOLUTIONW_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
63 { DISPLAY_RESOLUTIONH_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
64 { DISPLAY_INCHW_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
65 { DISPLAY_INCHH_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
66 { DISPLAY_PHYSICALW_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
67 { DISPLAY_PHYSICALH_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
68 { DISPLAY_BRIGHTNESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
72 const JSClassRef JSDisplayInfo::getClassRef()
75 m_classRef = JSClassCreate(&m_classInfo);
80 const JSClassDefinition* JSDisplayInfo::getClassInfo()
85 void JSDisplayInfo::Initialize(JSContextRef context, JSObjectRef object)
89 void JSDisplayInfo::Finalize(JSObjectRef object)
92 JSDisplayPriv* priv = static_cast<JSDisplayPriv*>(JSObjectGetPrivate(object));
93 JSObjectSetPrivate(object, NULL);
94 LogDebug("Deleting DisplayInfo object");
98 bool JSDisplayInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
100 return JSUtils::hasProperty(m_properties, propertyName);
103 JSObjectRef JSDisplayInfo::createJSObject(JSContextRef context, const Api::Systeminfo::DisplayProperties &displayInfo)
105 std::auto_ptr<Api::Systeminfo::DisplayProperties> accProps(new Api::Systeminfo::DisplayProperties(displayInfo));
106 JSDisplayPriv *priv = new JSDisplayPriv(context, accProps.get());
108 return JSObjectMake(context, getClassRef(), priv);
111 JSValueRef JSDisplayInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
114 JSDisplayPriv *priv = static_cast<JSDisplayPriv*>(JSObjectGetPrivate(object));
116 LogError("Private object not set.");
117 return JSValueMakeUndefined(context);
122 Api::Systeminfo::DisplayProperties *displayInfo = priv->getObject();
123 Converter convert(context);
124 if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_RESOLUTIONW_PROPERTY)) {
125 return convert.toJSValueRef(displayInfo->resolutionWidth);
126 } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_RESOLUTIONH_PROPERTY)) {
127 return convert.toJSValueRef(displayInfo->resolutionHeight);
128 } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_INCHW_PROPERTY)) {
129 return convert.toJSValueRef(displayInfo->dotsPerInchWidth);
130 } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_INCHH_PROPERTY)) {
131 return convert.toJSValueRef(displayInfo->dotsPerInchHeight);
132 } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_PHYSICALW_PROPERTY)) {
133 return convert.toJSValueRef(displayInfo->physicalWidth);
134 } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_PHYSICALH_PROPERTY)) {
135 return convert.toJSValueRef(displayInfo->physicalHeight);
136 } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_BRIGHTNESS_PROPERTY)) {
137 return convert.toJSValueRef(displayInfo->brightness);
142 LogError("Exception: " << _rethrown_exception.GetMessage());
144 return JSValueMakeUndefined(context);