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/EventGetCallService.h>
26 #include <Tizen/Common/JSTizenExceptionFactory.h>
27 #include <Tizen/Common/JSTizenException.h>
28 #include <Tizen/Common/SecurityExceptions.h>
29 #include "JSCallManager.h"
30 #include "JSCallHistory.h"
31 #include "Converter.h"
32 #include "plugin_config.h"
36 using namespace WrtDeviceApis;
37 using namespace WrtDeviceApis::Commons;
38 using namespace WrtDeviceApis::CommonsJavaScript;
39 using namespace TizenApis::Api::Call;
40 using namespace TizenApis::Api::Account;
41 using namespace TizenApis::Commons;
46 JSClassRef JSCallManager::m_jsClassRef = NULL;
48 JSClassDefinition JSCallManager::m_classInfo =
51 kJSClassAttributeNone,
61 NULL, //deleteProperty,
62 NULL, //getPropertyNames,
69 JSStaticValue JSCallManager::m_property[] = {
70 { "history", getProperty, NULL, kJSPropertyAttributeReadOnly },
74 JSStaticFunction JSCallManager::m_function[] =
76 { "isCallInProgress", JSCallManager::isCallInProgress, kJSPropertyAttributeNone },
77 { "getCallServices", JSCallManager::getCallServices, kJSPropertyAttributeNone },
81 const JSClassRef JSCallManager::getClassRef()
84 m_jsClassRef = JSClassCreate(&m_classInfo);
89 const JSClassDefinition* JSCallManager::getClassInfo()
94 void JSCallManager::initialize(JSContextRef context, JSObjectRef object)
96 JSCallManagerPriv* priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(object));
97 assert(!priv && "Invalid object creation.");
98 ICallManagerPtr Call(CallFactory::getInstance().getCallObject() );
99 priv = new JSCallManagerPriv(context, Call);
100 if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
101 LogError("Object can't store private data.");
105 LogDebug("JSCallManager::initialize ");
108 void JSCallManager::finalize(JSObjectRef object)
110 JSCallManagerPriv* priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(object));
111 JSObjectSetPrivate(object, NULL);
115 JSValueRef JSCallManager::getProperty(JSContextRef context,
117 JSStringRef propertyName,
118 JSValueRef* exception)
120 JSCallManagerPriv *priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(object));
122 return JSValueMakeUndefined(context);
125 JSContextRef globalContext = priv->getContext();
127 Converter convert(context);
128 if(JSStringIsEqualToUTF8CString(propertyName, "history")) {
129 return JSCallHistory::createJSObject(globalContext, object);
131 } catch(const WrtDeviceApis::Commons::Exception& ex) {
132 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
134 return JSValueMakeUndefined(context);
137 bool JSCallManager::hasInstance(JSContextRef context, JSObjectRef constructor,
138 JSValueRef possibleInstance, JSValueRef* exception)
140 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
143 JSValueRef JSCallManager::isCallInProgress(JSContextRef context, JSObjectRef object,
144 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
145 JSValueRef* exception)
147 JSCallManagerPriv *priv = static_cast<JSCallManagerPriv*>(JSObjectGetPrivate(thisObject));
149 JSContextRef gContext = priv->getContext();
150 Converter converter(context);
153 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "private object is null");
157 AceSecurityStatus status = CALL_CHECK_ACCESS(
159 CALL_FUNCTION_API_ISCALLINPROGRESS);
161 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
163 ICallManagerPtr callManager(priv->getObject());
164 bool result = callManager->isCallInProgress();
165 return converter.toJSValueRef(result);
166 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
167 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
168 } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
169 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
170 } catch(const WrtDeviceApis::Commons::Exception& ex) {
171 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
174 return JSValueMakeUndefined(context);
177 JSValueRef JSCallManager::getCallServices(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
178 const JSValueRef arguments[], JSValueRef* exception)
180 if (argumentCount > 1) {
181 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
184 JSCallManagerPriv *priv = static_cast<JSCallManagerPriv*> (JSObjectGetPrivate(thisObject));
186 assert(priv && "Invalid private pointer.");
187 JSContextRef gContext = priv->getContext();
188 Converter converter(context);
191 AceSecurityStatus status = CALL_CHECK_ACCESS(
193 CALL_FUNCTION_API_GETCALLSERVICES);
195 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
197 CallServiceFilterPtr filter(new CallServiceFilter());
199 if (argumentCount == 0) {
200 StringArrayPtr tags(new StringArray());
201 tags->push_back("call");
202 filter->setTags(tags);
204 if (!JSValueIsObject(context, arguments[0])) {
205 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : CallServiceFilter");
207 filter = converter.toCallServiceFilter(arguments[0]);
210 EventGetCallServicePtr event(new EventGetCallService());
212 event->setForSynchronousCall();
213 event->setFilter(filter);
215 ICallManagerPtr callManager(priv->getObject());
216 callManager->getCallService(event);
218 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
219 return converter.toJSValueRef(event->getResult(), gContext);
221 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnsupportedException) {
222 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not supported value");
224 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
227 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
228 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
229 } catch(const WrtDeviceApis::Commons::UnsupportedException& ex) {
230 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
231 } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
232 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
233 } catch(const WrtDeviceApis::Commons::Exception& ex) {
234 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
237 return JSValueMakeUndefined(context);