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 "JSStorageInfo.h"
23 namespace Systeminfo {
24 using namespace WrtDeviceApis::CommonsJavaScript;
25 using namespace WrtDeviceApis::Commons;
28 const char* STORAGE_TYPE_PROPERTY = "type";
29 const char* STORAGE_CAPACITY_PROPERTY = "capacity";
30 const char* STORAGE_AVAILCAPA_PROPERTY = "availableCapacity";
31 const char* STORAGE_REMOVEABLE_PROPERTY = "isRemoveable";
32 const char* STORAGE_REMOVABLE_PROPERTY = "isRemovable";
35 JSClassRef JSStorageInfo::m_classRef = NULL;
37 JSClassDefinition JSStorageInfo::m_classInfo = {
39 kJSClassAttributeNone,
57 JSStaticValue JSStorageInfo::m_properties[] = {
58 { STORAGE_TYPE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
59 { STORAGE_CAPACITY_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
60 { STORAGE_AVAILCAPA_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
61 { STORAGE_REMOVEABLE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
62 { STORAGE_REMOVABLE_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 LoggerD("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 StoragePropertiesPtr storageInfo)
99 JSStoragePriv *priv = new JSStoragePriv(context, storageInfo);
100 return JSObjectMake(context, getClassRef(), priv);
103 JSValueRef JSStorageInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
106 JSStoragePriv *priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
108 LoggerE("Private object not set.");
109 return JSValueMakeUndefined(context);
114 StoragePropertiesPtr storageInfo = priv->getObject();
115 Converter convert(context);
116 if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_TYPE_PROPERTY)) {
117 return convert.toJSValueRef(storageInfo->type);
118 } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_CAPACITY_PROPERTY)) {
119 return JSValueMakeNumber(context, storageInfo->capacity);
120 } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_AVAILCAPA_PROPERTY)) {
121 return JSValueMakeNumber(context, storageInfo->availableCapacity);
122 } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_REMOVEABLE_PROPERTY)) {
123 return convert.toJSValueRef(storageInfo->isRemoveable);
124 } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_REMOVABLE_PROPERTY)) {
125 return convert.toJSValueRef(storageInfo->isRemovable);
130 LoggerE("Exception: " << _rethrown_exception.GetMessage());
132 return JSValueMakeUndefined(context);