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 "CallHistoryEntryProperties.h"
24 #include "CallHistoryFactory.h"
25 #include "ICallHistoryEntry.h"
26 #include "CallHistoryDefine.h"
27 #include <JSWebAPIErrorFactory.h>
28 #include <SecurityExceptions.h>
29 #include "JSCallHistoryEntry.h"
30 #include "JSRemoteParty.h"
31 #include "Converter.h"
34 using namespace WrtDeviceApis;
35 using namespace WrtDeviceApis::Commons;
36 using namespace WrtDeviceApis::CommonsJavaScript;
37 using namespace DeviceAPI::Common;
40 namespace CallHistory {
42 JSClassDefinition JSCallHistoryEntry::m_classInfo = {
44 kJSClassAttributeNone,
53 setProperty, // NULL, //SetProperty,
54 NULL, //DeleteProperty,
55 NULL, //GetPropertyNames,
56 NULL, //CallAsFunction,
57 NULL, //CallAsConstructor,
62 JSStaticValue JSCallHistoryEntry::m_property[] = {
63 { STR_ENTRY_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
64 { STR_CALL_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
65 { STR_TAGS, getProperty, NULL, kJSPropertyAttributeReadOnly },
66 { STR_REMOTE_PARTIES, getProperty, NULL, kJSPropertyAttributeReadOnly },
67 { STR_START_TIME, getProperty, NULL, kJSPropertyAttributeReadOnly },
68 { STR_DURATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
69 { STR_DIRECTION, getProperty, setProperty, kJSPropertyAttributeNone },
73 const JSClassRef JSCallHistoryEntry::getClassRef()
76 m_jsClassRef = JSClassCreate(&m_classInfo);
81 const JSClassDefinition* JSCallHistoryEntry::getClassInfo()
86 JSClassRef JSCallHistoryEntry::m_jsClassRef = JSClassCreate(JSCallHistoryEntry::getClassInfo());
88 JSObjectRef JSCallHistoryEntry::createJSObject(JSContextRef context,
89 const CallHistoryEntryProperties &entryInfo)
91 CallHistoryEntryPropertiesPtr callHistoryEntryProps(new CallHistoryEntryProperties(entryInfo));
92 JSCallHistoryEntryPriv *priv = new JSCallHistoryEntryPriv(context, CallHistoryEntryPropertiesPtr(callHistoryEntryProps));
94 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
96 return JSObjectMake(context, getClassRef(), priv);
99 CallHistoryEntryPropertiesPtr JSCallHistoryEntry::getCallHistoryEntry(JSContextRef context, JSValueRef value)
101 if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
102 Throw(WrtDeviceApis::Commons::ConversionException);
104 JSObjectRef object = JSValueToObject(context, value, NULL);
106 Throw(WrtDeviceApis::Commons::ConversionException);
108 JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
110 Throw(WrtDeviceApis::Commons::ConversionException);
112 return priv->getObject();
115 void JSCallHistoryEntry::initialize(JSContextRef context, JSObjectRef object)
119 void JSCallHistoryEntry::finalize(JSObjectRef object)
121 JSCallHistoryEntryPriv* priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
123 JSObjectSetPrivate(object, NULL);
128 JSValueRef JSCallHistoryEntry::getProperty(JSContextRef context,
130 JSStringRef propertyName,
131 JSValueRef* exception)
133 JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
135 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
139 CallHistoryEntryPropertiesPtr entryInfo = priv->getObject();
140 Converter convert(context);
142 if (JSStringIsEqualToUTF8CString(propertyName, STR_ENTRY_ID)) {
143 std::ostringstream stream;
144 stream << entryInfo->getEntryId();
145 std::string idStr = stream.str();
146 return convert.toJSValueRef(idStr);
147 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CALL_TYPE)) {
148 return convert.toJSValueRef(entryInfo->getCallType());
149 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_TAGS)) {
150 return convert.toJSValueRef(entryInfo->getTags(), context);
151 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTIES)) {
152 return convert.toJSValueRef(entryInfo->getRemoteParties(), context);
153 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_START_TIME)) {
154 return convert.toJSValueRef(entryInfo->getStartTime());
155 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
156 return convert.toJSValueRef(entryInfo->getDuration());
157 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DIRECTION)) {
158 return convert.toJSValueRef(entryInfo->getDirection());
159 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
160 return convert.toJSValueRef(entryInfo->getDuration());
162 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
163 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
164 } catch(const WrtDeviceApis::Commons::Exception& ex) {
165 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
170 bool JSCallHistoryEntry::setProperty(JSContextRef context,
172 JSStringRef propertyName,
174 JSValueRef* exception)
176 JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
178 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
181 Converter converter(context);
183 if (JSStringIsEqualToUTF8CString(propertyName, STR_DIRECTION)) {
184 CallHistoryEntryPropertiesPtr entryInfo = priv->getObject();
185 if (entryInfo != NULL) {
186 ICallHistoryEntryPtr callHistoryEntry(CallHistoryFactory::getInstance().getCallHistoryEntryObject());
187 std::string direction(converter.toString(value));
189 if (callHistoryEntry != NULL) {
190 if((entryInfo->getDirection().compare(STR_MISSED_NEW) == 0) && (direction.compare(STR_MISSED) == 0)) {
191 callHistoryEntry->setMarkSeen(entryInfo->getEntryId());
192 entryInfo->setDirection(STR_MISSED);
198 } catch (const WrtDeviceApis::Commons::Exception& ex) {
199 JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown error");
204 bool JSCallHistoryEntry::hasInstance(JSContextRef context,
205 JSObjectRef constructor,
206 JSValueRef possibleInstance,
207 JSValueRef* exception)
209 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());