diff options
Diffstat (limited to 'mobile_src/Content/IContentManager.cpp')
-rwxr-xr-x | mobile_src/Content/IContentManager.cpp | 319 |
1 files changed, 319 insertions, 0 deletions
diff --git a/mobile_src/Content/IContentManager.cpp b/mobile_src/Content/IContentManager.cpp new file mode 100755 index 0000000..5d9a40f --- /dev/null +++ b/mobile_src/Content/IContentManager.cpp @@ -0,0 +1,319 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include <Commons/StringUtils.h> +#include <Commons/ThreadPool.h> +#include "IContentManager.h" +#include "ContentListener.h" +#include "ContentImage.h" +#include "ContentMedia.h" +#include "ContentVideo.h" +#include "ContentAudio.h" +#include "ContentManager.h" +#include "ContentUtility.h" +#include <Logger.h> + +namespace DeviceAPI { +namespace Content { + + +IMediacontentManager::IMediacontentManager() : + WrtDeviceApis::Commons::EventRequestReceiver<IEventFindFolder>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD), + WrtDeviceApis::Commons::EventRequestReceiver<IEventBrowseFolder>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD), + WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMedia>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD), + WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMediaItems>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD) + +{ +} + +IMediacontentManager::~IMediacontentManager() +{ +} + +void IMediacontentManager::findFolder(IEventFindFolderPtr &ptr) +{ + WrtDeviceApis::Commons::EventRequestReceiver<IEventFindFolder>::PostRequest(ptr); +} + +void IMediacontentManager::updateMedia(IEventUpdateMediaPtr &ptr) +{ + WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMedia>::PostRequest(ptr); +} + +void IMediacontentManager::browseFolder(IEventBrowseFolderPtr &ptr) +{ + WrtDeviceApis::Commons::EventRequestReceiver<IEventBrowseFolder>::PostRequest(ptr); +} + +void IMediacontentManager::updateMediaItems(IEventUpdateMediaItemsPtr &ptr) +{ + WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMediaItems>::PostRequest(ptr); +} + + +struct scanCallbackData +{ + std::string path; + int result; + scanCompletedCallback callback; + void *user_data; +}; + +static gboolean _scan_file_completed_cb(void *user_data) +{ + + scanCallbackData *data = static_cast<scanCallbackData*>(user_data); + + if(data != NULL) + { + string path = data->path; + void* _user_data = data->user_data; + scanCompletedCallback _callback = data->callback; + + std::string err_msg; + + if( data->result == MEDIA_CONTENT_ERROR_NONE) + { + err_msg = ""; + } + else if( data->result == MEDIA_CONTENT_ERROR_OUT_OF_MEMORY) + { + err_msg = "scanning is failed by out of memory"; + } + else if( data->result == MEDIA_CONTENT_ERROR_INVALID_OPERATION) + { + err_msg = "scanning is failed by invalid operation"; + } + else if( data->result == MEDIA_CONTENT_ERROR_DB_FAILED) + { + err_msg = "scanning is failed because db operation is failed"; + } + else if( data->result == MEDIA_CONTENT_ERROR_DB_BUSY) + { + err_msg = "scanning is failed because db operation is failed"; + } + else + { + err_msg = "scanning is failed by unknown reason"; + } + _callback(err_msg, path, _user_data); + + delete data; + } + return false; +} + + +static void _scan_file_thread(void *user_data, Ecore_Thread *thread){ + scanCallbackData *data = static_cast<scanCallbackData*>(user_data); + data->result = media_content_scan_file(data->path.c_str()); + g_idle_add(_scan_file_completed_cb, data); +} + +bool IMediacontentManager::scanFile(scanCompletedCallback callback, std::string path, void* user_data) +{ + bool ret = false; + if( !path.empty() ) + { + scanCallbackData *data = new scanCallbackData(); + data->path = path; + data->callback = callback; + data->user_data = user_data; + + ecore_thread_run( _scan_file_thread, NULL, NULL, static_cast<void*>(data)); + ret = true; + + } + else + { + ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "URI is not available"); + } + return ret; +} + +static bool mediaItemCallback(media_info_h info, void* user_data) +{ + media_content_type_e type; + + if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) ) + { + if ( type == MEDIA_CONTENT_TYPE_IMAGE) + { + MediacontentManager::readImageFromMediaInfo(info, static_cast<MediacontentImage*>(user_data)); + } + else if ( type == MEDIA_CONTENT_TYPE_VIDEO) + { + MediacontentManager::readVideoFromMediaInfo(info, static_cast<MediacontentVideo*>(user_data)); + } + else if ( type == MEDIA_CONTENT_TYPE_MUSIC || type == MEDIA_CONTENT_TYPE_SOUND) + { + MediacontentManager::readMusicFromMediaInfo(info, static_cast<MediacontentAudio*>(user_data)); + } + else if( type == MEDIA_CONTENT_TYPE_OTHERS) + { + MediacontentManager::readCommonDataFromMediaInfo(info, static_cast<MediacontentMedia*>(user_data)); + } + + } + return false; +} + +static void content_notification_cb( + media_content_error_e error, + int pid, + media_content_db_update_item_type_e update_item, + media_content_db_update_type_e update_type, + media_content_type_e media_type, + char *uuid, + char *path, + char *mime_type, + void *user_data) +{ + + ContentListener *listener = static_cast<ContentListener*>(user_data); + std::string err_msg; + if( error == MEDIA_CONTENT_ERROR_NONE) + { + err_msg = ""; + if( update_item == MEDIA_ITEM_FILE) + { + string condition = "MEDIA_ID=\""; + condition += uuid; + condition += "\""; + + MediacontentMedia *p_content; + if(update_type == MEDIA_CONTENT_INSERT) + { + filter_h filter = NULL; + if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter)) + { + media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT); + + if(media_type == MEDIA_CONTENT_TYPE_IMAGE) + { + p_content = new MediacontentImage(); + } + else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + p_content = new MediacontentVideo(); + } + else if(media_type == MEDIA_CONTENT_TYPE_SOUND || media_type == MEDIA_CONTENT_TYPE_MUSIC) + { + p_content = new MediacontentAudio(); + } + else + { + p_content = new MediacontentMedia(); + } + + if( MEDIA_CONTENT_ERROR_NONE == media_info_foreach_media_from_db(filter,mediaItemCallback,(void*)p_content)) + { + MediacontentMediaPtr result(p_content); + listener->oncontentadded(result); + } + media_filter_destroy(filter); + } + } + else if(update_type == MEDIA_CONTENT_UPDATE) + { + + filter_h filter = NULL; + if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter)) + { + media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT); + + if(media_type == MEDIA_CONTENT_TYPE_IMAGE) + { + p_content = new MediacontentImage(); + } + else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) + { + p_content = new MediacontentVideo(); + } + else if(media_type == MEDIA_CONTENT_TYPE_SOUND || media_type == MEDIA_CONTENT_TYPE_MUSIC) + { + p_content = new MediacontentAudio(); + } + else + { + p_content = new MediacontentMedia(); + } + + if( MEDIA_CONTENT_ERROR_NONE == media_info_foreach_media_from_db(filter,mediaItemCallback,(void*)p_content)) + { + MediacontentMediaPtr result(p_content); + listener->oncontentupdated(result); + } + media_filter_destroy(filter); + } + + } + else if(update_type == MEDIA_CONTENT_DELETE) + { + listener->oncontentremoved(uuid); + } + } + } + else if( error == MEDIA_CONTENT_ERROR_OUT_OF_MEMORY) + { + err_msg = "scanning is failed by out of memory"; + } + else if( error == MEDIA_CONTENT_ERROR_INVALID_OPERATION) + { + err_msg = "scanning is failed by invalid operation"; + } + else if( error == MEDIA_CONTENT_ERROR_DB_FAILED) + { + err_msg = "scanning is failed because db operation is failed"; + } + else if( error == MEDIA_CONTENT_ERROR_DB_BUSY) + { + err_msg = "scanning is failed because db operation is failed"; + } + else + { + err_msg = "scanning is failed by unknown reason"; + } +} + +bool IMediacontentManager::setListener( void* user_data) +{ + bool ret = false; + if(media_content_unset_db_updated_cb() == MEDIA_CONTENT_ERROR_NONE) + { + if(media_content_set_db_updated_cb(content_notification_cb,user_data) == MEDIA_CONTENT_ERROR_NONE) + { + ret = true; + } + } + return ret; +} + +bool IMediacontentManager::unsetListener() +{ + bool ret = false; + + if(media_content_unset_db_updated_cb() == MEDIA_CONTENT_ERROR_NONE) + { + ret = true; + } + return ret; +} + + +} +} |