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/CallHistoryEntryProperties.h>
25 #include "JSCallHistoryEntry.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_ENTRY_ID "entryId"
37 #define STR_ACCOUNT_ID "accountId"
38 #define STR_CALL_TYPE "callType"
39 #define STR_REMOTE_PARTY "remoteParty"
40 #define STR_CONTACT_ID "contactId"
41 #define STR_CONTACT_DETAILS "contactDetails"
42 #define STR_FORWARDEDFROM "forwardedFrom"
43 #define STR_START_TIME "startTime"
44 #define STR_DURATION "duration"
45 #define STR_END_REASON "endReason"
46 #define STR_USED_CAPABILITIES "usedCapabilities"
47 #define STR_KIND "kind"
48 #define STR_DIRECTION "direction"
49 #define STR_RECORDING "recording"
50 #define STR_COST "cost"
51 #define STR_CURRENCY "currency"
53 JSClassDefinition JSCallHistoryEntry::m_classInfo = {
55 kJSClassAttributeNone,
65 NULL, //DeleteProperty,
66 NULL, //GetPropertyNames,
67 NULL, //CallAsFunction,
68 NULL, //CallAsConstructor,
73 JSStaticValue JSCallHistoryEntry::m_property[] = {
74 { STR_ENTRY_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
75 { STR_ACCOUNT_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
76 { STR_CALL_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
77 { STR_REMOTE_PARTY, getProperty, NULL, kJSPropertyAttributeNone },
78 { STR_CONTACT_ID, getProperty, NULL, kJSPropertyAttributeNone },
79 { STR_CONTACT_DETAILS, getProperty, NULL, kJSPropertyAttributeNone },
80 { STR_FORWARDEDFROM, getProperty, NULL, kJSPropertyAttributeNone },
81 { STR_START_TIME, getProperty, NULL, kJSPropertyAttributeReadOnly },
82 { STR_DURATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
83 { STR_END_REASON, getProperty, NULL, kJSPropertyAttributeNone },
84 { STR_USED_CAPABILITIES, getProperty, NULL, kJSPropertyAttributeNone },
85 { STR_KIND, getProperty, NULL, kJSPropertyAttributeNone },
86 { STR_DIRECTION, getProperty, NULL, kJSPropertyAttributeNone },
87 { STR_RECORDING, getProperty, NULL, kJSPropertyAttributeNone },
88 { STR_COST, getProperty, NULL, kJSPropertyAttributeNone },
89 { STR_CURRENCY, getProperty, NULL, kJSPropertyAttributeNone },
93 const JSClassRef JSCallHistoryEntry::getClassRef()
96 m_jsClassRef = JSClassCreate(&m_classInfo);
101 const JSClassDefinition* JSCallHistoryEntry::getClassInfo()
106 JSClassRef JSCallHistoryEntry::m_jsClassRef = JSClassCreate(JSCallHistoryEntry::getClassInfo());
108 JSObjectRef JSCallHistoryEntry::createJSObject(JSContextRef context,
109 const CallHistoryEntryProperties &callInfo)
111 std::auto_ptr<CallHistoryEntryProperties> callHistoryEntryProps(new CallHistoryEntryProperties(callInfo));
112 JSCallHistoryEntryPriv *priv = new JSCallHistoryEntryPriv(context, callHistoryEntryProps.get());
113 callHistoryEntryProps.release();
115 ThrowMsg(Commons::NullPointerException, "Can not new an object");
117 return JSObjectMake(context, getClassRef(), priv);
120 void JSCallHistoryEntry::initialize(JSContextRef context, JSObjectRef object)
124 void JSCallHistoryEntry::finalize(JSObjectRef object)
126 JSCallHistoryEntryPriv* priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
127 JSObjectSetPrivate(object, NULL);
131 JSValueRef JSCallHistoryEntry::getProperty(JSContextRef context,
133 JSStringRef propertyName,
134 JSValueRef* exception)
136 JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
137 assert(priv && "Private object not set.");
140 CallHistoryEntryProperties *callInfo = priv->getObject();
141 Converter convert(context);
143 if (JSStringIsEqualToUTF8CString(propertyName, STR_ENTRY_ID)) {
144 return convert.toJSValueRef(callInfo->getEntryId());
145 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_ACCOUNT_ID)) {
146 return convert.toJSValueRef(callInfo->getAccountId());
147 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CALL_TYPE)) {
148 return convert.toJSValueRef(callInfo->getCallType());
149 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTY)) {
150 return convert.toJSValueRef(callInfo->getRemoteParty());
151 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CONTACT_ID)) {
152 return convert.toJSValueRef(callInfo->getContactId());
153 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CONTACT_DETAILS)) {
154 return convert.toJSValueRef(callInfo->getContactDetails());
155 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_FORWARDEDFROM)) {
156 return convert.toJSValueRef(callInfo->getForwardedFrom());
157 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_START_TIME)) {
158 return convert.toJSValueRef(callInfo->getStartTime());
159 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
160 return convert.toJSValueRef(callInfo->getDuration());
161 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_END_REASON)) {
162 return convert.toJSValueRef(callInfo->getEndReason());
163 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_USED_CAPABILITIES)) {
164 return convert.toJSValueRef(callInfo->getUsedCapabilities(), context);
165 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_KIND)) {
166 return convert.toJSValueRef(callInfo->getKind());
167 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DIRECTION)) {
168 return convert.toJSValueRef(callInfo->getDirection());
169 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
170 return convert.toJSValueRef(callInfo->getDuration());
171 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_RECORDING)) {
172 return convert.toJSValueRef(callInfo->getRecording(), context);
173 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_COST)) {
174 return convert.toJSValueRef(callInfo->getCost());
175 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CURRENCY)) {
176 return convert.toJSValueRef(callInfo->getCurrency());
178 } catch(Commons::Exception) {
179 LogWarning("trying to get incorrect value");
181 return JSValueMakeUndefined(context);
184 bool JSCallHistoryEntry::hasInstance(JSContextRef context,
185 JSObjectRef constructor,
186 JSValueRef possibleInstance,
187 JSValueRef* exception)
189 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());