2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <JavaScriptCore/JavaScript.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 "CallHistoryStaticController.h"
25 #include "Converter.h"
28 using namespace WrtDeviceApis::Commons;
29 using namespace WrtDeviceApis::CommonsJavaScript;
32 namespace CallHistory {
34 CallHistoryStaticController& CallHistoryStaticController::getInstance()
36 static CallHistoryStaticController controller;
40 CallHistoryStaticController::CallHistoryStaticController() :
41 WrtDeviceApis::Commons::EventListener<EventCallHistoryListener>(ThreadEnum::NULL_THREAD)
45 void CallHistoryStaticController::onAnswerReceived(const EventCallHistoryListenerPtr& event)
47 EventCallHistoryListenerPrivateDataPtr multiCallbacks =
48 DPL::DynamicPointerCast<EventCallHistoryListenerPrivateData>(event->getPrivateData());
50 if (multiCallbacks == NULL) {
54 if ((multiCallbacks->getOnAdded() == NULL) || (multiCallbacks->getOnChanged() == NULL)) {
58 JSCallbackManagerPtr defaultCbm = multiCallbacks->getOnAdded();
59 JSContextRef context = defaultCbm->getContext();
60 Converter converter(context);
63 switch (event->getResultState()) {
64 case EventCallHistoryListener::ADDED :
66 JSValueRef result = converter.toJSValueRef(event->getResult(), context);
67 multiCallbacks->getOnAdded()->callOnSuccess(result);
70 case EventCallHistoryListener::CHANGED :
72 JSValueRef result = converter.toJSValueRef(event->getResult(), context);
73 multiCallbacks->getOnChanged()->callOnSuccess(result);
76 case EventCallHistoryListener::REMOVED :
78 JSValueRef result = converter.toJSValueRef(event->getRemoveResult(), context);
79 multiCallbacks->getOnRemoved()->callOnSuccess(result);
83 } catch(ConversionException) {
84 LoggerE("Conversion exception while processing EventCallHistoryListener");