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.
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"
29 namespace Mediacontent {
32 MediacontentManagerController& MediacontentManagerController::getInstance()
34 static MediacontentManagerController instance;
39 MediacontentManagerController::MediacontentManagerController():
40 EventFindMediaAnswerReceiver(ThreadEnum::NULL_THREAD),
41 EventFindFolderAnswerReceiver(ThreadEnum::NULL_THREAD)
43 LogDebug("create a MediacontentManagerController");
46 MediacontentManagerController::~MediacontentManagerController()
53 void MediacontentManagerController::OnAnswerReceived(const IEventFindMediaPtr &event)
56 LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
58 JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
61 LogError("no callback manager");
66 if (event->getResult())
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);
77 LogError("error during processing answer");
79 JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
80 cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
81 cbm->callOnError(errorObject);
87 void MediacontentManagerController::OnAnswerReceived(const IEventFindFolderPtr &event)
90 LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
92 JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
95 LogError("no callback manager");
100 if (event->getResult())
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);
111 LogError("error during processing answer");
113 JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
114 cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
115 cbm->callOnError(errorObject);