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 <JSTizenExceptionFactory.h>
24 #include <JSTizenException.h>
25 #include "CallHistoryDefine.h"
26 #include "RemoteParty.h"
27 #include "JSRemoteParty.h"
28 #include "Converter.h"
31 using namespace WrtDeviceApis;
32 using namespace WrtDeviceApis::Commons;
33 using namespace WrtDeviceApis::CommonsJavaScript;
34 using namespace DeviceAPI::Common;
37 namespace CallHistory {
39 JSClassDefinition JSRemoteParty::m_classInfo = {
41 kJSClassAttributeNone,
50 setProperty, // NULL, //SetProperty,
51 NULL, //DeleteProperty,
52 NULL, //GetPropertyNames,
53 NULL, //CallAsFunction,
54 NULL, //CallAsConstructor,
59 JSStaticValue JSRemoteParty::m_property[] = {
60 { STR_REMOTE_PARTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
61 { STR_PERSIONID, getProperty, NULL, kJSPropertyAttributeReadOnly },
65 const JSClassRef JSRemoteParty::getClassRef()
68 m_jsClassRef = JSClassCreate(&m_classInfo);
73 const JSClassDefinition* JSRemoteParty::getClassInfo()
78 JSClassRef JSRemoteParty::m_jsClassRef = JSClassCreate(JSRemoteParty::getClassInfo());
80 JSObjectRef JSRemoteParty::createJSObject(JSContextRef context,
81 const RemoteParty &remoteParty)
83 RemotePartyPtr RemotePartyProps(new RemoteParty(remoteParty));
84 JSRemotePartyPriv *priv = new JSRemotePartyPriv(context, RemotePartyPtr(RemotePartyProps));
86 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
88 return JSObjectMake(context, getClassRef(), priv);
91 RemotePartyPtr JSRemoteParty::getRemoteParty(JSContextRef context, JSValueRef value)
93 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
94 Throw(WrtDeviceApis::Commons::ConversionException);
96 JSObjectRef object = JSValueToObject(context, value, NULL);
98 Throw(WrtDeviceApis::Commons::ConversionException);
100 JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
102 Throw(WrtDeviceApis::Commons::ConversionException);
104 return priv->getObject();
107 void JSRemoteParty::initialize(JSContextRef context, JSObjectRef object)
111 void JSRemoteParty::finalize(JSObjectRef object)
113 JSRemotePartyPriv* priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
115 JSObjectSetPrivate(object, NULL);
120 JSValueRef JSRemoteParty::getProperty(JSContextRef context,
122 JSStringRef propertyName,
123 JSValueRef* exception)
125 JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
127 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
131 RemotePartyPtr remoteParty = priv->getObject();
132 Converter convert(context);
134 if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTY)) {
135 return convert.toJSValueRef(remoteParty->getRemoteParty());
136 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_PERSIONID)) {
137 return convert.toJSValueRef(remoteParty->getPersonId());
139 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
140 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
141 } catch(const WrtDeviceApis::Commons::Exception& ex) {
142 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
147 bool JSRemoteParty::setProperty(JSContextRef context,
149 JSStringRef propertyName,
151 JSValueRef* exception)
157 bool JSRemoteParty::hasInstance(JSContextRef context,
158 JSObjectRef constructor,
159 JSValueRef possibleInstance,
160 JSValueRef* exception)
162 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());