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.
18 * @file JSTizenServiceEvent.cpp
19 * @author Yunchan Cho (yunchan.cho@samsung.com)
23 #include "JSTizenServiceEvent.h"
24 #include <dpl/log/log.h>
25 #include <dpl/assert.h>
26 #include <TizenServiceEvent/ITizenServiceEvent.h>
27 #include <CommonsJavaScript/Converter.h>
28 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
30 using namespace WrtDeviceApis;
31 using namespace WrtDeviceApis::Commons;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 using namespace WrtDeviceApis::TizenServiceEvent::Api;
35 #define WIDGET_PLUGIN_NAME "TizenServiceEvent"
37 #define TIZEN_SERVICE_EVENT_PROPERTY_SCALE "scale"
38 #define TIZEN_SERVICE_EVENT_PROPERTY_BUNDLE "__bundle"
40 #define CATCH_EXCEPTION_CONVERSION \
41 Catch(Commons::ConversionException) { \
42 LogError("Error on conversion"); \
43 return JSDOMExceptionFactory:: \
44 UnknownException.make(context, exception); \
47 #define CATCH_EXCEPTION_NULL_PTR \
48 Catch(Commons::NullPointerException) { \
49 LogError("Error on pointer, null value"); \
50 return JSDOMExceptionFactory:: \
51 UnknownException.make(context, exception); \
54 #define CATCH_EXCEPTION_PLATFORM_ERROR \
55 Catch(Commons::PlatformException){ \
56 LogError("PlatformException occured"); \
57 return JSDOMExceptionFactory:: \
58 UnknownException.make(context, exception); \
61 #define CATCH_EXCEPTION_SECURITY \
62 Catch(Commons::SecurityException){ \
63 LogError("Security exception occured"); \
64 return JSDOMExceptionFactory:: \
65 SecurityException.make(context, exception); \
68 namespace WrtPlugins {
70 JSClassDefinition JSTizenServiceEvent::m_classInfo = {
72 kJSClassAttributeNone,
82 NULL, //DeleteProperty,
83 NULL, //GetPropertyNames,
84 NULL, //CallAsFunction,
85 NULL, //CallAsConstructor,
87 NULL, //ConvertToType,
90 JSStaticValue JSTizenServiceEvent::m_property[] = {
91 { TIZEN_SERVICE_EVENT_PROPERTY_SCALE, JSTizenServiceEvent::getScale,
92 0, kJSPropertyAttributeReadOnly },
93 { TIZEN_SERVICE_EVENT_PROPERTY_BUNDLE, JSTizenServiceEvent::getBundle,
94 0, kJSPropertyAttributeReadOnly },
98 JSClassRef JSTizenServiceEvent::getClassRef()
101 m_jsClassRef = JSClassCreate(&m_classInfo);
106 const JSClassDefinition* JSTizenServiceEvent::getClassInfo()
111 JSClassRef JSTizenServiceEvent::m_jsClassRef = JSClassCreate(
112 JSTizenServiceEvent::getClassInfo());
114 void JSTizenServiceEvent::initialize(JSContextRef /*context*/,
119 JSTizenServiceEventPrivateObject* priv =
120 static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(
123 Assert(priv && "Missing private object");
126 void JSTizenServiceEvent::finalize(JSObjectRef object)
129 JSTizenServiceEventPrivateObject* priv =
130 static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(
134 LogDebug("private object is realised");
137 JSValueRef JSTizenServiceEvent::getScale(
138 JSContextRef context,
140 JSStringRef /*propertyName*/,
141 JSValueRef* exception)
147 Converter converter(context);
148 return converter.toJSValueRef(getPrivateObject(object)->getScale());
150 CATCH_EXCEPTION_CONVERSION
151 CATCH_EXCEPTION_NULL_PTR
152 CATCH_EXCEPTION_PLATFORM_ERROR
153 CATCH_EXCEPTION_SECURITY
156 JSValueRef JSTizenServiceEvent::getBundle(
157 JSContextRef context,
159 JSStringRef /*propertyName*/,
160 JSValueRef* exception)
166 Converter converter(context);
167 return converter.toJSValueRef(getPrivateObject(object)->getBundle());
169 CATCH_EXCEPTION_CONVERSION
170 CATCH_EXCEPTION_NULL_PTR
171 CATCH_EXCEPTION_PLATFORM_ERROR
172 CATCH_EXCEPTION_SECURITY
175 ITizenServiceEventPtr JSTizenServiceEvent::getPrivateObject(JSObjectRef arg)
177 JSTizenServiceEventPrivateObject* priv =
178 static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(arg));
181 LogError("Private object not initialized");
182 ThrowMsg(Commons::NullPointerException,
183 "Private object not initialized");
186 return priv->getObject();
189 #undef CATCH_EXCEPTION_CONVERSION
190 #undef CATCH_EXCEPTION_NULL_PTR
191 #undef CATCH_EXCEPTION_PLATFORM_ERROR
192 #undef CATCH_EXCEPTION_SECURITY