Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Mediacontent / MediacontentController.cpp
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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. 
15 */
16
17
18
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/JSCallbackManager.h>
21 #include <Tizen/Common/JSTizenException.h>
22 #include <Tizen/Common/JSTizenExceptionFactory.h>
23 #include "MediacontentController.h"
24 #include "MediaConverter.h"
25 #include "JSMediacontent.h"
26
27 namespace TizenApis {
28 namespace Tizen1_0 {
29 namespace Mediacontent {
30
31
32 MediacontentManagerController& MediacontentManagerController::getInstance()
33 {
34     static MediacontentManagerController instance;
35     return instance;
36 }
37
38
39 MediacontentManagerController::MediacontentManagerController():
40         EventFindMediaAnswerReceiver(ThreadEnum::NULL_THREAD),
41         EventFindFolderAnswerReceiver(ThreadEnum::NULL_THREAD)
42 {
43         LogDebug("create a MediacontentManagerController");
44 }
45
46 MediacontentManagerController::~MediacontentManagerController() 
47 {
48         LogDebug("<<<");
49         LogDebug(">>>");
50 }
51
52
53 void MediacontentManagerController::OnAnswerReceived(const IEventFindMediaPtr &event)
54 {
55
56         LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
57
58     JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
59     if (!cbm) 
60         {
61         LogError("no callback manager");
62         return;
63     }
64     Try
65     {
66         if (event->getResult()) 
67                 {
68             MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext());
69             const std::vector<MediacontentMediaPtr> &results = event->getMedia();
70             JSValueRef result = converter->toJSValueRef(results);
71             cbm->callOnSuccess(result);
72             return;
73         }
74     }
75     Catch(Exception)
76     {
77         LogError("error during processing answer");
78     }
79     JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
80             cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
81     cbm->callOnError(errorObject);
82
83 }
84
85
86
87 void MediacontentManagerController::OnAnswerReceived(const IEventFindFolderPtr &event)
88 {
89
90         LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
91
92     JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
93     if (!cbm) 
94         {
95         LogError("no callback manager");
96         return;
97     }
98     Try
99     {
100         if (event->getResult()) 
101                 {
102             MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext());
103             const std::vector<MediacontentFolderPtr> &results = event->getFolder();
104             JSValueRef result = converter->toJSValueRef(results);
105             cbm->callOnSuccess(result);
106             return;
107         }
108     }
109     Catch(Exception)
110     {
111         LogError("error during processing answer");
112     }
113     JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
114             cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
115     cbm->callOnError(errorObject);
116
117 }
118
119
120 }
121 }
122 }
123