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 <API/Call/CallHistoryFactory.h>
26 #include <API/Call/ICallHistoryEntry.h>
27 #include <Tizen/Common/JSTizenException.h>
28 #include <Tizen/Common/JSTizenExceptionFactory.h>
29 #include <Tizen/Common/SecurityExceptions.h>
30 #include "JSCallHistoryEntry.h"
31 #include "JSRemoteParty.h"
32 #include "Converter.h"
37 using namespace WrtDeviceApis;
38 using namespace WrtDeviceApis::Commons;
39 using namespace WrtDeviceApis::CommonsJavaScript;
40 using namespace Api::Call;
41 using namespace TizenApis::Commons;
43 #define STR_ENTRY_ID "entryId"
44 #define STR_SERVICE_ID "serviceId"
45 #define STR_CALL_TYPE "callType"
46 #define STR_TAGS "tags"
47 #define STR_REMOTE_PARTIES "remoteParties"
48 #define STR_FORWARDEDFROM "forwardedFrom"
49 #define STR_START_TIME "startTime"
50 #define STR_DURATION "duration"
51 #define STR_END_REASON "endReason"
52 #define STR_DIRECTION "direction"
53 #define STR_RECORDING "recording"
54 #define STR_COST "cost"
55 #define STR_CURRENCY "currency"
57 JSClassDefinition JSCallHistoryEntry::m_classInfo = {
59 kJSClassAttributeNone,
69 NULL, //DeleteProperty,
70 NULL, //GetPropertyNames,
71 NULL, //CallAsFunction,
72 NULL, //CallAsConstructor,
77 JSStaticValue JSCallHistoryEntry::m_property[] = {
78 { STR_ENTRY_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
79 { STR_SERVICE_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
80 { STR_CALL_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
81 { STR_TAGS, getProperty, NULL, kJSPropertyAttributeReadOnly },
82 { STR_REMOTE_PARTIES, getProperty, NULL, kJSPropertyAttributeReadOnly },
83 { STR_FORWARDEDFROM, getProperty, NULL, kJSPropertyAttributeReadOnly },
84 { STR_START_TIME, getProperty, NULL, kJSPropertyAttributeReadOnly },
85 { STR_DURATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
86 { STR_END_REASON, getProperty, NULL, kJSPropertyAttributeReadOnly },
87 { STR_DIRECTION, getProperty, setProperty, kJSPropertyAttributeNone },
88 { STR_RECORDING, getProperty, NULL, kJSPropertyAttributeReadOnly },
89 { STR_COST, getProperty, NULL, kJSPropertyAttributeReadOnly },
90 { STR_CURRENCY, getProperty, NULL, kJSPropertyAttributeReadOnly },
94 const JSClassRef JSCallHistoryEntry::getClassRef()
97 m_jsClassRef = JSClassCreate(&m_classInfo);
102 const JSClassDefinition* JSCallHistoryEntry::getClassInfo()
107 JSClassRef JSCallHistoryEntry::m_jsClassRef = JSClassCreate(JSCallHistoryEntry::getClassInfo());
109 JSObjectRef JSCallHistoryEntry::createJSObject(JSContextRef context,
110 const CallHistoryEntryProperties &entryInfo)
112 std::auto_ptr<CallHistoryEntryProperties> callHistoryEntryProps(new CallHistoryEntryProperties(entryInfo));
113 JSCallHistoryEntryPriv *priv = new JSCallHistoryEntryPriv(context, callHistoryEntryProps.get());
114 callHistoryEntryProps.release();
116 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
118 return JSObjectMake(context, getClassRef(), priv);
121 void JSCallHistoryEntry::initialize(JSContextRef context, JSObjectRef object)
125 void JSCallHistoryEntry::finalize(JSObjectRef object)
127 JSCallHistoryEntryPriv* priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
128 JSObjectSetPrivate(object, NULL);
132 JSValueRef JSCallHistoryEntry::getProperty(JSContextRef context,
134 JSStringRef propertyName,
135 JSValueRef* exception)
137 JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
138 assert(priv && "Private object not set.");
141 JSContextRef globalContext = priv->getContext();
142 CallHistoryEntryProperties *entryInfo = priv->getObject();
143 Converter convert(context);
145 if (JSStringIsEqualToUTF8CString(propertyName, STR_ENTRY_ID)) {
146 return convert.toJSValueRef(entryInfo->getEntryId());
147 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_SERVICE_ID)) {
148 return convert.toJSValueRef(entryInfo->getServiceId());
149 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CALL_TYPE)) {
150 return convert.toJSValueRef(entryInfo->getCallType());
151 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_TAGS)) {
152 return convert.toJSValueRef(entryInfo->getTags(), context);
153 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTIES)) {
154 return convert.toJSValueRef(entryInfo->getRemoteParties(), context);
155 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_FORWARDEDFROM)) {
156 return TizenApis::Tizen1_0::JSRemoteParty::createJSObject(globalContext, (*(entryInfo->getForwardedFrom())));
157 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_START_TIME)) {
158 return convert.toJSValueRef(entryInfo->getStartTime());
159 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
160 return convert.toJSValueRef(entryInfo->getDuration());
161 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_END_REASON)) {
162 return convert.toJSValueRef(entryInfo->getEndReason());
163 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DIRECTION)) {
164 return convert.toJSValueRef(entryInfo->getDirection());
165 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
166 return convert.toJSValueRef(entryInfo->getDuration());
167 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_RECORDING)) {
168 return convert.toJSValueRef(entryInfo->getRecording(), context);
169 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_COST)) {
170 return convert.toJSValueRef(entryInfo->getCost());
171 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CURRENCY)) {
172 return convert.toJSValueRef(entryInfo->getCurrency());
174 } catch(WrtDeviceApis::Commons::Exception) {
175 LogWarning("trying to get incorrect value");
177 return JSValueMakeUndefined(context);
180 bool JSCallHistoryEntry::setProperty(JSContextRef context,
182 JSStringRef propertyName,
184 JSValueRef* exception)
186 JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
187 assert(priv && "Private object not set.");
189 Converter converter(context);
191 if (JSStringIsEqualToUTF8CString(propertyName, STR_DIRECTION)) {
192 CallHistoryEntryProperties *entryInfo = priv->getObject();
193 if (entryInfo != NULL) {
194 ICallHistoryEntryPtr callHistoryEntry(CallHistoryFactory::getInstance().getCallHistoryEntryObject());
195 std::string direction(converter.toString(value));
197 if (callHistoryEntry != NULL) {
198 if((entryInfo->getDirection().compare("missed-new") == 0) && (direction.compare("missed") == 0)) {
199 callHistoryEntry->setMarkSeen(entryInfo->getEntryId());
200 entryInfo->setDirection("missed");
202 Throw(WrtDeviceApis::Commons::UnsupportedException);
207 Throw(WrtDeviceApis::Commons::Exception);
210 Throw(WrtDeviceApis::Commons::Exception);
213 Throw(WrtDeviceApis::Commons::UnsupportedException);
215 } catch(const WrtDeviceApis::Commons::UnsupportedException& ex) {
216 JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not supported error");
217 } catch (const WrtDeviceApis::Commons::Exception& ex) {
218 JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
223 bool JSCallHistoryEntry::hasInstance(JSContextRef context,
224 JSObjectRef constructor,
225 JSValueRef possibleInstance,
226 JSValueRef* exception)
228 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());