upload tizen1.0 source
[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 MediacontentManagerController::MediacontentManagerController():
39         EventFindMediaAnswerReceiver(ThreadEnum::NULL_THREAD),
40         EventBrowseFolderAnswerReceiver(ThreadEnum::NULL_THREAD),       
41         EventUpdateMediaItemsAnswerReceiver(ThreadEnum::NULL_THREAD),           
42         EventFindFolderAnswerReceiver(ThreadEnum::NULL_THREAD)
43 {
44         LogDebug("create a MediacontentManagerController");
45 }
46
47 MediacontentManagerController::~MediacontentManagerController() 
48 {
49         LogDebug("<<<");
50         LogDebug(">>>");
51 }
52
53
54 void MediacontentManagerController::OnAnswerReceived(const IEventFindMediaPtr &event)
55 {
56
57         LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
58
59     JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
60     if (!cbm) 
61         {
62         LogError("no callback manager");
63         return;
64     }
65     Try
66     {
67         if (event->getResult()) 
68                 {
69             MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext());
70             const std::vector<MediacontentMediaPtr> &results = event->getMedia();
71             JSValueRef result = converter->toJSValueRef(results);
72             cbm->callOnSuccess(result);
73         }
74         else
75         {
76                         JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
77                                         cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
78                         cbm->callOnError(errorObject);
79         }        
80         return;
81     }
82     Catch(Exception)
83     {
84         LogError("error during processing answer");
85     }
86 }
87
88 void MediacontentManagerController::OnAnswerReceived(const IEventUpdateMediaItemsPtr &event)
89 {
90
91         LogDebug("MediacontentManagerController::IEventUpdateMediaItemsPtr:entered");
92
93     JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
94     if(!cbm) 
95         {
96         LogError("no callback manager");
97         return;
98     }
99     Try
100     {
101         if (event->getResult()) 
102                 {
103                         cbm->callOnSuccess();
104         }
105         else
106         {
107                         JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
108                                         cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
109                         cbm->callOnError(errorObject);
110         }
111         return;
112     }
113     Catch(Exception)
114     {
115         LogError("error during processing answer");
116     }
117 }
118
119
120 void MediacontentManagerController::OnAnswerReceived(const IEventBrowseFolderPtr &event)
121 {
122
123         LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
124
125     JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
126     if (!cbm) 
127         {
128         LogError("no callback manager");
129         return;
130     }
131     Try
132     {
133         if (event->getResult()) 
134                 {
135             MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext());
136             const std::vector<MediacontentMediaPtr> &results = event->getMedia();
137             JSValueRef result = converter->toJSValueRef(results);
138             cbm->callOnSuccess(result);
139         }
140         else
141         {
142                         JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
143                                         cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
144                         cbm->callOnError(errorObject);
145         }        
146                 return;
147     }
148     Catch(Exception)
149     {
150         LogError("error during processing answer");
151     }
152 }
153
154
155
156 void MediacontentManagerController::OnAnswerReceived(const IEventFindFolderPtr &event)
157 {
158
159         LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
160
161     JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
162     if (!cbm) 
163         {
164         LogError("no callback manager");
165         return;
166     }
167     Try
168     {
169         if (event->getResult()) 
170                 {
171             MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext());
172             const std::vector<MediacontentFolderPtr> &results = event->getFolder();
173             JSValueRef result = converter->toJSValueRef(results);
174             cbm->callOnSuccess(result);
175         }
176         else
177         {
178                         JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
179                                         cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
180                         cbm->callOnError(errorObject);
181         }        
182                 return;
183     }
184     Catch(Exception)
185     {
186         LogError("error during processing answer");
187     }
188
189 }
190
191
192 }
193 }
194 }
195