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 "JSPeripheralInfo.h"
23 namespace Systeminfo {
24 using namespace WrtDeviceApis::CommonsJavaScript;
25 using namespace WrtDeviceApis::Commons;
28 const char* PERIPHERAL_IS_VIDEO_OUTPUT_ON_PROPERTY = "isVideoOutputOn";
31 JSClassRef JSPeripheralInfo::m_classRef = NULL;
33 JSClassDefinition JSPeripheralInfo::m_classInfo = {
35 kJSClassAttributeNone,
53 JSStaticValue JSPeripheralInfo::m_properties[] = {
54 { PERIPHERAL_IS_VIDEO_OUTPUT_ON_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
58 const JSClassRef JSPeripheralInfo::getClassRef()
61 m_classRef = JSClassCreate(&m_classInfo);
66 const JSClassDefinition* JSPeripheralInfo::getClassInfo()
71 void JSPeripheralInfo::Initialize(JSContextRef context, JSObjectRef object)
75 void JSPeripheralInfo::Finalize(JSObjectRef object)
78 JSPeripheralPriv* priv = static_cast<JSPeripheralPriv*>(JSObjectGetPrivate(object));
79 JSObjectSetPrivate(object, NULL);
80 LoggerD("Deleting peripheralInfo object");
84 bool JSPeripheralInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
86 return JSUtils::hasProperty(m_properties, propertyName);
89 JSObjectRef JSPeripheralInfo::createJSObject(JSContextRef context, const PeripheralPropertiesPtr peripheralInfo)
91 JSPeripheralPriv *priv = new JSPeripheralPriv(context, peripheralInfo);
92 return JSObjectMake(context, getClassRef(), priv);
95 JSValueRef JSPeripheralInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
98 JSPeripheralPriv *priv = static_cast<JSPeripheralPriv*>(JSObjectGetPrivate(object));
100 LoggerE("Private object not set.");
101 return JSValueMakeUndefined(context);
106 PeripheralPropertiesPtr peripheralInfo = priv->getObject();
107 Converter convert(context);
109 if (JSStringIsEqualToUTF8CString(propertyName, PERIPHERAL_IS_VIDEO_OUTPUT_ON_PROPERTY)) {
110 return convert.toJSValueRef(peripheralInfo->isVideoOutputOn);
115 LoggerE("Exception: " << _rethrown_exception.GetMessage());
117 return JSValueMakeUndefined(context);