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 "ResponseDispatcher.h"
20 #include <dpl/log/log.h>
21 #include <dpl/assert.h>
23 #include <Commons/Exception.h>
24 #include <Commons/IEvent.h>
25 #include <CommonsJavaScript/JSUtils.h>
26 #include <CommonsJavaScript/JSCallbackManager.h>
27 #include <Tizen/Common/JSTizenExceptionFactory.h>
28 #include <Tizen/Common/JSTizenException.h>
29 #include "JSCallHistory.h"
30 #include "Converter.h"
32 using namespace WrtDeviceApis::Commons;
33 using namespace WrtDeviceApis::CommonsJavaScript;
34 using namespace TizenApis::Commons;
38 ResponseDispatcher& ResponseDispatcher::getInstance()
40 static ResponseDispatcher dispatcher;
44 ResponseDispatcher::ResponseDispatcher() :
45 EventAnswerReceiver<Api::Call::EventFindCallHistory>(ThreadEnum::NULL_THREAD),
46 EventAnswerReceiver<Api::Call::EventRemoveBatch>(ThreadEnum::NULL_THREAD)
50 void ResponseDispatcher::OnAnswerReceived(const Api::Call::EventFindCallHistoryPtr& event)
52 DPL::SharedPtr<JSCallbackManager> data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
55 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
56 Converter converter(data->getContext());
58 data->callOnSuccess(converter.toJSValueRef(event->getResult(), data->getContext()));
59 } catch(WrtDeviceApis::Commons::ConversionException) {
60 data->callOnError(JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error"));
63 JSObjectRef jsException = NULL;
64 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
65 jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
67 jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
69 data->callOnError(jsException);
73 void ResponseDispatcher::OnAnswerReceived(const Api::Call::EventRemoveBatchPtr& event)
75 DPL::SharedPtr<JSCallbackManager> data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
78 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
80 data->callOnSuccess();
81 } Catch(WrtDeviceApis::Commons::ConversionException) {
82 data->callOnError(JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error"));
85 JSObjectRef jsException = NULL;
86 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
87 jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
89 jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
91 data->callOnError(jsException);