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.
21 #include "JSSystemInfoBuild.h"
22 #include "JSSystemInfoProperty.h"
23 #include "PlatformException.h"
26 namespace SystemInfo {
28 struct SystemInfoBuildHolder {
29 SystemInfoBuildPtr ptr;
33 const char* SYSTEMINFO_SYSTEMINFO_BUILD = "SystemInfoBuild";
34 const char* SYSTEMINFO_MODEL = "model";
35 const char* SYSTEMINFO_MANUFACTURER = "manufacturer";
36 const char* SYSTEMINFO_BUILDVERSION = "buildVersion";
39 JSClassDefinition JSSystemInfoBuild::m_classInfo = {
40 0, // current (and only) version is 0
41 kJSClassAttributeNone, //attributes
42 SYSTEMINFO_SYSTEMINFO_BUILD, //class name
43 JSSystemInfoProperty::getClassRef(), // parent class
51 NULL, //deleteProperty,
52 NULL, //getPropertyNames,
59 JSStaticValue JSSystemInfoBuild::m_property[] = {
60 { SYSTEMINFO_MODEL, getModel, NULL,
61 kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
62 { SYSTEMINFO_MANUFACTURER, getManufacturer, NULL,
63 kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
64 { SYSTEMINFO_BUILDVERSION, getBuildVersion, NULL,
65 kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
69 const JSClassDefinition* JSSystemInfoBuild::getClassInfo()
74 JSClassRef JSSystemInfoBuild::m_jsClassRef =
75 JSClassCreate(JSSystemInfoBuild::getClassInfo());
77 SystemInfoBuildPtr JSSystemInfoBuild::getPrivateObject(JSContextRef context,
80 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
81 LOGE("Type mismatch");
82 throw Common::TypeMismatchException("Type mismatch");
85 JSObjectRef object = Common::JSUtil::JSValueToObject(context, value);
86 SystemInfoBuildHolder* priv =
87 static_cast< SystemInfoBuildHolder* >(JSObjectGetPrivate(object));
89 LOGE("Holder is null");
90 throw Common::UnknownException("Holder is null");
94 throw Common::UnknownException("Priv is null");
99 JSClassRef DLL_EXPORT JSSystemInfoBuild::getClassRef()
102 m_jsClassRef = JSClassCreate(&m_classInfo);
107 void JSSystemInfoBuild::setPrivateObject(JSObjectRef object,
108 SystemInfoBuildPtr native)
110 SystemInfoBuildHolder* priv =
111 static_cast< SystemInfoBuildHolder* >(JSObjectGetPrivate(object));
113 LOGE("Holder is null");
114 throw Common::UnknownException("Holder is null");
119 JSObjectRef JSSystemInfoBuild::makeJSObject(JSContextRef context,
120 SystemInfoPropertyPtr native)
124 LOGE("NULL pointer to SystemInfoBuild given");
125 throw Common::UnknownException("NULL pointer to SystemInfoBuild given");
128 SystemInfoBuildPtr build = std::dynamic_pointer_cast<SystemInfoBuild>(
132 LOGE("Invalid pointer to SystemInfoBuild given");
133 throw Common::UnknownException("Invalid pointer to SystemInfoBuild given");
136 SystemInfoBuildHolder* priv = new(std::nothrow) SystemInfoBuildHolder();
138 LOGE("Failed to allocate memory");
139 throw Common::UnknownException("Failed to allocate memory");
143 JSObjectRef obj = JSObjectMake(context, getClassRef(),
144 static_cast< void* >(priv));
148 void JSSystemInfoBuild::initialize(JSContextRef context, JSObjectRef object)
153 void JSSystemInfoBuild::finalize(JSObjectRef object)
156 SystemInfoBuildHolder* priv =
157 static_cast< SystemInfoBuildHolder* >(JSObjectGetPrivate(object));
159 JSObjectSetPrivate(object, NULL);
165 JSValueRef JSSystemInfoBuild::getModel(JSContextRef context,
166 JSObjectRef object, JSStringRef property_name, JSValueRef* exception)
171 SystemInfoBuildPtr priv = getPrivateObject(context, object);
172 return Common::JSUtil::toJSValueRef(context, priv->getModel());
174 catch (const Common::BasePlatformException &err) {
175 LOGE("Exception caught: name: %s, msg: %s",
176 err.getName().c_str(), err.getMessage().c_str());
179 LOGE("getModel fails");
182 return JSValueMakeUndefined(context);
185 JSValueRef JSSystemInfoBuild::getManufacturer(JSContextRef context,
187 JSStringRef property_name,
188 JSValueRef* exception)
193 SystemInfoBuildPtr priv = getPrivateObject(context, object);
194 return Common::JSUtil::toJSValueRef(context, priv->getManufacturer());
196 catch (const Common::BasePlatformException &err) {
197 LOGE("Exception caught: name: %s, msg: %s",
198 err.getName().c_str(), err.getMessage().c_str());
201 LOGE("getManufacturer fails");
204 return JSValueMakeUndefined(context);
207 JSValueRef JSSystemInfoBuild::getBuildVersion(JSContextRef context,
209 JSStringRef property_name,
210 JSValueRef* exception)
215 SystemInfoBuildPtr priv = getPrivateObject(context, object);
216 return Common::JSUtil::toJSValueRef(context, priv->getBuildVersion());
218 catch (const Common::BasePlatformException &err) {
219 LOGE("Exception caught: name: %s, msg: %s",
220 err.getName().c_str(), err.getMessage().c_str());
223 LOGE("getBuildVersion fails");
226 return JSValueMakeUndefined(context);
229 } // namespace SystemInfo