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.
18 #include <CommonsJavaScript/Validator.h>
19 #include <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/JSCallbackManager.h>
21 #include <CommonsJavaScript/Utils.h>
22 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
23 #include <API/Call/ICallManager.h>
24 #include <API/Call/CallFactory.h>
25 #include <API/Call/CallDefine.h>
26 #include <API/Call/EventGetCallService.h>
27 #include <Tizen/Common/JSTizenExceptionFactory.h>
28 #include <Tizen/Common/JSTizenException.h>
29 #include <Tizen/Common/SecurityExceptions.h>
30 #include "JSCallManager.h"
31 #include "JSCallHistory.h"
32 #include "Converter.h"
33 #include "plugin_config.h"
37 using namespace WrtDeviceApis;
38 using namespace WrtDeviceApis::Commons;
39 using namespace WrtDeviceApis::CommonsJavaScript;
40 using namespace TizenApis::Api::Call;
41 using namespace TizenApis::Api::Account;
42 using namespace TizenApis::Commons;
47 JSClassRef JSCallManager::m_jsClassRef = NULL;
49 JSClassDefinition JSCallManager::m_classInfo =
52 kJSClassAttributeNone,
62 NULL, //deleteProperty,
63 NULL, //getPropertyNames,
70 JSStaticValue JSCallManager::m_property[] = {
71 { STR_HISTORY, getProperty, NULL, kJSPropertyAttributeReadOnly },
75 JSStaticFunction JSCallManager::m_function[] =
77 { "isCallInProgress", JSCallManager::isCallInProgress, kJSPropertyAttributeNone },
78 { "getCallServices", JSCallManager::getCallServices, kJSPropertyAttributeNone },
82 const JSClassRef JSCallManager::getClassRef()
85 m_jsClassRef = JSClassCreate(&m_classInfo);
90 const JSClassDefinition* JSCallManager::getClassInfo()
95 void JSCallManager::initialize(JSContextRef context, JSObjectRef object)
97 JSCallManagerPriv* priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(object));
98 assert(!priv && "Invalid object creation.");
99 ICallManagerPtr Call(CallFactory::getInstance().getCallObject() );
100 priv = new JSCallManagerPriv(context, Call);
101 if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
102 LogError("Object can't store private data.");
106 LogDebug("JSCallManager::initialize ");
109 void JSCallManager::finalize(JSObjectRef object)
111 JSCallManagerPriv* priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(object));
112 JSObjectSetPrivate(object, NULL);
116 JSValueRef JSCallManager::getProperty(JSContextRef context,
118 JSStringRef propertyName,
119 JSValueRef* exception)
121 JSCallManagerPriv *priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(object));
123 return JSValueMakeUndefined(context);
126 JSContextRef globalContext = priv->getContext();
128 Converter convert(context);
129 if(JSStringIsEqualToUTF8CString(propertyName, STR_HISTORY)) {
130 return JSCallHistory::createJSObject(globalContext, object);
132 } catch(const WrtDeviceApis::Commons::Exception& ex) {
133 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
135 return JSValueMakeUndefined(context);
138 bool JSCallManager::hasInstance(JSContextRef context, JSObjectRef constructor,
139 JSValueRef possibleInstance, JSValueRef* exception)
141 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
144 JSValueRef JSCallManager::isCallInProgress(JSContextRef context, JSObjectRef object,
145 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
146 JSValueRef* exception)
148 JSCallManagerPriv *priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(thisObject));
150 JSContextRef gContext = priv->getContext();
151 Converter converter(context);
154 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "private object is null");
158 AceSecurityStatus status = CALL_CHECK_ACCESS(
160 CALL_FUNCTION_API_ISCALLINPROGRESS);
162 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
164 ICallManagerPtr callManager(priv->getObject());
165 bool result = callManager->isCallInProgress();
166 return converter.toJSValueRef(result);
167 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
168 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
169 } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
170 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
171 } catch(const WrtDeviceApis::Commons::Exception& ex) {
172 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
175 return JSValueMakeUndefined(context);
178 JSValueRef JSCallManager::getCallServices(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
179 const JSValueRef arguments[], JSValueRef* exception)
181 if (argumentCount > 1) {
182 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
185 JSCallManagerPriv *priv = static_cast<JSCallManagerPriv*> (JSObjectGetPrivate(thisObject));
187 assert(priv && "Invalid private pointer.");
188 JSContextRef gContext = priv->getContext();
189 Converter converter(context);
192 AceSecurityStatus status = CALL_CHECK_ACCESS(
194 CALL_FUNCTION_API_GETCALLSERVICES);
196 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
198 CallServiceFilterPtr filter(new CallServiceFilter());
200 if (argumentCount == 0) {
201 StringArrayPtr tags(new StringArray());
202 tags->push_back(STR_CALL);
203 filter->setTags(tags);
205 if (!JSValueIsObject(context, arguments[0])) {
206 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : CallServiceFilter");
208 filter = converter.toCallServiceFilter(arguments[0]);
211 EventGetCallServicePtr event(new EventGetCallService());
213 event->setForSynchronousCall();
214 event->setFilter(filter);
216 ICallManagerPtr callManager(priv->getObject());
217 callManager->getCallService(event);
219 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
220 return converter.toJSValueRef(event->getResult(), gContext);
222 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException) {
223 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error : CallServiceFilter");
225 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
228 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
229 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
230 } catch(const WrtDeviceApis::Commons::UnsupportedException& ex) {
231 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
232 } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
233 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
234 } catch(const WrtDeviceApis::Commons::Exception& ex) {
235 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
238 return JSValueMakeUndefined(context);