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.
18 #include <JSWebAPIException.h>
19 #include <CommonsJavaScript/Converter.h>
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <CommonsJavaScript/Utils.h>
23 #include "JSPackageInformation.h"
24 #include "PackageInformation.h"
31 using namespace WrtDeviceApis::Commons;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 using namespace DeviceAPI::Common;
35 JSClassRef JSPackageInformation::m_classRef = NULL;
37 JSClassDefinition JSPackageInformation::m_classInfo = {
38 0, // current (and only) version is 0
39 kJSClassAttributeNone, // attributes
40 TIZEN_INTERFACE_PACKAGE_INFORMATION, // class name
42 m_property, // static values
43 NULL, // static functions
44 initialize, // initialize
49 NULL, // deleteProperty
50 NULL, // getPropertyNames
51 NULL, // callAsConstructor
52 NULL, // callAsConstructor
57 JSStaticValue JSPackageInformation::m_property[] = {
58 { TIZEN_PACKAGE_INFORMATION_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
59 { TIZEN_PACKAGE_INFORMATION_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
60 { TIZEN_PACKAGE_INFORMATION_ICONPATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
61 { TIZEN_PACKAGE_INFORMATION_VERSION, getProperty, NULL, kJSPropertyAttributeReadOnly },
62 { TIZEN_PACKAGE_INFORMATION_TOTAL_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },
63 { TIZEN_PACKAGE_INFORMATION_DATA_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },
64 { TIZEN_PACKAGE_INFORMATION_LAST_MODIFIED, getProperty, NULL, kJSPropertyAttributeReadOnly },
65 { TIZEN_PACKAGE_INFORMATION_AUTHOR, getProperty, NULL, kJSPropertyAttributeReadOnly },
66 { TIZEN_PACKAGE_INFORMATION_DESCRIPTION, getProperty, NULL, kJSPropertyAttributeReadOnly },
67 { TIZEN_PACKAGE_INFORMATION_APP_IDS, getProperty, NULL, kJSPropertyAttributeReadOnly },
71 // type is defined to partner feature on native
72 //{ TIZEN_PACKAGE_INFORMATION_TYPE, getProperty, setProperty, kJSPropertyAttributeReadOnly },
74 JSClassRef JSPackageInformation::getClassRef() {
76 m_classRef = JSClassCreate(&m_classInfo);
82 JSValueRef JSPackageInformation::createJSObject(JSContextRef context, PackageInformation *pkgInfo)
84 //LoggerE("createJSObject enter");
85 JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(pkgInfo));
86 if (NULL == jsValueRef) {
87 LoggerE("object creation error");
88 return JSValueMakeUndefined(context);
95 void JSPackageInformation::initialize(JSContextRef context, JSObjectRef object)
97 LoggerD(">> initialize");
100 void JSPackageInformation::finalize(JSObjectRef object)
102 LoggerD(">> finalize");
105 bool JSPackageInformation::isObjectOfClass(JSContextRef context, JSValueRef value)
107 return JSValueIsObjectOfClass(context, value, getClassRef());
110 PackageInformation* JSPackageInformation::getPrivData(JSObjectRef object)
112 PackageInformation *priv = static_cast<PackageInformation*>(JSObjectGetPrivate(object));
114 throw TypeMismatchException("Private object is null");
120 JSValueRef JSPackageInformation::getProperty(JSContextRef context,
122 JSStringRef propertyName,
123 JSValueRef* exception)
126 //WrtDeviceApis::CommonsJavaScript::Converter converter(context);
127 PackageInformation* privateData = getPrivData(object);
129 throw TypeMismatchException("Private object is NULL");
132 if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_ID)) {
133 return JSUtil::toJSValueRef(context, privateData->m_id);
134 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_NAME)) {
135 return JSUtil::toJSValueRef(context, privateData->m_name);
136 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_ICONPATH)) {
137 return JSUtil::toJSValueRef(context, privateData->m_iconPath);
138 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_VERSION)) {
139 return JSUtil::toJSValueRef(context, privateData->m_version);
140 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_TOTAL_SIZE)) {
141 return JSUtil::toJSValueRef(context, privateData->m_totalSize);
142 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_DATA_SIZE)) {
143 return JSUtil::toJSValueRef(context, privateData->m_dataSize);
144 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_LAST_MODIFIED)) {
145 return JSUtil::makeDateObject(context, privateData->m_lastModified);
146 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_AUTHOR)) {
147 return JSUtil::toJSValueRef(context, privateData->m_author);
148 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_DESCRIPTION)) {
149 return JSUtil::toJSValueRef(context, privateData->m_description);
150 } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_PACKAGE_INFORMATION_APP_IDS)) {
151 return JSUtil::toJSValueRef(context, privateData->m_appIds);
153 } catch (const BasePlatformException &err) {
154 return JSWebAPIException::throwException(context, exception, err);
156 DeviceAPI::Common::TypeMismatchException err("TypeMismatchException occured");
157 return JSWebAPIException::throwException(context, exception, err);
160 return JSValueMakeUndefined(context);