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.
22 #include <dpl/log/log.h>
23 #include <media_content.h>
24 #include <Commons/Regex.h>
25 #include <Commons/StringUtils.h>
26 #include <CommonsJavaScript/Converter.h>
28 #include "ContentManager.h"
29 #include "ContentFilterValidator.h"
30 #include "ContentUtility.h"
33 using namespace WrtDeviceApis::Commons;
40 int MediacontentManager::m_instanceCount = 0;
42 MediacontentManager::MediacontentManager()
46 //protect for pararel execution
47 DPL::Mutex::ScopedLock mx(&m_constructorMutex);
48 if (m_instanceCount == 0)
50 //when it is first instance then connect to media content service.
51 if( MEDIA_CONTENT_ERROR_NONE != media_content_connect())
53 LogDebug("Media Content Service Connect Fail...");
57 //increase counter of instances
62 MediacontentManager::~MediacontentManager()
64 LogDebug("entered : " << m_instanceCount);
65 DPL::Mutex::ScopedLock mx(&m_constructorMutex);
66 //decrease counter of instances
68 if (m_instanceCount == 0)
70 LogDebug("instance Count is zero ");
71 //when it is last instance then clse connection to database
72 if ( MEDIA_CONTENT_ERROR_NONE != media_content_disconnect())
74 LogDebug("Media Content Service Disconnect Fail...");
80 void MediacontentManager::OnRequestReceived(const IEventGetMediacontentPtr &event)
82 LogDebug( "OnRequestReceived::entered");
83 //IMediacontentPtr newMediacontent(new Mediacontent());
84 //IMediacontentPtr newMediacontent = MediacontentFactory::getInstance().createMediacontentObject();
88 LogDebug( "get Mediacontent \n");
89 // event->setMediacontent(m_mediaContent);
90 event->setResult(true);
94 LogError("error occuered during obtaining data");
95 event->setResult(false);
97 event->setCancelAllowed(true);
101 tm MediacontentManager::toDateTm(time_t date)
105 localtime_r(&date, &tm_date);
110 media_content_orientation_e MediacontentManager::convertToOrientation(string orientation)
112 media_content_orientation_e ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
114 if ( orientation.compare("NORMAL")==0)
116 ret = MEDIA_CONTENT_ORIENTATION_NORMAL;
118 else if (orientation.compare("FLIP_HORIZONTAL")==0)
120 ret = MEDIA_CONTENT_ORIENTATION_HFLIP;
122 else if (orientation.compare("ROTATE_180")==0)
124 ret = MEDIA_CONTENT_ORIENTATION_ROT_180;
126 else if (orientation.compare("FLIP_VERTICAL")==0)
128 ret = MEDIA_CONTENT_ORIENTATION_VFLIP;
130 else if (orientation.compare("TRANSPOSE")==0)
132 ret = MEDIA_CONTENT_ORIENTATION_TRANSPOSE;
134 else if (orientation.compare("ROTATE_90")==0)
136 ret = MEDIA_CONTENT_ORIENTATION_ROT_90;
138 else if (orientation.compare("TRANSVERSE")==0)
140 ret =MEDIA_CONTENT_ORIENTATION_TRANSVERSE;
142 else if (orientation.compare("ROTATE_270")==0)
144 ret =MEDIA_CONTENT_ORIENTATION_ROT_270;
148 LogDebug("wrong value.");
149 ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
155 void MediacontentManager::convertToPlatformFolder(media_folder_h media_folder, MediacontentFolderPtr& newFolder)
159 media_content_storage_e storageType;
161 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_folder_id(media_folder, &tmpStr))
165 LogDebug("Folder UUID : " << tmpStr);
166 newFolder->setFolderUUID(tmpStr);
172 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_path(media_folder, &tmpStr))
176 LogDebug("Folder path : " << tmpStr);
177 newFolder->setFolderPath(ContentUtility::convertPathToUri(tmpStr));
183 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_name(media_folder, &tmpStr))
187 LogDebug("Folder name : " << tmpStr);
188 newFolder->setFolderName(tmpStr);
194 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_modified_time(media_folder, &date))
196 LogDebug("get Modified Time ");
197 newFolder->setFolderModifiedDate(toDateTm(date));
200 if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_storage_type(media_folder, &storageType))
202 LogDebug("storage Type=" << storageType);
204 if(storageType == MEDIA_CONTENT_STORAGE_INTERNAL )
208 else if( storageType == MEDIA_CONTENT_STORAGE_EXTERNAL)
216 newFolder->setFolderStorageType(type);
222 void MediacontentManager::readCommonDataFromMediaInfo(media_info_h info, MediacontentMedia* newMedia)
228 unsigned long long tmpLongLong = 0;
231 LogDebug("enter Common Data type : " << newMedia->getMediaType());
233 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_id(info, &tmpStr) )
237 newMedia->setMediaUUID(tmpStr);
238 LogDebug("UUID : " << tmpStr);
244 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_mime_type(info, &tmpStr) )
248 newMedia->setMimeType(tmpStr);
249 LogDebug("MineType : " << tmpStr);
255 if (MEDIA_CONTENT_ERROR_NONE == media_info_get_display_name(info, &tmpStr) )
259 newMedia->setDisplayName(tmpStr);
260 newMedia->setTitle(tmpStr);
261 LogDebug("Display Name : " << tmpStr);
267 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_file_path(info, &tmpStr) )
271 newMedia->setFilePath(ContentUtility::convertPathToUri(tmpStr));
272 LogDebug("Path : " << newMedia->getFilePath());
278 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_thumbnail_path (info, &tmpStr) )
282 newMedia->setThumbnailPath(ContentUtility::convertPathToUri(tmpStr));
283 LogDebug("Thumnail Path : " << newMedia->getThumbnailPath());
289 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_description(info, &tmpStr) )
293 newMedia->setDescription(tmpStr);
294 LogDebug("Desc : " << tmpStr);
300 //newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
301 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_modified_time (info, &tmpDate) )
303 newMedia->setModifiedDate(toDateTm(tmpDate));
306 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_favorite (info, &tmpBool) )
308 newMedia->setFavorite(tmpBool);
309 LogDebug("favorite " << tmpBool);
312 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_rating (info, &tmpInt) )
314 newMedia->setRating(tmpInt);
315 LogDebug("rating " << tmpInt);
318 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
320 newMedia->setSize(tmpLongLong);
321 LogDebug("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) )
348 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
349 LogError( "Couldn't convert supplied date.");
352 LogDebug("image_meta_get_date_taken : " << tmpStr); //time??
353 newImage->setReleasedDate(result);
359 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt) )
361 newImage->setImageWidth(tmpInt);
362 LogDebug("Image Width " << tmpInt);
365 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_height(img, &tmpInt) )
367 newImage->setImageHeight(tmpInt);
368 LogDebug("Image Height " << tmpInt);
371 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
373 newImage->setImageLatitude(tmpDouble);
374 LogDebug("Image Latitude " << tmpDouble);
377 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
379 newImage->setImageLongitude(tmpDouble);
380 LogDebug("Image Longitude " << tmpDouble);
383 media_content_orientation_e orientation;
385 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_orientation(img, &orientation) )
388 string orientationStr;
393 orientationStr = "NORMAL";
396 orientationStr = "FLIP_HORIZONTAL";
399 orientationStr = "ROTATE_180";
402 orientationStr = "FLIP_VERTICAL";
405 orientationStr = "TRANSPOSE";
408 orientationStr = "ROTATE_90";
411 orientationStr = "TRANSVERSE";
414 orientationStr = "ROTATE_270";
418 newImage->setImageOrientation(orientationStr);
419 LogDebug(" image Orientation. " << orientationStr);
424 if ( METADATA_EXTRACTOR_ERROR_NONE != image_meta_destroy(img))
426 LogDebug(" image_meta_destroy is fail... ");
431 LogDebug("fetch Image Info failed..");
437 LogDebug("media info is NULL");
441 void MediacontentManager::readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo)
449 newVideo->setMediaType("VIDEO");
451 readCommonDataFromMediaInfo(info, newVideo); //set common media infomation
455 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(info, &video))
458 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr) )
463 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
464 LogError( "Couldn't convert supplied date.");
466 newVideo->setReleasedDate(result);
468 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
474 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_album(video, &tmpStr) )
478 newVideo->setVideoAlbum(tmpStr);
479 LogDebug(" Video Album. " << tmpStr);
485 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_title(video, &tmpStr) )
489 newVideo->setTitle(tmpStr);
490 LogDebug(" Video Title. " << tmpStr);
496 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_artist(video, &tmpStr) )
500 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
501 for( unsigned int i=0; i < artists.size(); i++)
503 string artist = artists.at(i);
504 LogDebug("Audio artist: " << artist);
505 newVideo->appendVideoArtist(artist);
514 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
516 newVideo->setVideoLongitude(tmpDouble);
519 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
521 newVideo->setVideoLatitude(tmpDouble);
524 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_width(video, &tmpInt) )
526 newVideo->setVideoWidth(tmpInt);
529 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_height(video, &tmpInt) )
531 newVideo->setVideoHeight(tmpInt);
534 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt) )
536 newVideo->setVideoDuration(tmpInt);
539 if ( METADATA_EXTRACTOR_ERROR_NONE != video_meta_destroy(video))
541 LogDebug(" video_meta_destroy is fail... ");
547 LogDebug("fetch Video info fail...");
552 LogDebug("media info is NULL");
557 void MediacontentManager::readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio)
561 unsigned long long tmpLongLong = 0;
565 newAudio->setMediaType("AUDIO");
567 readCommonDataFromMediaInfo(info, newAudio); //set common media infomation
571 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio))
573 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr) )
578 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
579 LogError( "Couldn't convert supplied date.");
581 newAudio->setReleasedDate(result);
583 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
589 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_title(audio, &tmpStr) )
593 newAudio->setTitle(tmpStr);
594 LogDebug("Audio Title : " << tmpStr);
600 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr) )
604 newAudio->setAudioAlbum(tmpStr);
605 LogDebug("Audio Album : " << tmpStr);
611 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_artist(audio, &tmpStr) )
615 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
616 for( unsigned int i=0; i < artists.size(); i++)
618 string artist = artists.at(i);
619 LogDebug("Audio artist: " << artist);
620 newAudio->appendAudioArtist(artist);
628 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_composer(audio, &tmpStr) )
632 std::vector<std::string> composers = String::split(tmpStr, TAG_DELIMETER);
633 for( unsigned int i=0; i < composers.size(); i++)
635 string composer = composers.at(i);
636 LogDebug("Audio Composer : " << composer);
637 newAudio->appendAudioComposer(composer);
645 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_duration(audio, &tmpInt) )
647 newAudio->setAudioDuration(tmpInt);
648 LogDebug("Audio Duration : " << tmpInt);
651 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_copyright(audio, &tmpStr) )
655 newAudio->setAudioCopyright(tmpStr);
656 LogDebug("Audio CopyRight: " << tmpStr);
662 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_track_num(audio, &tmpStr) )
667 LogDebug("trackNum: " << tmpStr);
669 istringstream(tmpStr) >> trackNum;
671 LogDebug("Track Number type is wrong. (track number:" << tmpStr << ")");
675 newAudio->setAudioTrackNum(trackNum);
681 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
684 newAudio->setAudioSize(tmpLongLong);
685 LogDebug("Audio Size: " << tmpLongLong);
688 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_bit_rate(audio, &tmpInt) )
691 newAudio->setAudioBitrate(tmpInt);
692 LogDebug("Audio Bitrate: " << tmpInt);
695 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_genre(audio, &tmpStr) )
700 std::vector<std::string> genres = String::split(tmpStr, TAG_DELIMETER);
702 for( unsigned int i=0; i < genres.size(); i++)
704 string genre = genres.at(i);
705 LogDebug("Audio Genre: " << genre);
706 newAudio->appendAudioGenre(genre);
714 if ( METADATA_EXTRACTOR_ERROR_NONE != audio_meta_destroy(audio))
716 LogDebug(" audio_meta_destroy is fail... ");
723 LogDebug("fetch Music Info fail...");
730 LogDebug("media info is NULL");
737 bool MediacontentManager::mediaFolderCallback(media_folder_h folder, void *user_data)
740 if (user_data != NULL){
741 IEventFindFolder* event = (IEventFindFolder*)user_data;
742 LogDebug("user data is valide");
745 LogDebug("folder is valide");
746 MediacontentFolderPtr newFolder(new MediacontentFolder());
747 convertToPlatformFolder(folder, newFolder);
748 LogDebug("folder type" << newFolder->getFolderStorageType());
750 event->addFolder(newFolder);
755 LogDebug("user data is NULL");
762 bool MediacontentManager::mediaItemCallback(media_info_h info, void* user_data)
764 if (user_data != NULL){
765 IEventBrowseFolder* event = (IEventBrowseFolder*)user_data;
767 media_content_type_e type;
769 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) )
771 if ( type == MEDIA_CONTENT_TYPE_IMAGE)
773 MediacontentImage *newImage(new MediacontentImage());
774 readImageFromMediaInfo(info, newImage);
775 event->addMedia(newImage);
777 else if ( type == MEDIA_CONTENT_TYPE_VIDEO)
779 MediacontentVideo *newVideo(new MediacontentVideo());
780 readVideoFromMediaInfo(info, newVideo);
781 event->addMedia(newVideo);
783 else if ( type == MEDIA_CONTENT_TYPE_MUSIC)
785 MediacontentAudio *newVAudio(new MediacontentAudio());
786 readMusicFromMediaInfo(info, newVAudio);
787 event->addMedia(newVAudio);
789 else if( type == MEDIA_CONTENT_TYPE_OTHERS)
791 MediacontentMedia *newMedia(new MediacontentMedia());
793 newMedia->setMediaType("OTHER");
794 readCommonDataFromMediaInfo(info, newMedia);
795 event->addMedia(newMedia);
802 LogDebug("event is NULL");
808 void MediacontentManager::OnRequestReceived(const IEventFindFolderPtr &eFolder)
812 if ( MEDIA_CONTENT_ERROR_NONE !=
813 media_folder_foreach_folder_from_db (NULL, mediaFolderCallback, eFolder.Get()))
815 LogError("error ( media_folder_foreach_folder_from_db ) : ");
816 eFolder->setResult(false);
820 eFolder->setResult(true);
827 void MediacontentManager::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
829 LogDebug("OnRequestReceived::IEventBrowseFolderPtr entered");
831 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
832 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
833 int ret = MEDIA_CONTENT_ERROR_NONE;
836 filter_h filter = NULL;
838 if(eBrowse->getFilterIsSet() || eBrowse->getFolderIdIsSet() || eBrowse->getSortModesIsSet()
839 || eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
842 if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter))
844 if (eBrowse->getFilterIsSet())
847 FilterPtr jsFilter = eBrowse->getFilter();
849 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
850 bool success = jsFilter->validate(validator);
853 ThrowMsg(PlatformException, "Invalid attirbutes.");
855 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
857 jsFilter->travel(IVisitor);
858 condition = visitor->getResult();
860 LogDebug("execute condition [" << condition << "]");
861 media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT ); //set condition
864 if(eBrowse->getSortModesIsSet())
866 media_content_order_e order;
868 SortModePtr attr = eBrowse->getSortMode();
872 string attriName = attr->getAttributeName();
873 attriName = visitor->getPlatformAttr(attriName);
874 LogDebug("Attribute Name [" << attriName << "]");
876 if (attriName.compare("") != 0)
878 if (attr->getOrder() == DeviceAPI::Tizen::ASCENDING_SORT_ORDER)
880 order = MEDIA_CONTENT_ORDER_ASC;
884 order = MEDIA_CONTENT_ORDER_DESC;
887 if ( MEDIA_CONTENT_ERROR_NONE !=
888 media_filter_set_order(filter, order, attriName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT )) //set order
890 LogDebug("media_filter_set_order fail...");
897 if (eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
899 LogDebug("limit or offset");
904 if ( eBrowse->getLimitIsSet() )
906 count = eBrowse->getLimit();
907 LogDebug("limit is " << count);
910 if ( eBrowse->getOffsetIsSet() )
912 offset = eBrowse->getOffset();
913 LogDebug("offset is " << offset);
916 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_set_offset(filter, offset, count))
918 LogDebug("set limit or offset fail...");
926 LogError("error ( media filter create ) : ");
927 eBrowse->setResult(false);
931 if ( eBrowse->getFolderIdIsSet())
933 string folderID = eBrowse->getFolderID();
934 LogDebug("FolderID :" << folderID);
936 if ( MEDIA_CONTENT_ERROR_NONE !=
937 media_folder_foreach_media_from_db (folderID.c_str(), filter, mediaItemCallback, eBrowse.Get()))
939 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
940 eBrowse->setResult(false);
944 eBrowse->setResult(true);
949 if ( MEDIA_CONTENT_ERROR_NONE !=
950 media_info_foreach_media_from_db (filter, mediaItemCallback, eBrowse.Get()))
952 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
953 eBrowse->setResult(false);
957 eBrowse->setResult(true);
964 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_destroy(filter))
966 LogError("media_filter_create Error: " << ret);
971 catch(const Exception &ex){
972 LogError("Exception: " << ex.DumpToString());
973 eBrowse->setResult(false);
981 bool MediacontentManager::updateMediaToDB(MediacontentMediaPtr mediaPtr)
983 string type = mediaPtr->getMediaType(); //media type.
984 string mediaId = mediaPtr->getMediaUUID();
986 LogDebug("MediaId : " << mediaId);
987 media_info_h media = NULL;
991 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_from_db(mediaId.c_str(), &media))
993 if ( mediaPtr->isChangedRating())
995 if ( MEDIA_CONTENT_ERROR_NONE
996 != media_info_set_rating(media, mediaPtr->getRating()))
998 LogDebug("Error: set rating");
1001 if ( mediaPtr->isChangedDescription() )
1003 if ( MEDIA_CONTENT_ERROR_NONE
1004 != media_info_set_description (media, mediaPtr->getDescription().c_str()))
1006 LogDebug("Error: set description");
1009 if( mediaPtr->isChangedDisplayName())
1011 if ( MEDIA_CONTENT_ERROR_NONE
1012 != media_info_set_display_name (media, mediaPtr->getDisplayName().c_str()))
1014 LogDebug("Error: set displayname");
1018 if(type.compare("IMAGE") ==0 )
1020 MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
1024 image_meta_h img=NULL;
1025 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img))
1027 if(imagePtr->isChangedOrientaion())
1029 if ( MEDIA_CONTENT_ERROR_NONE !=
1030 image_meta_set_orientation (img, convertToOrientation(imagePtr->getImageOrientation())))
1032 LogDebug("Error: set orientation");
1037 if ( MEDIA_CONTENT_ERROR_NONE !=
1038 media_info_set_latitude(media, imagePtr->getImageLatitude())
1041 LogDebug("Error: set Latitude");
1045 if ( MEDIA_CONTENT_ERROR_NONE !=
1046 media_info_set_longitude(media, imagePtr->getImageLongitude())
1049 LogDebug("Error: set Longitude");
1053 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_update_to_db (img) )
1055 LogDebug("Error: update db");
1059 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_destroy(img))
1061 LogDebug("Error: destroy media info");
1070 LogDebug("Error: get Image from DB");
1077 if(type.compare("VIDEO") ==0 )
1079 MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
1083 video_meta_h video = NULL;
1084 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(media, &video))
1087 if ( videoPtr->isChangedPlayCount() )
1089 if ( MEDIA_CONTENT_ERROR_NONE !=
1090 video_meta_set_played_count (video, videoPtr->getVideoPlayCount()))
1092 LogDebug("Error: set play count");
1098 if (videoPtr->isChangedPlayedTime())
1100 if ( MEDIA_CONTENT_ERROR_NONE !=
1101 video_meta_set_played_position (video, videoPtr->getVideoPlayedTime()))
1103 LogDebug("Error: set played time");
1108 if (videoPtr->isChangedAlbum())
1110 LogDebug("Not support - Album API");
1114 if (videoPtr->isChangedArtists())
1116 LogDebug("Not support - Artist API");
1120 if ( MEDIA_CONTENT_ERROR_NONE !=
1121 media_info_set_latitude(media, videoPtr->getVideoLatitude())
1124 LogDebug("Error: set Latitude");
1128 if ( MEDIA_CONTENT_ERROR_NONE !=
1129 media_info_set_longitude(media, videoPtr->getVideoLongitude())
1132 LogDebug("Error: set Latitude");
1137 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_update_to_db (video) )
1139 LogDebug("Error: update db");
1143 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_destroy(video))
1145 LogDebug("Error: destroy video meta");
1158 if(type.compare("AUDIO") ==0 )
1161 MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
1162 if (audioPtr && ( audioPtr->isChangedAudioArtist () || audioPtr->isChangedAudioAlbum()
1163 || audioPtr->isChangedAudioGenre() ||audioPtr->isChangedAudioComposer()
1164 || audioPtr->isChangedAudioTrackNumber()) )
1167 audio_meta_h audio=NULL;
1168 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(media, &audio))
1171 if ( audioPtr->isChangedPlayCount() )
1173 if ( MEDIA_CONTENT_ERROR_NONE !=
1174 audio_meta_set_played_count (audio, audioPtr->getAudioPlayCount()))
1176 LogDebug("Error: set play count");
1181 if (audioPtr->isChangedPlayedTime())
1183 if ( MEDIA_CONTENT_ERROR_NONE !=
1184 audio_meta_set_played_position (audio, audioPtr->getAudioPlayedTime()))
1186 LogDebug("Error: set played time");
1191 if (audioPtr->isChangedAudioArtist())
1193 LogDebug("Not Support API");
1197 if (audioPtr->isChangedAudioAlbum())
1199 LogDebug("Not Support API");
1203 if (audioPtr->isChangedAudioGenre())
1205 LogDebug("Not Support API");
1209 if (audioPtr->isChangedAudioComposer())
1211 LogDebug("Not Support API");
1215 if (audioPtr->isChangedAudioTrackNumber())
1217 LogDebug("Not Support API");
1221 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_update_to_db (audio) )
1223 LogDebug("Error: update db");
1227 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_destroy(audio))
1229 LogDebug("Error: destroy audio meta");
1241 if ( MEDIA_CONTENT_ERROR_NONE != media_info_update_to_db(media))
1243 LogDebug("Error: update to DB");
1250 if ( MEDIA_CONTENT_ERROR_NONE !=media_info_destroy(media))
1252 LogDebug("Error: destroy media info");
1260 void MediacontentManager::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
1262 LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
1265 MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
1267 if(updateMediaToDB(mediaPtr))
1269 eMedia->setResult(true);
1270 LogDebug("update success");
1274 eMedia->setResult(false);
1275 ThrowMsg(PlatformException, "DB operation is failed");
1278 catch (const Exception &ex)
1280 LogError("Exception: " << ex.DumpToString());
1281 eMedia->setResult(false);
1286 void MediacontentManager::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
1288 LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
1292 MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
1293 if (mediaListPtr->empty())
1295 LogDebug("Item vector is empty");
1299 for(unsigned int i=0; i<mediaListPtr->size(); i++)
1302 MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
1303 if(updateMediaToDB(mediaPtr))
1305 eItems->setResult(true);
1306 LogDebug("update success");
1310 eItems->setResult(false);
1311 ThrowMsg(PlatformException, "DB operation is failed");
1317 catch (const Exception &ex)
1319 LogError("Exception: " << ex.DumpToString());
1320 eItems->setResult(false);
1322 //eItems->setCancelAllowed(false);