Update change log and spec for wrt-plugins-tizen_0.4.13
[framework/web/wrt-plugins-tizen.git] / src / Callhistory / CallHistoryStaticController.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17  
18 #include <JavaScriptCore/JavaScript.h>
19 #include <dpl/log/log.h>
20 #include <dpl/shared_ptr.h>
21 #include <Commons/IEvent.h>
22 #include <CommonsJavaScript/PrivateObject.h>
23 #include <CommonsJavaScript/JSCallbackManager.h>
24 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
25 #include "CallHistoryStaticController.h"
26 #include "Converter.h"
27
28 using namespace WrtDeviceApis::Commons;
29 using namespace WrtDeviceApis::CommonsJavaScript;
30
31 namespace DeviceAPI {
32 namespace CallHistory {
33
34 CallHistoryStaticController& CallHistoryStaticController::getInstance()
35 {
36     static CallHistoryStaticController controller;
37     return controller;
38 }
39
40 CallHistoryStaticController::CallHistoryStaticController() :
41         WrtDeviceApis::Commons::EventListener<EventCallHistoryListener>(ThreadEnum::NULL_THREAD)
42 {
43 }
44
45 void CallHistoryStaticController::onAnswerReceived(const EventCallHistoryListenerPtr& event)
46 {
47         EventCallHistoryListenerPrivateDataPtr multiCallbacks = 
48                 DPL::DynamicPointerCast<EventCallHistoryListenerPrivateData>(event->getPrivateData());
49
50         if (multiCallbacks == NULL) {
51                 return;
52         }
53
54         if ((multiCallbacks->getOnAdded() == NULL)  || (multiCallbacks->getOnChanged() == NULL)) {
55                 return; 
56         }
57
58         JSCallbackManagerPtr defaultCbm = multiCallbacks->getOnAdded(); 
59         JSContextRef context = defaultCbm->getContext();
60         Converter converter(context);
61
62         try {           
63                 switch (event->getResultState()) {
64                 case EventCallHistoryListener::ADDED :
65                         {
66                                 JSValueRef result = converter.toJSValueRef(event->getResult(), context);
67                                 multiCallbacks->getOnAdded()->callOnSuccess(result);
68                                 break;
69                         }
70                 case EventCallHistoryListener::CHANGED :
71                         {
72                                 JSValueRef result = converter.toJSValueRef(event->getResult(), context);
73                                 multiCallbacks->getOnChanged()->callOnSuccess(result);
74                                 break;                  
75                         }
76                 case EventCallHistoryListener::REMOVED :
77                         {
78                                 JSValueRef result = converter.toJSValueRef(event->getRemoveResult(), context);
79                                 multiCallbacks->getOnRemoved()->callOnSuccess(result);
80                                 break;
81                         }
82                 }
83         } catch(ConversionException) {
84                 LogError("Conversion exception while processing EventCallHistoryListener");
85         }
86 }
87
88 }
89 }