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.
21 #include <CommonsJavaScript/JSUtils.h>
22 //#include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
24 #include "StorageProperties.h"
25 #include "JSStorage.h"
26 #include "Converter.h"
30 namespace Filesystem {
32 using namespace WrtDeviceApis;
33 using namespace WrtDeviceApis::Commons;
34 using namespace WrtDeviceApis::CommonsJavaScript;
37 const char* STR_STORAGE_LABEL = "label";
38 const char* STR_STORAGE_TYPE = "type";
39 const char* STR_STORAGE_STATE = "state";
40 /*const char* STR_TYPE_INTERNAL = "INTERNAL";
41 const char* STR_TYPE_EXTERNAL = "EXTERNAL";
42 const char* STR_STATE_MOUNTED = "MOUNTED";
43 const char* STR_STATE_REMOVED = "REMOVED";
44 const char* STR_STATE_UNMOUNTABLE = "UNMOUNTABLE";*/
47 JSClassDefinition JSStorage::m_classInfo = {
49 kJSClassAttributeNone,
59 NULL, //DeleteProperty,
60 NULL, //GetPropertyNames,
61 NULL, //CallAsFunction,
62 NULL, //CallAsConstructor,
67 JSStaticValue JSStorage::m_property[] = {
68 { STR_STORAGE_LABEL, getProperty, NULL, kJSPropertyAttributeReadOnly },
69 { STR_STORAGE_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
70 { STR_STORAGE_STATE, getProperty, NULL, kJSPropertyAttributeReadOnly },
71 /* { STR_TYPE_INTERNAL, getProperty, NULL, kJSPropertyAttributeReadOnly },
72 { STR_TYPE_EXTERNAL, getProperty, NULL, kJSPropertyAttributeReadOnly },
73 { STR_STATE_MOUNTED, getProperty, NULL, kJSPropertyAttributeReadOnly },
74 { STR_STATE_REMOVED, getProperty, NULL, kJSPropertyAttributeReadOnly },
75 { STR_STATE_UNMOUNTABLE, getProperty, NULL, kJSPropertyAttributeReadOnly },*/
79 const JSClassRef JSStorage::getClassRef()
82 m_jsClassRef = JSClassCreate(&m_classInfo);
87 const JSClassDefinition* JSStorage::getClassInfo()
92 JSClassRef JSStorage::m_jsClassRef = JSClassCreate(
93 JSStorage::getClassInfo());
95 JSObjectRef JSStorage::createJSObject(JSContextRef context,
96 const StorageProperties &storages)
98 std::auto_ptr<StorageProperties> storageProps(new StorageProperties());
100 storageProps->setLabel(storages.getLabel());
101 storageProps->setType(storages.getType());
102 storageProps->setState(storages.getState());
104 JSStoragePriv *priv = new JSStoragePriv(context, storageProps.get());
105 storageProps.release();
107 ThrowMsg(Commons::NullPointerException, "Can not new an object");
109 return JSObjectMake(context, getClassRef(), priv);
112 void JSStorage::initialize(JSContextRef context,
117 void JSStorage::finalize(JSObjectRef object)
119 JSStoragePriv* priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
120 JSObjectSetPrivate(object, NULL);
124 JSValueRef JSStorage::getProperty(JSContextRef context,
126 JSStringRef propertyName,
127 JSValueRef* exception)
129 JSStoragePriv *priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
130 assert(priv && "Private object not set.");
133 StorageProperties *storages = priv->getObject();
134 Converter convert(context);
136 if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_LABEL)) {
137 return convert.toJSValueRef(storages->getLabel());
138 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_TYPE)) {
139 return convert.toStorageType(storages->getType());
140 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_STATE)) {
141 return convert.toStorageState(storages->getState());
143 /*else if (JSStringIsEqualToUTF8CString(propertyName, STR_TYPE_INTERNAL)) {
144 return convert.toJSValueRef(TYPE_INTERNAL);
145 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_TYPE_EXTERNAL)) {
146 return convert.toJSValueRef(TYPE_EXTERNAL);
147 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_MOUNTED)) {
148 return convert.toJSValueRef(STATE_MOUNTED);
149 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_REMOVED)) {
150 return convert.toJSValueRef(STATE_REMOVED);
151 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_UNMOUNTABLE)) {
152 return convert.toJSValueRef(STATE_UNMOUNTABLE);
154 } Catch(Commons::Exception) {
155 LoggerW("trying to get incorrect value");
157 return JSValueMakeUndefined(context);
160 bool JSStorage::hasInstance(JSContextRef context,
161 JSObjectRef constructor,
162 JSValueRef possibleInstance,
163 JSValueRef* exception)
165 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());