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.
20 #include <dpl/log/log.h>
21 #include <dpl/shared_ptr.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
24 #include <API/Call/RemoteParty.h>
25 #include "JSRemoteParty.h"
26 #include "Converter.h"
31 using namespace WrtDeviceApis;
32 using namespace WrtDeviceApis::Commons;
33 using namespace WrtDeviceApis::CommonsJavaScript;
34 using namespace Api::Call;
36 #define STR_REMOTE_PARTY "remoteParty"
37 #define STR_DISPLAY_NAME "displayName"
38 #define STR_CONTACT_ID "contactId"
40 JSClassDefinition JSRemoteParty::m_classInfo = {
42 kJSClassAttributeNone,
52 NULL, //DeleteProperty,
53 NULL, //GetPropertyNames,
54 NULL, //CallAsFunction,
55 NULL, //CallAsConstructor,
60 JSStaticValue JSRemoteParty::m_property[] = {
61 { STR_REMOTE_PARTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
62 { STR_DISPLAY_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
63 { STR_CONTACT_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
67 const JSClassRef JSRemoteParty::getClassRef()
70 m_jsClassRef = JSClassCreate(&m_classInfo);
75 const JSClassDefinition* JSRemoteParty::getClassInfo()
80 JSClassRef JSRemoteParty::m_jsClassRef = JSClassCreate(JSRemoteParty::getClassInfo());
82 JSObjectRef JSRemoteParty::createJSObject(JSContextRef context,
83 const RemoteParty &remoteParty)
85 std::auto_ptr<RemoteParty> RemotePartyProps(new RemoteParty(remoteParty));
86 JSRemotePartyPriv *priv = new JSRemotePartyPriv(context, RemotePartyProps.get());
87 RemotePartyProps.release();
89 ThrowMsg(Commons::NullPointerException, "Can not new an object");
91 return JSObjectMake(context, getClassRef(), priv);
94 void JSRemoteParty::initialize(JSContextRef context, JSObjectRef object)
98 void JSRemoteParty::finalize(JSObjectRef object)
100 JSRemotePartyPriv* priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
101 JSObjectSetPrivate(object, NULL);
105 JSValueRef JSRemoteParty::getProperty(JSContextRef context,
107 JSStringRef propertyName,
108 JSValueRef* exception)
110 JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
111 assert(priv && "Private object not set.");
114 RemoteParty* remoteParty = priv->getObject();
115 Converter convert(context);
117 if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTY)) {
118 return convert.toJSValueRef(remoteParty->getRemoteParty());
119 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DISPLAY_NAME)) {
120 return convert.toJSValueRef(remoteParty->getDisplayName());
121 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CONTACT_ID)) {
122 return convert.toJSValueRef(remoteParty->getContactId());
124 } catch(Commons::Exception) {
125 LogWarning("trying to get incorrect value");
127 return JSValueMakeUndefined(context);
130 bool JSRemoteParty::hasInstance(JSContextRef context,
131 JSObjectRef constructor,
132 JSValueRef possibleInstance,
133 JSValueRef* exception)
135 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());