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 "JSSystemInfoDeviceOrientation.h"
26 namespace SystemInfo {
28 using namespace DeviceAPI::Common;
30 struct SystemInfoDeviceOrientationHolder {
31 SystemInfoDeviceOrientationPtr ptr;
35 const char* SYSTEMINFO_SYSTEMINFO_DEVICE_ORIENTATION = "SystemInfoDeviceOrientation";
37 const char* SYSTEMINFO_DEVICE_ORIENTATION_STATUS = "status";
38 const char* SYSTEMINFO_DEVICE_ORIENTATION_IS_AUTO_ROTATION = "isAutoRotation";
41 JSClassDefinition JSSystemInfoDeviceOrientation::m_classInfo = {
42 0, // current (and only) version is 0
43 kJSClassAttributeNone, //attributes
44 SYSTEMINFO_SYSTEMINFO_DEVICE_ORIENTATION, //class name
45 JSSystemInfoProperty::getClassRef(), // parent class
53 NULL, //deleteProperty,
54 NULL, //getPropertyNames,
61 JSStaticValue JSSystemInfoDeviceOrientation::m_property[] = {
62 { SYSTEMINFO_DEVICE_ORIENTATION_STATUS, getStatus, NULL,
63 kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
64 { SYSTEMINFO_DEVICE_ORIENTATION_IS_AUTO_ROTATION, isAutoRotation, NULL,
65 kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
69 const JSClassDefinition* JSSystemInfoDeviceOrientation::getClassInfo()
74 JSClassRef JSSystemInfoDeviceOrientation::m_jsClassRef =
75 JSClassCreate(JSSystemInfoDeviceOrientation::getClassInfo());
77 JSClassRef DLL_EXPORT JSSystemInfoDeviceOrientation::getClassRef()
80 m_jsClassRef = JSClassCreate(&m_classInfo);
85 SystemInfoDeviceOrientationPtr JSSystemInfoDeviceOrientation::getPrivateObject(
89 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
90 LOGE("Type mismatch");
91 throw TypeMismatchException("Type mismatch");
94 JSObjectRef object = JSUtil::JSValueToObject(context, value);
95 SystemInfoDeviceOrientationHolder* priv =
96 static_cast<SystemInfoDeviceOrientationHolder*>(JSObjectGetPrivate(object));
98 LOGE("Holder is null");
99 throw UnknownException("Holder is null");
102 LOGE("Priv is null");
103 throw UnknownException("Priv is null");
108 void JSSystemInfoDeviceOrientation::setPrivateObject(JSObjectRef object,
109 SystemInfoDeviceOrientationPtr native)
111 SystemInfoDeviceOrientationHolder* priv =
112 static_cast<SystemInfoDeviceOrientationHolder*>(JSObjectGetPrivate(object));
114 LOGE("Holder is null");
115 throw UnknownException("Holder is null");
120 JSObjectRef JSSystemInfoDeviceOrientation::makeJSObject(JSContextRef context,
121 SystemInfoPropertyPtr native)
124 LOGE("NULL pointer to SystemInfoDeviceOrientation given");
125 throw UnknownException("NULL pointer to SystemInfoDeviceOrientation given");
128 SystemInfoDeviceOrientationPtr orientation =
129 std::dynamic_pointer_cast<SystemInfoDeviceOrientation>(native);
132 LOGE("Invalid pointer to SystemInfoDeviceOrientation given");
133 throw UnknownException("Invalid pointer to SystemInfoDeviceOrientation given");
136 SystemInfoDeviceOrientationHolder* priv =
137 new(std::nothrow) SystemInfoDeviceOrientationHolder();
139 LOGE("Failed to allocate memory");
140 throw UnknownException("Failed to allocate memory");
142 priv->ptr = orientation;
144 JSObjectRef obj = JSObjectMake(context, getClassRef(),
145 static_cast<void*>(priv));
149 void JSSystemInfoDeviceOrientation::initialize(JSContextRef context, JSObjectRef object)
154 void JSSystemInfoDeviceOrientation::finalize(JSObjectRef object)
157 SystemInfoDeviceOrientationHolder* priv =
158 static_cast<SystemInfoDeviceOrientationHolder*>(JSObjectGetPrivate(object));
160 JSObjectSetPrivate(object, NULL);
166 JSValueRef JSSystemInfoDeviceOrientation::getStatus(JSContextRef context,
168 JSStringRef property_name,
169 JSValueRef* exception)
173 SystemInfoDeviceOrientationPtr priv = getPrivateObject(context, object);
175 return JSUtil::toJSValueRef(context, priv->getStatus());
177 catch (const BasePlatformException &err) {
178 LOGE("Exception caught: name: %s, msg: %s",
179 err.getName().c_str(), err.getMessage().c_str());
182 LOGE("getStatus failed");
184 return JSValueMakeUndefined(context);
187 JSValueRef JSSystemInfoDeviceOrientation::isAutoRotation(JSContextRef context,
189 JSStringRef property_name,
190 JSValueRef* exception)
194 SystemInfoDeviceOrientationPtr priv = getPrivateObject(context, object);
196 return JSUtil::toJSValueRef(context, priv->isAutoRotation());
198 catch (const BasePlatformException &err) {
199 LOGE("Exception caught: name: %s, msg: %s",
200 err.getName().c_str(), err.getMessage().c_str());
203 LOGE("isAutoRotation failed");
205 return JSValueMakeUndefined(context);