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.
17 #include <JavaScriptCore/JavaScript.h>
18 #include <dpl/log/log.h>
19 #include <dpl/shared_ptr.h>
20 #include <Commons/IEvent.h>
21 #include <CommonsJavaScript/PrivateObject.h>
22 #include <CommonsJavaScript/JSCallbackManager.h>
23 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
24 #include "CallStaticController.h"
25 #include "Converter.h"
27 using namespace TizenApis::Api::Call;
28 using namespace WrtDeviceApis::Commons;
29 using namespace WrtDeviceApis::CommonsJavaScript;
33 CallStaticController& CallStaticController::getInstance()
35 static CallStaticController controller;
39 CallStaticController::CallStaticController() :
40 WrtDeviceApis::Commons::EventListener<EventCallHistoryListener>(ThreadEnum::NULL_THREAD)
44 void CallStaticController::onAnswerReceived(const EventCallHistoryListenerPtr& event)
46 EventCallHistoryListenerPrivateDataPtr multiCallbacks =
47 DPL::DynamicPointerCast<EventCallHistoryListenerPrivateData>(event->getPrivateData());
49 assert(multiCallbacks != NULL);
50 assert(multiCallbacks->getOnAdded() != NULL);
51 assert(multiCallbacks->getOnChanged() != NULL);
53 JSCallbackManagerPtr defaultCbm = multiCallbacks->getOnAdded();
54 JSContextRef context = defaultCbm->getContext();
55 Converter converter(context);
58 JSValueRef result = converter.toJSValueRef(event->getResult(), context);
60 switch (event->getResultState()) {
61 case EventCallHistoryListener::ADDED :
62 multiCallbacks->getOnAdded()->callOnSuccess(result);
64 case EventCallHistoryListener::CHANGED :
65 multiCallbacks->getOnChanged()->callOnSuccess(result);
68 } catch(ConversionException) {
69 LogError( "Conversion exception while processing EventCallHistoryListener");