2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <media_content.h>
22 #include <Commons/Regex.h>
23 #include <Commons/StringUtils.h>
24 #include <CommonsJavaScript/Converter.h>
26 #include "ContentManager.h"
27 #include "ContentFilterValidator.h"
28 #include "ContentUtility.h"
31 using namespace WrtDeviceApis::Commons;
38 int MediacontentManager::m_instanceCount = 0;
40 MediacontentManager::MediacontentManager()
44 //protect for pararel execution
45 DPL::Mutex::ScopedLock mx(&m_constructorMutex);
46 if (m_instanceCount == 0)
48 //when it is first instance then connect to media content service.
49 if( MEDIA_CONTENT_ERROR_NONE != media_content_connect())
51 LoggerD("Media Content Service Connect Fail...");
55 //increase counter of instances
60 MediacontentManager::~MediacontentManager()
62 LoggerD("entered : " << m_instanceCount);
63 DPL::Mutex::ScopedLock mx(&m_constructorMutex);
64 //decrease counter of instances
66 if (m_instanceCount == 0)
68 LoggerD("instance Count is zero ");
69 //when it is last instance then clse connection to database
70 if ( MEDIA_CONTENT_ERROR_NONE != media_content_disconnect())
72 LoggerD("Media Content Service Disconnect Fail...");
78 void MediacontentManager::OnRequestReceived(const IEventGetMediacontentPtr &event)
80 LoggerD( "OnRequestReceived::entered");
81 //IMediacontentPtr newMediacontent(new Mediacontent());
82 //IMediacontentPtr newMediacontent = MediacontentFactory::getInstance().createMediacontentObject();
86 LoggerD( "get Mediacontent \n");
87 // event->setMediacontent(m_mediaContent);
88 event->setResult(true);
92 LogError("error occuered during obtaining data");
93 event->setResult(false);
95 event->setCancelAllowed(true);
99 tm* MediacontentManager::toDateTm(time_t date)
101 tm *tm_date = (struct tm *)calloc(1, sizeof(struct tm));
103 localtime_r(&date, tm_date);
108 media_content_orientation_e MediacontentManager::convertToOrientation(string orientation)
110 media_content_orientation_e ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
112 if ( orientation.compare("NORMAL")==0)
114 ret = MEDIA_CONTENT_ORIENTATION_NORMAL;
116 else if (orientation.compare("FLIP_HORIZONTAL")==0)
118 ret = MEDIA_CONTENT_ORIENTATION_HFLIP;
120 else if (orientation.compare("ROTATE_180")==0)
122 ret = MEDIA_CONTENT_ORIENTATION_ROT_180;
124 else if (orientation.compare("FLIP_VERTICAL")==0)
126 ret = MEDIA_CONTENT_ORIENTATION_VFLIP;
128 else if (orientation.compare("TRANSPOSE")==0)
130 ret = MEDIA_CONTENT_ORIENTATION_TRANSPOSE;
132 else if (orientation.compare("ROTATE_90")==0)
134 ret = MEDIA_CONTENT_ORIENTATION_ROT_90;
136 else if (orientation.compare("TRANSVERSE")==0)
138 ret =MEDIA_CONTENT_ORIENTATION_TRANSVERSE;
140 else if (orientation.compare("ROTATE_270")==0)
142 ret =MEDIA_CONTENT_ORIENTATION_ROT_270;
146 LoggerD("wrong value.");
147 ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
153 void MediacontentManager::convertToPlatformFolder(media_folder_h media_folder, MediacontentFolderPtr& newFolder)
157 media_content_storage_e storageType;
159 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_folder_id(media_folder, &tmpStr))
163 LoggerD("Folder UUID : " << tmpStr);
164 newFolder->setFolderUUID(tmpStr);
170 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_path(media_folder, &tmpStr))
174 LoggerD("Folder path : " << tmpStr);
175 newFolder->setFolderPath(ContentUtility::convertPathToUri(tmpStr));
181 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_name(media_folder, &tmpStr))
185 LoggerD("Folder name : " << tmpStr);
186 newFolder->setFolderName(tmpStr);
192 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_modified_time(media_folder, &date))
194 LoggerD("get Modified Time ");
195 newFolder->setFolderModifiedDate(toDateTm(date));
198 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_storage_type(media_folder, &storageType))
200 LoggerD("storage Type=" << storageType);
202 if(storageType == MEDIA_CONTENT_STORAGE_INTERNAL )
206 else if( storageType == MEDIA_CONTENT_STORAGE_EXTERNAL)
214 newFolder->setFolderStorageType(type);
220 void MediacontentManager::readCommonDataFromMediaInfo(media_info_h info, MediacontentMedia* newMedia)
226 unsigned long long tmpLongLong = 0;
229 LoggerD("enter Common Data type : " << newMedia->getMediaType());
231 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_id(info, &tmpStr) )
235 newMedia->setMediaUUID(tmpStr);
236 LoggerD("UUID : " << tmpStr);
242 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_mime_type(info, &tmpStr) )
246 newMedia->setMimeType(tmpStr);
247 LoggerD("MineType : " << tmpStr);
253 if (MEDIA_CONTENT_ERROR_NONE == media_info_get_display_name(info, &tmpStr) )
257 newMedia->setDisplayName(tmpStr);
258 LoggerD("Display Name : " << tmpStr);
264 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_file_path(info, &tmpStr) )
268 newMedia->setFilePath(ContentUtility::convertPathToUri(tmpStr));
269 LoggerD("Path : " << newMedia->getFilePath());
275 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_thumbnail_path (info, &tmpStr) )
279 newMedia->setThumbnailPath(ContentUtility::convertPathToUri(tmpStr));
280 LoggerD("Thumnail Path : " << newMedia->getThumbnailPath());
286 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_description(info, &tmpStr) )
290 newMedia->setDescription(tmpStr);
291 LoggerD("Description : " << tmpStr);
297 //newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
298 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_modified_time (info, &tmpDate) )
302 newMedia->setModifiedDate(toDateTm(tmpDate));
306 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_favorite (info, &tmpBool) )
308 newMedia->setFavorite(tmpBool);
309 LoggerD("favorite " << tmpBool);
312 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_rating (info, &tmpInt) )
314 newMedia->setRating(tmpInt);
315 LoggerD("rating " << tmpInt);
318 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
320 newMedia->setSize(tmpLongLong);
321 LoggerD("Size : " << tmpLongLong);
326 void MediacontentManager::readImageFromMediaInfo( media_info_h info, MediacontentImage* newImage)
334 newImage->setMediaType("IMAGE");
336 readCommonDataFromMediaInfo(info, newImage);
340 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(info, &img))
343 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_date_taken (img, &tmpStr) )
347 struct tm *result = (struct tm *)calloc(1, sizeof(struct tm));
348 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) {
349 LogError( "Couldn't convert supplied date.");
352 LoggerD("image_meta_get_date_taken : " << tmpStr); //time??
353 newImage->setReleasedDate(result);
358 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_title(img, &tmpStr) )
362 newImage->setTitle(tmpStr);
363 LoggerD(" Image Title: " << tmpStr);
369 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt) )
371 newImage->setImageWidth(tmpInt);
372 LoggerD("Image Width " << tmpInt);
375 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_height(img, &tmpInt) )
377 newImage->setImageHeight(tmpInt);
378 LoggerD("Image Height " << tmpInt);
381 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
383 newImage->setImageLatitude(tmpDouble);
384 LoggerD("Image Latitude " << tmpDouble);
387 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
389 newImage->setImageLongitude(tmpDouble);
390 LoggerD("Image Longitude " << tmpDouble);
393 media_content_orientation_e orientation;
395 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_orientation(img, &orientation) )
398 string orientationStr;
403 orientationStr = "NORMAL";
406 orientationStr = "FLIP_HORIZONTAL";
409 orientationStr = "ROTATE_180";
412 orientationStr = "FLIP_VERTICAL";
415 orientationStr = "TRANSPOSE";
418 orientationStr = "ROTATE_90";
421 orientationStr = "TRANSVERSE";
424 orientationStr = "ROTATE_270";
428 newImage->setImageOrientation(orientationStr);
429 LoggerD(" image Orientation. " << orientationStr);
434 if ( METADATA_EXTRACTOR_ERROR_NONE != image_meta_destroy(img))
436 LoggerD(" image_meta_destroy is fail... ");
441 LoggerD("fetch Image Info failed..");
447 LoggerD("media info is NULL");
451 void MediacontentManager::readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo)
459 newVideo->setMediaType("VIDEO");
461 readCommonDataFromMediaInfo(info, newVideo); //set common media infomation
465 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(info, &video))
468 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr) )
472 struct tm *result=(struct tm *)calloc(1, sizeof(struct tm));
473 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) {
474 LogError( "Couldn't convert supplied date.");
476 newVideo->setReleasedDate(result);
478 LoggerD("audio_meta_get_recorded_date : " << tmpStr);
484 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_album(video, &tmpStr) )
488 newVideo->setVideoAlbum(tmpStr);
489 LoggerD(" Video Album. " << tmpStr);
495 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_title(video, &tmpStr) )
499 newVideo->setTitle(tmpStr);
500 LoggerD(" Video Title. " << tmpStr);
506 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_artist(video, &tmpStr) )
510 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
511 for( unsigned int i=0; i < artists.size(); i++)
513 string artist = artists.at(i);
514 LoggerD("Audio artist: " << artist);
515 newVideo->appendVideoArtist(artist);
524 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
526 newVideo->setVideoLongitude(tmpDouble);
529 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
531 newVideo->setVideoLatitude(tmpDouble);
534 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_width(video, &tmpInt) )
536 newVideo->setVideoWidth(tmpInt);
539 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_height(video, &tmpInt) )
541 newVideo->setVideoHeight(tmpInt);
544 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt) )
546 newVideo->setVideoDuration(tmpInt);
549 if ( METADATA_EXTRACTOR_ERROR_NONE != video_meta_destroy(video))
551 LoggerD(" video_meta_destroy is fail... ");
557 LoggerD("fetch Video info fail...");
562 LoggerD("media info is NULL");
567 void MediacontentManager::readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio)
571 unsigned long long tmpLongLong = 0;
575 newAudio->setMediaType("AUDIO");
577 readCommonDataFromMediaInfo(info, newAudio); //set common media infomation
581 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio))
583 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr) )
587 struct tm *result = (struct tm *)calloc(1, sizeof(struct tm));
588 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) {
589 LogError( "Couldn't convert supplied date.");
591 newAudio->setReleasedDate(result);
593 LoggerD("audio_meta_get_recorded_date : " << tmpStr);
599 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_title(audio, &tmpStr) )
603 newAudio->setTitle(tmpStr);
604 LoggerD("Audio Title : " << tmpStr);
610 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr) )
614 newAudio->setAudioAlbum(tmpStr);
615 LoggerD("Audio Album : " << tmpStr);
621 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_artist(audio, &tmpStr) )
625 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
626 for( unsigned int i=0; i < artists.size(); i++)
628 string artist = artists.at(i);
629 LoggerD("Audio artist: " << artist);
630 newAudio->appendAudioArtist(artist);
638 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_composer(audio, &tmpStr) )
642 std::vector<std::string> composers = String::split(tmpStr, TAG_DELIMETER);
643 for( unsigned int i=0; i < composers.size(); i++)
645 string composer = composers.at(i);
646 LoggerD("Audio Composer : " << composer);
647 newAudio->appendAudioComposer(composer);
655 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_duration(audio, &tmpInt) )
657 newAudio->setAudioDuration(tmpInt);
658 LoggerD("Audio Duration : " << tmpInt);
661 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_copyright(audio, &tmpStr) )
665 newAudio->setAudioCopyright(tmpStr);
666 LoggerD("Audio CopyRight: " << tmpStr);
672 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_track_num(audio, &tmpStr) )
677 LoggerD("trackNum: " << tmpStr);
679 istringstream(tmpStr) >> trackNum;
681 LoggerD("Track Number type is wrong. (track number:" << tmpStr << ")");
684 newAudio->setAudioTrackNum(trackNum);
690 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
692 newAudio->setAudioSize(tmpLongLong);
693 LoggerD("Audio Size: " << tmpLongLong);
696 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_bit_rate(audio, &tmpInt) )
698 newAudio->setAudioBitrate(tmpInt);
699 LoggerD("Audio Bitrate: " << tmpInt);
702 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_genre(audio, &tmpStr) )
706 std::vector<std::string> genres = String::split(tmpStr, TAG_DELIMETER);
708 for( unsigned int i=0; i < genres.size(); i++)
710 string genre = genres.at(i);
711 LoggerD("Audio Genre: " << genre);
712 newAudio->appendAudioGenre(genre);
720 if ( METADATA_EXTRACTOR_ERROR_NONE != audio_meta_destroy(audio))
722 LoggerD(" audio_meta_destroy is fail... ");
729 LoggerD("fetch Music Info fail...");
736 LoggerD("media info is NULL");
743 bool MediacontentManager::mediaFolderCallback(media_folder_h folder, void *user_data)
746 if (user_data != NULL){
747 IEventFindFolder* event = (IEventFindFolder*)user_data;
748 LoggerD("user data is valide");
751 LoggerD("folder is valide");
752 MediacontentFolderPtr newFolder(new MediacontentFolder());
753 convertToPlatformFolder(folder, newFolder);
754 LoggerD("folder type" << newFolder->getFolderStorageType());
756 event->addFolder(newFolder);
761 LoggerD("user data is NULL");
768 bool MediacontentManager::mediaItemCallback(media_info_h info, void* user_data)
770 if (user_data != NULL){
771 IEventBrowseFolder* event = (IEventBrowseFolder*)user_data;
773 media_content_type_e type;
775 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) )
777 if ( type == MEDIA_CONTENT_TYPE_IMAGE)
779 MediacontentImage *newImage(new MediacontentImage());
780 readImageFromMediaInfo(info, newImage);
781 event->addMedia(newImage);
783 else if ( type == MEDIA_CONTENT_TYPE_VIDEO)
785 MediacontentVideo *newVideo(new MediacontentVideo());
786 readVideoFromMediaInfo(info, newVideo);
787 event->addMedia(newVideo);
789 else if ( type == MEDIA_CONTENT_TYPE_MUSIC)
791 MediacontentAudio *newVAudio(new MediacontentAudio());
792 readMusicFromMediaInfo(info, newVAudio);
793 event->addMedia(newVAudio);
795 else if( type == MEDIA_CONTENT_TYPE_OTHERS)
797 MediacontentMedia *newMedia(new MediacontentMedia());
799 newMedia->setMediaType("OTHER");
800 readCommonDataFromMediaInfo(info, newMedia);
801 event->addMedia(newMedia);
808 LoggerD("event is NULL");
814 void MediacontentManager::OnRequestReceived(const IEventFindFolderPtr &eFolder)
818 if ( MEDIA_CONTENT_ERROR_NONE !=
819 media_folder_foreach_folder_from_db (NULL, mediaFolderCallback, eFolder.Get()))
821 LogError("error ( media_folder_foreach_folder_from_db ) : ");
822 eFolder->setResult(false);
826 eFolder->setResult(true);
831 void MediacontentManager::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
833 LoggerD("OnRequestReceived::IEventBrowseFolderPtr entered");
835 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
836 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
837 int ret = MEDIA_CONTENT_ERROR_NONE;
840 filter_h filter = NULL;
842 if(eBrowse->getFilterIsSet() || eBrowse->getFolderIdIsSet() || eBrowse->getSortModesIsSet()
843 || eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
846 if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter))
848 if (eBrowse->getFilterIsSet())
851 FilterPtr jsFilter = eBrowse->getFilter();
853 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
854 bool success = jsFilter->validate(validator);
857 ThrowMsg(PlatformException, "Invalid attirbutes.");
859 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
861 jsFilter->travel(IVisitor);
862 condition = visitor->getResult();
864 LoggerD("execute condition [" << condition << "]");
865 media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT ); //set condition
868 if(eBrowse->getSortModesIsSet())
870 media_content_order_e order;
872 SortModePtr attr = eBrowse->getSortMode();
876 string attriName = attr->getAttributeName();
877 attriName = visitor->getPlatformAttr(attriName);
878 LoggerD("Attribute Name [" << attriName << "]");
880 if (attriName.compare("") != 0)
882 if (attr->getOrder() == DeviceAPI::Tizen::ASCENDING_SORT_ORDER)
884 order = MEDIA_CONTENT_ORDER_ASC;
888 order = MEDIA_CONTENT_ORDER_DESC;
891 if ( MEDIA_CONTENT_ERROR_NONE !=
892 media_filter_set_order(filter, order, attriName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT )) //set order
894 LoggerD("media_filter_set_order fail...");
901 if (eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
903 LoggerD("limit or offset");
908 if ( eBrowse->getLimitIsSet() )
910 count = eBrowse->getLimit();
911 LoggerD("limit is " << count);
914 if ( eBrowse->getOffsetIsSet() )
916 offset = eBrowse->getOffset();
917 LoggerD("offset is " << offset);
920 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_set_offset(filter, offset, count))
922 LoggerD("set limit or offset fail...");
930 LogError("error ( media filter create ) : ");
931 eBrowse->setResult(false);
935 if ( eBrowse->getFolderIdIsSet())
937 string folderID = eBrowse->getFolderID();
938 LoggerD("FolderID :" << folderID);
940 if ( MEDIA_CONTENT_ERROR_NONE !=
941 media_folder_foreach_media_from_db (folderID.c_str(), filter, mediaItemCallback, eBrowse.Get()))
943 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
944 eBrowse->setResult(false);
948 eBrowse->setResult(true);
953 if ( MEDIA_CONTENT_ERROR_NONE !=
954 media_info_foreach_media_from_db (filter, mediaItemCallback, eBrowse.Get()))
956 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
957 eBrowse->setResult(false);
961 eBrowse->setResult(true);
968 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_destroy(filter))
970 LogError("media_filter_create Error: " << ret);
975 catch(const Exception &ex){
976 LogError("Exception: " << ex.DumpToString());
977 eBrowse->setResult(false);
985 bool MediacontentManager::updateMediaToDB(MediacontentMediaPtr mediaPtr)
987 string type = mediaPtr->getMediaType(); //media type.
988 string mediaId = mediaPtr->getMediaUUID();
990 LoggerD("MediaId : " << mediaId);
991 media_info_h media = NULL;
995 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_from_db(mediaId.c_str(), &media))
997 if ( mediaPtr->isChangedRating())
999 if ( MEDIA_CONTENT_ERROR_NONE
1000 != media_info_set_rating(media, mediaPtr->getRating()))
1002 LoggerD("Error: set rating");
1005 if ( mediaPtr->isChangedDescription() )
1007 if ( MEDIA_CONTENT_ERROR_NONE
1008 != media_info_set_description (media, mediaPtr->getDescription().c_str()))
1010 LoggerD("Error: set description");
1013 if( mediaPtr->isChangedDisplayName())
1015 if ( MEDIA_CONTENT_ERROR_NONE
1016 != media_info_set_display_name (media, mediaPtr->getDisplayName().c_str()))
1018 LoggerD("Error: set displayname");
1022 if(type.compare("IMAGE") ==0 )
1024 MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
1028 image_meta_h img=NULL;
1029 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img))
1031 if(imagePtr->isChangedOrientaion())
1033 if ( MEDIA_CONTENT_ERROR_NONE !=
1034 image_meta_set_orientation (img, convertToOrientation(imagePtr->getImageOrientation())))
1036 LoggerD("Error: set orientation");
1041 if ( MEDIA_CONTENT_ERROR_NONE !=
1042 media_info_set_latitude(media, imagePtr->getImageLatitude())
1045 LoggerD("Error: set Latitude");
1049 if ( MEDIA_CONTENT_ERROR_NONE !=
1050 media_info_set_longitude(media, imagePtr->getImageLongitude())
1053 LoggerD("Error: set Longitude");
1057 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_update_to_db (img) )
1059 LoggerD("Error: update db");
1063 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_destroy(img))
1065 LoggerD("Error: destroy media info");
1074 LoggerD("Error: get Image from DB");
1081 if(type.compare("VIDEO") ==0 )
1083 MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
1087 video_meta_h video = NULL;
1088 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(media, &video))
1091 if ( videoPtr->isChangedPlayCount() )
1093 if ( MEDIA_CONTENT_ERROR_NONE !=
1094 video_meta_set_played_count (video, videoPtr->getVideoPlayCount()))
1096 LoggerD("Error: set play count");
1102 if (videoPtr->isChangedPlayedTime())
1104 if ( MEDIA_CONTENT_ERROR_NONE !=
1105 video_meta_set_played_position (video, videoPtr->getVideoPlayedTime()))
1107 LoggerD("Error: set played time");
1112 if (videoPtr->isChangedAlbum())
1114 LoggerD("Not support - Album API");
1118 if (videoPtr->isChangedArtists())
1120 LoggerD("Not support - Artist API");
1124 if ( MEDIA_CONTENT_ERROR_NONE !=
1125 media_info_set_latitude(media, videoPtr->getVideoLatitude())
1128 LoggerD("Error: set Latitude");
1132 if ( MEDIA_CONTENT_ERROR_NONE !=
1133 media_info_set_longitude(media, videoPtr->getVideoLongitude())
1136 LoggerD("Error: set Latitude");
1141 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_update_to_db (video) )
1143 LoggerD("Error: update db");
1147 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_destroy(video))
1149 LoggerD("Error: destroy video meta");
1162 if(type.compare("AUDIO") ==0 )
1165 MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
1166 if (audioPtr && ( audioPtr->isChangedAudioArtist () || audioPtr->isChangedAudioAlbum()
1167 || audioPtr->isChangedAudioGenre() ||audioPtr->isChangedAudioComposer()
1168 || audioPtr->isChangedAudioTrackNumber()) )
1171 audio_meta_h audio=NULL;
1172 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(media, &audio))
1175 if ( audioPtr->isChangedPlayCount() )
1177 if ( MEDIA_CONTENT_ERROR_NONE !=
1178 audio_meta_set_played_count (audio, audioPtr->getAudioPlayCount()))
1180 LoggerD("Error: set play count");
1185 if (audioPtr->isChangedPlayedTime())
1187 if ( MEDIA_CONTENT_ERROR_NONE !=
1188 audio_meta_set_played_position (audio, audioPtr->getAudioPlayedTime()))
1190 LoggerD("Error: set played time");
1195 if (audioPtr->isChangedAudioArtist())
1197 LoggerD("Not Support API");
1201 if (audioPtr->isChangedAudioAlbum())
1203 LoggerD("Not Support API");
1207 if (audioPtr->isChangedAudioGenre())
1209 LoggerD("Not Support API");
1213 if (audioPtr->isChangedAudioComposer())
1215 LoggerD("Not Support API");
1219 if (audioPtr->isChangedAudioTrackNumber())
1221 LoggerD("Not Support API");
1225 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_update_to_db (audio) )
1227 LoggerD("Error: update db");
1231 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_destroy(audio))
1233 LoggerD("Error: destroy audio meta");
1245 if ( MEDIA_CONTENT_ERROR_NONE != media_info_update_to_db(media))
1247 LoggerD("Error: update to DB");
1254 if ( MEDIA_CONTENT_ERROR_NONE !=media_info_destroy(media))
1256 LoggerD("Error: destroy media info");
1264 void MediacontentManager::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
1266 LoggerD("OnRequestReceived::IEventUpdateMediaPtr entered");
1269 MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
1271 if(updateMediaToDB(mediaPtr))
1273 eMedia->setResult(true);
1274 LoggerD("update success");
1278 eMedia->setResult(false);
1279 ThrowMsg(PlatformException, "DB operation is failed");
1282 catch (const Exception &ex)
1284 LogError("Exception: " << ex.DumpToString());
1285 eMedia->setResult(false);
1290 void MediacontentManager::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
1292 LoggerD("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
1296 MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
1297 if (mediaListPtr->empty())
1299 LoggerD("Item vector is empty");
1303 for(unsigned int i=0; i<mediaListPtr->size(); i++)
1306 MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
1307 if(updateMediaToDB(mediaPtr))
1309 eItems->setResult(true);
1310 LoggerD("update success");
1314 eItems->setResult(false);
1315 ThrowMsg(PlatformException, "DB operation is failed");
1321 catch (const Exception &ex)
1323 LogError("Exception: " << ex.DumpToString());
1324 eItems->setResult(false);
1326 //eItems->setCancelAllowed(false);