9ee9874fe5f0a8883f2c7053831c70e567282a99
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Call / JSCallHistoryEntry.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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. 
15  */
16
17
18 #include <cassert>
19 #include <memory>
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"
27
28 namespace TizenApis {
29 namespace Tizen1_0 {
30
31 using namespace WrtDeviceApis;
32 using namespace WrtDeviceApis::Commons;
33 using namespace WrtDeviceApis::CommonsJavaScript;
34 using namespace Api::Call;
35
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"
52
53 JSClassDefinition JSCallHistoryEntry::m_classInfo = {
54         0,
55         kJSClassAttributeNone,
56         "callhistoryentry",
57         0,
58         m_property,
59         0,
60         initialize,
61         finalize,
62         NULL,     //HasProperty,
63         getProperty,
64         NULL,     //SetProperty,
65         NULL,     //DeleteProperty,
66         NULL,     //GetPropertyNames,
67         NULL,     //CallAsFunction,
68         NULL,     //CallAsConstructor,
69         hasInstance,
70         NULL,     //ConvertToType
71 };
72
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 },
90         { 0, 0, 0, 0 }
91 };
92
93 const JSClassRef JSCallHistoryEntry::getClassRef()
94 {
95         if (!m_jsClassRef) {
96                 m_jsClassRef = JSClassCreate(&m_classInfo);
97         }
98         return m_jsClassRef;
99 }
100
101 const JSClassDefinition* JSCallHistoryEntry::getClassInfo()
102 {
103         return &m_classInfo;
104 }
105
106 JSClassRef JSCallHistoryEntry::m_jsClassRef = JSClassCreate(JSCallHistoryEntry::getClassInfo());
107
108 JSObjectRef JSCallHistoryEntry::createJSObject(JSContextRef context,
109         const CallHistoryEntryProperties &callInfo)
110 {
111         std::auto_ptr<CallHistoryEntryProperties> callHistoryEntryProps(new CallHistoryEntryProperties(callInfo));
112         JSCallHistoryEntryPriv *priv = new JSCallHistoryEntryPriv(context, callHistoryEntryProps.get());
113         callHistoryEntryProps.release();
114         if (!priv) {
115                 ThrowMsg(Commons::NullPointerException, "Can not new an object");
116         }
117         return JSObjectMake(context, getClassRef(), priv);
118 }
119
120 void JSCallHistoryEntry::initialize(JSContextRef context, JSObjectRef object)
121 {
122 }
123
124 void JSCallHistoryEntry::finalize(JSObjectRef object)
125 {
126         JSCallHistoryEntryPriv* priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
127         JSObjectSetPrivate(object, NULL);
128         delete priv;
129 }
130
131 JSValueRef JSCallHistoryEntry::getProperty(JSContextRef context,
132         JSObjectRef object,
133         JSStringRef propertyName,
134         JSValueRef* exception)
135 {
136         JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
137         assert(priv && "Private object not set.");
138
139         try {
140                 CallHistoryEntryProperties *callInfo = priv->getObject();
141                 Converter convert(context);
142
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());
177                 }
178         } catch(Commons::Exception) {
179                 LogWarning("trying to get incorrect value");
180         }
181         return JSValueMakeUndefined(context);
182 }
183
184 bool JSCallHistoryEntry::hasInstance(JSContextRef context,
185         JSObjectRef constructor,
186         JSValueRef possibleInstance,
187         JSValueRef* exception)
188 {
189         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
190 }
191 }
192 }
193