2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
23 #include "JSApplicationServiceReply.h"
27 namespace Application {
28 using namespace WrtDeviceApis;
29 using namespace WrtDeviceApis::Commons;
30 using namespace WrtDeviceApis::CommonsJavaScript;
31 using namespace Api::Application;
34 const char* APPLICATION_SERVICE_REPLY_SUCCESS = "isSucceed";
35 const char* APPLICATION_SERVICE_EXTRADATA = "extraData";
40 JSClassRef JSApplicationServiceReply::m_jsClassRef = NULL;
42 JSClassDefinition JSApplicationServiceReply::m_classInfo = {
44 kJSClassAttributeNone,
45 "ApplicationServiceReply",
54 NULL, //DeleteProperty,
55 NULL, //GetPropertyNames,
56 NULL, //CallAsFunction,
57 NULL, //CallAsConstructor,
62 JSStaticValue JSApplicationServiceReply::m_property[] = {
63 { APPLICATION_SERVICE_REPLY_SUCCESS, getIsSucceed, NULL, kJSPropertyAttributeReadOnly },
64 { APPLICATION_SERVICE_EXTRADATA, getExtraData, NULL, kJSPropertyAttributeReadOnly },
68 const JSClassDefinition* JSApplicationServiceReply::getClassInfo()
73 const JSClassRef JSApplicationServiceReply::getClassRef()
76 m_jsClassRef = JSClassCreate(&m_classInfo);
81 JSObjectRef JSApplicationServiceReply::createJSObject(JSContextRef context,
82 const ApplicationServiceReplyPtr &appsvc)
84 ApplicationServiceReplyPtr privateData(new ApplicationServiceReply());
85 JSApplicationServiceReplyPriv *priv = new JSApplicationServiceReplyPriv(context, privateData);
88 ThrowMsg(Commons::NullPointerException, "Can not new an object");
90 return JSObjectMake(context, getClassRef(), priv);
93 ApplicationServiceReplyPtr JSApplicationServiceReply::getApplicationServiceReply(JSContextRef context, JSValueRef value)
95 if (!isObjectOfClass(context, value)) {
96 Throw(Commons::InvalidArgumentException);
98 JSObjectRef object = JSValueToObject(context, value, NULL);
100 Throw(Commons::InvalidArgumentException);
102 JSApplicationServiceReplyPriv *priv = static_cast<JSApplicationServiceReplyPriv*>(JSObjectGetPrivate(object));
104 Throw(Commons::NullPointerException);
106 return priv->getObject();
109 ApplicationServiceReplyPtr JSApplicationServiceReply::getPrivateData(JSObjectRef object)
111 JSApplicationServiceReplyPriv* priv = static_cast<JSApplicationServiceReplyPriv*>(JSObjectGetPrivate(object));
113 Throw(Commons::NullPointerException);
115 return priv->getObject();
120 void JSApplicationServiceReply::initialize(JSContextRef context,JSObjectRef object)
122 LogDebug("Entered. Nothing to do.");
125 void JSApplicationServiceReply::finalize(JSObjectRef object)
128 JSApplicationServiceReplyPriv* priv =
129 static_cast<JSApplicationServiceReplyPriv*>(JSObjectGetPrivate(object));
130 JSObjectSetPrivate(object, NULL);
131 LogDebug("Deleting ApplicationServiceReply object");
135 bool JSApplicationServiceReply::isObjectOfClass(JSContextRef context, JSValueRef value)
137 return JSValueIsObjectOfClass(context, value, getClassRef());
140 JSValueRef JSApplicationServiceReply::getIsSucceed(JSContextRef context,
142 JSStringRef propertyName,
143 JSValueRef* exception)
146 JSApplicationServiceReplyPriv *priv =
147 static_cast<JSApplicationServiceReplyPriv*>(JSObjectGetPrivate(object));
148 assert(priv && "Private object not set.");
151 ApplicationServiceReplyPtr appsvc = priv->getObject();
152 CommonsJavaScript::Converter converter(context);
154 if (JSStringIsEqualToUTF8CString(propertyName,APPLICATION_SERVICE_REPLY_SUCCESS)) {
156 "JSApplicationServiceReply::getProperty ::success ");
158 bool isSucceed = appsvc->getIsSucceed();
159 return converter.toJSValueRef(isSucceed);
163 Catch(Commons::Exception) {
164 LogError("Exception: " << _rethrown_exception.GetMessage());
165 return JSDOMExceptionFactory::UnknownException.make(context, exception);
167 return JSValueMakeUndefined(context);
170 JSValueRef JSApplicationServiceReply::getExtraData(JSContextRef context,
172 JSStringRef propertyName,
173 JSValueRef* exception)
176 JSApplicationServiceReplyPriv *priv =
177 static_cast<JSApplicationServiceReplyPriv*>(JSObjectGetPrivate(object));
178 assert(priv && "Private object not set.");
181 ApplicationServiceReplyPtr appsvc = priv->getObject();
182 CommonsJavaScript::Converter convert(context);
184 if (JSStringIsEqualToUTF8CString(propertyName,APPLICATION_SERVICE_EXTRADATA)) {
186 "JSApplicationServiceReply::getProperty ::extraData ");
188 JSObjectRef result = JSApplicationServiceExtraDataArray::createArray(context, appsvc->getExtraDataArray());
193 Catch(Commons::Exception) {
194 LogError("Exception: " << _rethrown_exception.GetMessage());
195 return JSDOMExceptionFactory::UnknownException.make(context, exception);
197 return JSValueMakeUndefined(context);
200 bool JSApplicationServiceReply::hasInstance(JSContextRef context,
201 JSObjectRef constructor,
202 JSValueRef possibleInstance,
203 JSValueRef* exception)
205 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());