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 <SecurityExceptions.h>
21 #include <JSWebAPIErrorFactory.h>
22 #include <ArgumentValidator.h>
23 #include <GlobalContextManager.h>
24 #include <MultiCallbackUserData.h>
25 #include <PlatformException.h>
27 #include "plugin_config.h"
29 #include "JSHCEEventData.h"
31 using namespace WrtDeviceApis::Commons;
32 using namespace DeviceAPI::Common;
38 const char* HCEAPDU_DATA_EVENT_TYPE ="eventType";
39 const char* HCEAPDU_DATA_APDU ="apdu";
40 const char* HCEAPDU_DATA_LENGTH ="length";
43 JSClassDefinition JSHCEEventData::m_classInfo = {
45 kJSClassAttributeNone,
48 m_property, //StaticValues
49 NULL, //StaticFunctions
50 initialize, //Initialize
55 NULL, //DeleteProperty,
56 NULL, //GetPropertyNames,
57 NULL, //CallAsFunction,
58 NULL, //CallAsConstructor,
63 JSStaticValue JSHCEEventData::m_property[] = {
64 { HCEAPDU_DATA_EVENT_TYPE, getEventType, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
65 { HCEAPDU_DATA_APDU, getApdu, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
66 { HCEAPDU_DATA_LENGTH, getLength, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
71 JSClassRef JSHCEEventData::m_jsClassRef = JSClassCreate(JSHCEEventData::getClassInfo());
73 const JSClassRef JSHCEEventData::getClassRef()
78 m_jsClassRef = JSClassCreate(&m_classInfo);
83 const JSClassDefinition* JSHCEEventData::getClassInfo()
89 void JSHCEEventData::initialize(JSContextRef context, JSObjectRef object)
94 void JSHCEEventData::finalize(JSObjectRef object)
99 HceEventDataPtr JSHCEEventData::getPrivateObject(JSContextRef context, JSObjectRef object)
103 if (!JSValueIsObjectOfClass(context, object, getClassRef())) {
104 LOGE("Type mismatch");
105 throw TypeMismatchException("Type mismatch");
108 HceEventDataHolder * holder = static_cast<HceEventDataHolder *>(JSObjectGetPrivate(object));
110 LOGE("No holder data exist");
111 throw TypeMismatchException("No holder data exist");
115 LOGE("holder ptr is null");
116 throw TypeMismatchException("holder ptr is null");
122 void JSHCEEventData::setPrivateObject(JSContextRef context, JSObjectRef object, HceEventDataPtr priv)
127 JSObjectRef JSHCEEventData::makeJSObject(JSContextRef context, HceEventDataPtr native)
132 LOGE("Native is null");
133 throw Common::UnknownException("Native is null");
135 HceEventDataHolder* holder = new(std::nothrow) HceEventDataHolder();
137 LOGE("No holder data exist");
138 throw TypeMismatchException("No holder data exist");
140 holder->ptr = native;
142 JSObjectRef obj = JSObjectMake(context, getClassRef(), static_cast<void*>(holder));
144 LOGE("Object creation failed");
147 throw Common::UnknownException("Object creation failed");
153 JSValueRef JSHCEEventData::getEventType(JSContextRef context,
155 JSStringRef propertyName,
156 JSValueRef* exception)
160 HceEventDataPtr priv = getPrivateObject(context, object);
162 return JSUtil::toJSValueRef(context, priv->getEventType());
164 catch (const BasePlatformException &err) {
165 LOGE("Exception caught: name: %s, msg: %s",
166 err.getName().c_str(), err.getMessage().c_str());
169 LOGE("getEventType fails");
171 return JSValueMakeUndefined(context);
174 JSValueRef JSHCEEventData::getApdu(JSContextRef context,
176 JSStringRef propertyName,
177 JSValueRef* exception)
181 HceEventDataPtr priv = getPrivateObject(context, object);
183 return JSUtil::toJSValueRef_(context, priv->getApdu());
185 catch (const BasePlatformException &err) {
186 LOGE("Exception caught: name: %s, msg: %s",
187 err.getName().c_str(), err.getMessage().c_str());
190 LOGE("getApdu fails");
192 return JSValueMakeUndefined(context);
195 JSValueRef JSHCEEventData::getLength(JSContextRef context,
197 JSStringRef propertyName,
198 JSValueRef* exception)
202 HceEventDataPtr priv = getPrivateObject(context, object);
204 return JSUtil::toJSValueRef(context, priv->getLength());
206 catch (const BasePlatformException &err) {
207 LOGE("Exception caught: name: %s, msg: %s",
208 err.getName().c_str(), err.getMessage().c_str());
211 LOGE("getLength fails");
213 return JSValueMakeUndefined(context);