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.
19 #include <dpl/shared_ptr.h>
20 #include <CommonsJavaScript/JSUtils.h>
21 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
22 #include <JSWebAPIErrorFactory.h>
23 #include "CallHistoryDefine.h"
24 #include "RemoteParty.h"
25 #include "JSRemoteParty.h"
26 #include "Converter.h"
29 using namespace WrtDeviceApis;
30 using namespace WrtDeviceApis::Commons;
31 using namespace WrtDeviceApis::CommonsJavaScript;
32 using namespace DeviceAPI::Common;
35 namespace CallHistory {
37 JSClassDefinition JSRemoteParty::m_classInfo = {
39 kJSClassAttributeNone,
48 setProperty, // NULL, //SetProperty,
49 NULL, //DeleteProperty,
50 NULL, //GetPropertyNames,
51 NULL, //CallAsFunction,
52 NULL, //CallAsConstructor,
57 JSStaticValue JSRemoteParty::m_property[] = {
58 { STR_REMOTE_PARTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
59 { STR_PERSIONID, getProperty, NULL, kJSPropertyAttributeReadOnly },
63 const JSClassRef JSRemoteParty::getClassRef()
66 m_jsClassRef = JSClassCreate(&m_classInfo);
71 const JSClassDefinition* JSRemoteParty::getClassInfo()
76 JSClassRef JSRemoteParty::m_jsClassRef = JSClassCreate(JSRemoteParty::getClassInfo());
78 JSObjectRef JSRemoteParty::createJSObject(JSContextRef context,
79 const RemoteParty &remoteParty)
81 RemotePartyPtr RemotePartyProps(new RemoteParty(remoteParty));
82 JSRemotePartyPriv *priv = new JSRemotePartyPriv(context, RemotePartyPtr(RemotePartyProps));
84 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
86 return JSObjectMake(context, getClassRef(), priv);
89 RemotePartyPtr JSRemoteParty::getRemoteParty(JSContextRef context, JSValueRef value)
91 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
92 Throw(WrtDeviceApis::Commons::ConversionException);
94 JSObjectRef object = JSValueToObject(context, value, NULL);
96 Throw(WrtDeviceApis::Commons::ConversionException);
98 JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
100 Throw(WrtDeviceApis::Commons::ConversionException);
102 return priv->getObject();
105 void JSRemoteParty::initialize(JSContextRef context, JSObjectRef object)
109 void JSRemoteParty::finalize(JSObjectRef object)
111 JSRemotePartyPriv* priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
113 JSObjectSetPrivate(object, NULL);
118 JSValueRef JSRemoteParty::getProperty(JSContextRef context,
120 JSStringRef propertyName,
121 JSValueRef* exception)
123 JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
125 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
129 RemotePartyPtr remoteParty = priv->getObject();
130 Converter convert(context);
132 if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTY)) {
133 return convert.toJSValueRef(remoteParty->getRemoteParty());
134 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_PERSIONID)) {
135 return convert.toJSValueRef(remoteParty->getPersonId());
137 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
138 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
139 } catch(const WrtDeviceApis::Commons::Exception& ex) {
140 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
145 bool JSRemoteParty::setProperty(JSContextRef context,
147 JSStringRef propertyName,
149 JSValueRef* exception)
155 bool JSRemoteParty::hasInstance(JSContextRef context,
156 JSObjectRef constructor,
157 JSValueRef possibleInstance,
158 JSValueRef* exception)
160 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());