2 // Tizen Web Device API
3 // Copyright (c) 2012-2013 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.
18 #include "JSSystemInfoProperty.h"
19 #include "JSSystemInfoPeripheral.h"
23 #include <PlatformException.h>
27 namespace SystemInfo {
29 struct SystemInfoPeripheralHolder {
30 SystemInfoPeripheralPtr ptr;
34 const char* SYSTEMINFO_SYSTEMINFO_PERIPHERAL = "SystemInfoPeripheral";
35 const char* SYSTEMINFO_SYSTEMINFO_IS_VIDEO_OUTPUT_ON = "isVideoOutputOn";
38 JSClassDefinition JSSystemInfoPeripheral::m_classInfo = {
39 0, // current (and only) version is 0
40 kJSClassAttributeNone, //attributes
41 SYSTEMINFO_SYSTEMINFO_PERIPHERAL, //class name
42 JSSystemInfoProperty::getClassRef(), // parent class
50 NULL, //deleteProperty,
51 NULL, //getPropertyNames,
58 JSStaticValue JSSystemInfoPeripheral::m_property[] = {
59 { SYSTEMINFO_SYSTEMINFO_IS_VIDEO_OUTPUT_ON, getIsVideoOutputOn, NULL,
60 kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
64 const JSClassDefinition* JSSystemInfoPeripheral::getClassInfo()
69 JSClassRef JSSystemInfoPeripheral::m_jsClassRef =
70 JSClassCreate(JSSystemInfoPeripheral::getClassInfo());
72 JSClassRef DLL_EXPORT JSSystemInfoPeripheral::getClassRef()
75 m_jsClassRef = JSClassCreate(&m_classInfo);
80 SystemInfoPeripheralPtr JSSystemInfoPeripheral::getPrivateObject(JSContextRef context,
83 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
84 LOGE("Type mismatch");
85 throw Common::TypeMismatchException("Type mismatch");
88 JSObjectRef object = Common::JSUtil::JSValueToObject(context, value);
89 SystemInfoPeripheralHolder* priv =
90 static_cast<SystemInfoPeripheralHolder*>(JSObjectGetPrivate(object));
92 LOGE("Holder is null");
93 throw Common::UnknownException("Holder is null");
97 throw Common::UnknownException("Priv is null");
102 void JSSystemInfoPeripheral::setPrivateObject(JSObjectRef object,
103 SystemInfoPeripheralPtr native)
105 SystemInfoPeripheralHolder* priv =
106 static_cast<SystemInfoPeripheralHolder*>(JSObjectGetPrivate(object));
108 LOGE("Holder is null");
109 throw Common::UnknownException("Holder is null");
114 JSObjectRef JSSystemInfoPeripheral::makeJSObject(JSContextRef context,
115 SystemInfoPropertyPtr native)
118 LOGE("NULL pointer to SystemInfoPeripheral given");
119 throw Common::UnknownException("NULL pointer to SystemInfoPeripheral given");
122 SystemInfoPeripheralPtr peripheral =
123 std::dynamic_pointer_cast<SystemInfoPeripheral>(native);
126 LOGE("Invalid pointer to SystemInfoPeripheral given");
127 throw Common::UnknownException("Invalid pointer to SystemInfoPeripheral given");
130 SystemInfoPeripheralHolder* priv = new(std::nothrow) SystemInfoPeripheralHolder();
132 LOGE("Failed to allocate memory");
133 throw Common::UnknownException("Failed to allocate memory");
135 priv->ptr = peripheral;
137 JSObjectRef obj = JSObjectMake(context, getClassRef(),
138 static_cast<void*>(priv));
142 void JSSystemInfoPeripheral::initialize(JSContextRef context, JSObjectRef object)
147 void JSSystemInfoPeripheral::finalize(JSObjectRef object)
150 SystemInfoPeripheralHolder* priv =
151 static_cast<SystemInfoPeripheralHolder*>(JSObjectGetPrivate(object));
153 JSObjectSetPrivate(object, NULL);
159 JSValueRef JSSystemInfoPeripheral::getIsVideoOutputOn(JSContextRef context,
161 JSStringRef property_name,
162 JSValueRef* exception)
166 SystemInfoPeripheralPtr priv = getPrivateObject(context, object);
168 return Common::JSUtil::toJSValueRef(context, priv->isVideoOutputOn());
170 catch (const Common::BasePlatformException &err) {
171 LOGE("Exception caught: name: %s, msg: %s",
172 err.getName().c_str(), err.getMessage().c_str());
175 LOGE("getIsVideoOutputOn fails");
177 return JSValueMakeUndefined(context);