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.
20 #include <dpl/shared_ptr.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
23 #include <JSWebAPIErrorFactory.h>
24 #include "CallHistoryDefine.h"
25 #include "RemoteParty.h"
26 #include "JSRemoteParty.h"
27 #include "Converter.h"
30 using namespace WrtDeviceApis;
31 using namespace WrtDeviceApis::Commons;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 using namespace DeviceAPI::Common;
36 namespace CallHistory {
38 JSClassDefinition JSRemoteParty::m_classInfo = {
40 kJSClassAttributeNone,
49 setProperty, // NULL, //SetProperty,
50 NULL, //DeleteProperty,
51 NULL, //GetPropertyNames,
52 NULL, //CallAsFunction,
53 NULL, //CallAsConstructor,
58 JSStaticValue JSRemoteParty::m_property[] = {
59 { STR_REMOTE_PARTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
60 { STR_PERSIONID, getProperty, NULL, kJSPropertyAttributeReadOnly },
64 const JSClassRef JSRemoteParty::getClassRef()
67 m_jsClassRef = JSClassCreate(&m_classInfo);
72 const JSClassDefinition* JSRemoteParty::getClassInfo()
77 JSClassRef JSRemoteParty::m_jsClassRef = JSClassCreate(JSRemoteParty::getClassInfo());
79 JSObjectRef JSRemoteParty::createJSObject(JSContextRef context,
80 const RemoteParty &remoteParty)
82 RemotePartyPtr RemotePartyProps(new RemoteParty(remoteParty));
83 JSRemotePartyPriv *priv = new JSRemotePartyPriv(context, RemotePartyPtr(RemotePartyProps));
85 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
87 return JSObjectMake(context, getClassRef(), priv);
90 RemotePartyPtr JSRemoteParty::getRemoteParty(JSContextRef context, JSValueRef value)
92 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
93 Throw(WrtDeviceApis::Commons::ConversionException);
95 JSObjectRef object = JSValueToObject(context, value, NULL);
97 Throw(WrtDeviceApis::Commons::ConversionException);
99 JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
101 Throw(WrtDeviceApis::Commons::ConversionException);
103 return priv->getObject();
106 void JSRemoteParty::initialize(JSContextRef context, JSObjectRef object)
110 void JSRemoteParty::finalize(JSObjectRef object)
112 JSRemotePartyPriv* priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
114 JSObjectSetPrivate(object, NULL);
119 JSValueRef JSRemoteParty::getProperty(JSContextRef context,
121 JSStringRef propertyName,
122 JSValueRef* exception)
124 JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
126 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
130 RemotePartyPtr remoteParty = priv->getObject();
131 Converter convert(context);
133 if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTY)) {
134 return convert.toJSValueRef(remoteParty->getRemoteParty());
135 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_PERSIONID)) {
136 return convert.toJSValueRef(remoteParty->getPersonId());
138 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
139 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
140 } catch(const WrtDeviceApis::Commons::Exception& ex) {
141 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
146 bool JSRemoteParty::setProperty(JSContextRef context,
148 JSStringRef propertyName,
150 JSValueRef* exception)
156 bool JSRemoteParty::hasInstance(JSContextRef context,
157 JSObjectRef constructor,
158 JSValueRef possibleInstance,
159 JSValueRef* exception)
161 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());