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 "JSStorageInfo.h"
25 using namespace WrtDeviceApis::CommonsJavaScript;
26 using namespace WrtDeviceApis::Commons;
27 using namespace Api::Systeminfo;
30 const char* STORAGE_TYPE_PROPERTY = "type";
31 const char* STORAGE_CAPACITY_PROPERTY = "capacity";
32 const char* STORAGE_AVAILCAPA_PROPERTY = "availableCapacity";
33 const char* STORAGE_REMOVEABLE_PROPERTY = "isRemoveable";
36 JSClassRef JSStorageInfo::m_classRef = NULL;
38 JSClassDefinition JSStorageInfo::m_classInfo = {
40 kJSClassAttributeNone,
58 JSStaticValue JSStorageInfo::m_properties[] = {
59 { STORAGE_TYPE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
60 { STORAGE_CAPACITY_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
61 { STORAGE_AVAILCAPA_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
62 { STORAGE_REMOVEABLE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
66 const JSClassRef JSStorageInfo::getClassRef()
69 m_classRef = JSClassCreate(&m_classInfo);
74 const JSClassDefinition* JSStorageInfo::getClassInfo()
79 void JSStorageInfo::Initialize(JSContextRef context, JSObjectRef object)
83 void JSStorageInfo::Finalize(JSObjectRef object)
86 JSStoragePriv* priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
87 JSObjectSetPrivate(object, NULL);
88 LogDebug("Deleting StorageInfo object");
92 bool JSStorageInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
94 return JSUtils::hasProperty(m_properties, propertyName);
97 JSObjectRef JSStorageInfo::createJSObject(JSContextRef context, const Api::Systeminfo::StorageProperties &storageInfo)
99 std::auto_ptr<Api::Systeminfo::StorageProperties> accProps(new Api::Systeminfo::StorageProperties(storageInfo));
100 JSStoragePriv *priv = new JSStoragePriv(context, accProps.get());
102 return JSObjectMake(context, getClassRef(), priv);
105 JSValueRef JSStorageInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
108 JSStoragePriv *priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
110 LogError("Private object not set.");
111 return JSValueMakeUndefined(context);
116 Api::Systeminfo::StorageProperties *storageInfo = priv->getObject();
117 Converter convert(context);
118 if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_TYPE_PROPERTY)) {
119 return convert.toJSValueRef(storageInfo->type);
120 } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_CAPACITY_PROPERTY)) {
121 return convert.toJSValueRef(storageInfo->capacity);
122 } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_AVAILCAPA_PROPERTY)) {
123 return convert.toJSValueRef(storageInfo->availableCapacity);
124 } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_REMOVEABLE_PROPERTY)) {
125 return convert.toJSValueRef(storageInfo->isRemoveable);
130 LogError("Exception: " << _rethrown_exception.GetMessage());
132 return JSValueMakeUndefined(context);