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)
103 tm *tm_date = (struct tm *)calloc(1, sizeof(struct tm));
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) )
305 newMedia->setModifiedDate(toDateTm(tmpDate));
309 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_favorite (info, &tmpBool) )
311 newMedia->setFavorite(tmpBool);
312 LogDebug("favorite " << tmpBool);
315 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_rating (info, &tmpInt) )
317 newMedia->setRating(tmpInt);
318 LogDebug("rating " << tmpInt);
321 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
323 newMedia->setSize(tmpLongLong);
324 LogDebug("Size : " << tmpLongLong);
329 void MediacontentManager::readImageFromMediaInfo( media_info_h info, MediacontentImage* newImage)
337 newImage->setMediaType("IMAGE");
339 readCommonDataFromMediaInfo(info, newImage);
343 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(info, &img))
346 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_date_taken (img, &tmpStr) )
350 struct tm *result = (struct tm *)calloc(1, sizeof(struct tm));
351 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) {
352 LogError( "Couldn't convert supplied date.");
355 LogDebug("image_meta_get_date_taken : " << tmpStr); //time??
356 newImage->setReleasedDate(result);
362 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt) )
364 newImage->setImageWidth(tmpInt);
365 LogDebug("Image Width " << tmpInt);
368 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_height(img, &tmpInt) )
370 newImage->setImageHeight(tmpInt);
371 LogDebug("Image Height " << tmpInt);
374 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
376 newImage->setImageLatitude(tmpDouble);
377 LogDebug("Image Latitude " << tmpDouble);
380 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
382 newImage->setImageLongitude(tmpDouble);
383 LogDebug("Image Longitude " << tmpDouble);
386 media_content_orientation_e orientation;
388 if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_orientation(img, &orientation) )
391 string orientationStr;
396 orientationStr = "NORMAL";
399 orientationStr = "FLIP_HORIZONTAL";
402 orientationStr = "ROTATE_180";
405 orientationStr = "FLIP_VERTICAL";
408 orientationStr = "TRANSPOSE";
411 orientationStr = "ROTATE_90";
414 orientationStr = "TRANSVERSE";
417 orientationStr = "ROTATE_270";
421 newImage->setImageOrientation(orientationStr);
422 LogDebug(" image Orientation. " << orientationStr);
427 if ( METADATA_EXTRACTOR_ERROR_NONE != image_meta_destroy(img))
429 LogDebug(" image_meta_destroy is fail... ");
434 LogDebug("fetch Image Info failed..");
440 LogDebug("media info is NULL");
444 void MediacontentManager::readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo)
452 newVideo->setMediaType("VIDEO");
454 readCommonDataFromMediaInfo(info, newVideo); //set common media infomation
458 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(info, &video))
461 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr) )
465 struct tm *result=(struct tm *)calloc(1, sizeof(struct tm));
466 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) {
467 LogError( "Couldn't convert supplied date.");
469 newVideo->setReleasedDate(result);
471 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
477 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_album(video, &tmpStr) )
481 newVideo->setVideoAlbum(tmpStr);
482 LogDebug(" Video Album. " << tmpStr);
488 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_title(video, &tmpStr) )
492 newVideo->setTitle(tmpStr);
493 LogDebug(" Video Title. " << tmpStr);
499 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_artist(video, &tmpStr) )
503 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
504 for( unsigned int i=0; i < artists.size(); i++)
506 string artist = artists.at(i);
507 LogDebug("Audio artist: " << artist);
508 newVideo->appendVideoArtist(artist);
517 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
519 newVideo->setVideoLongitude(tmpDouble);
522 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
524 newVideo->setVideoLatitude(tmpDouble);
527 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_width(video, &tmpInt) )
529 newVideo->setVideoWidth(tmpInt);
532 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_height(video, &tmpInt) )
534 newVideo->setVideoHeight(tmpInt);
537 if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt) )
539 newVideo->setVideoDuration(tmpInt);
542 if ( METADATA_EXTRACTOR_ERROR_NONE != video_meta_destroy(video))
544 LogDebug(" video_meta_destroy is fail... ");
550 LogDebug("fetch Video info fail...");
555 LogDebug("media info is NULL");
560 void MediacontentManager::readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio)
564 unsigned long long tmpLongLong = 0;
568 newAudio->setMediaType("AUDIO");
570 readCommonDataFromMediaInfo(info, newAudio); //set common media infomation
574 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio))
576 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr) )
580 struct tm *result = (struct tm *)calloc(1, sizeof(struct tm));
581 if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", result) == NULL) {
582 LogError( "Couldn't convert supplied date.");
584 newAudio->setReleasedDate(result);
586 LogDebug("audio_meta_get_recorded_date : " << tmpStr);
592 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_title(audio, &tmpStr) )
596 newAudio->setTitle(tmpStr);
597 LogDebug("Audio Title : " << tmpStr);
603 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr) )
607 newAudio->setAudioAlbum(tmpStr);
608 LogDebug("Audio Album : " << tmpStr);
614 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_artist(audio, &tmpStr) )
618 std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
619 for( unsigned int i=0; i < artists.size(); i++)
621 string artist = artists.at(i);
622 LogDebug("Audio artist: " << artist);
623 newAudio->appendAudioArtist(artist);
631 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_composer(audio, &tmpStr) )
635 std::vector<std::string> composers = String::split(tmpStr, TAG_DELIMETER);
636 for( unsigned int i=0; i < composers.size(); i++)
638 string composer = composers.at(i);
639 LogDebug("Audio Composer : " << composer);
640 newAudio->appendAudioComposer(composer);
648 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_duration(audio, &tmpInt) )
650 newAudio->setAudioDuration(tmpInt);
651 LogDebug("Audio Duration : " << tmpInt);
654 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_copyright(audio, &tmpStr) )
658 newAudio->setAudioCopyright(tmpStr);
659 LogDebug("Audio CopyRight: " << tmpStr);
665 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_track_num(audio, &tmpStr) )
670 LogDebug("trackNum: " << tmpStr);
672 istringstream(tmpStr) >> trackNum;
674 LogDebug("Track Number type is wrong. (track number:" << tmpStr << ")");
678 newAudio->setAudioTrackNum(trackNum);
684 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
687 newAudio->setAudioSize(tmpLongLong);
688 LogDebug("Audio Size: " << tmpLongLong);
691 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_bit_rate(audio, &tmpInt) )
694 newAudio->setAudioBitrate(tmpInt);
695 LogDebug("Audio Bitrate: " << tmpInt);
698 if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_genre(audio, &tmpStr) )
703 std::vector<std::string> genres = String::split(tmpStr, TAG_DELIMETER);
705 for( unsigned int i=0; i < genres.size(); i++)
707 string genre = genres.at(i);
708 LogDebug("Audio Genre: " << genre);
709 newAudio->appendAudioGenre(genre);
717 if ( METADATA_EXTRACTOR_ERROR_NONE != audio_meta_destroy(audio))
719 LogDebug(" audio_meta_destroy is fail... ");
726 LogDebug("fetch Music Info fail...");
733 LogDebug("media info is NULL");
740 bool MediacontentManager::mediaFolderCallback(media_folder_h folder, void *user_data)
743 if (user_data != NULL){
744 IEventFindFolder* event = (IEventFindFolder*)user_data;
745 LogDebug("user data is valide");
748 LogDebug("folder is valide");
749 MediacontentFolderPtr newFolder(new MediacontentFolder());
750 convertToPlatformFolder(folder, newFolder);
751 LogDebug("folder type" << newFolder->getFolderStorageType());
753 event->addFolder(newFolder);
758 LogDebug("user data is NULL");
765 bool MediacontentManager::mediaItemCallback(media_info_h info, void* user_data)
767 if (user_data != NULL){
768 IEventBrowseFolder* event = (IEventBrowseFolder*)user_data;
770 media_content_type_e type;
772 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) )
774 if ( type == MEDIA_CONTENT_TYPE_IMAGE)
776 MediacontentImage *newImage(new MediacontentImage());
777 readImageFromMediaInfo(info, newImage);
778 event->addMedia(newImage);
780 else if ( type == MEDIA_CONTENT_TYPE_VIDEO)
782 MediacontentVideo *newVideo(new MediacontentVideo());
783 readVideoFromMediaInfo(info, newVideo);
784 event->addMedia(newVideo);
786 else if ( type == MEDIA_CONTENT_TYPE_MUSIC)
788 MediacontentAudio *newVAudio(new MediacontentAudio());
789 readMusicFromMediaInfo(info, newVAudio);
790 event->addMedia(newVAudio);
792 else if( type == MEDIA_CONTENT_TYPE_OTHERS)
794 MediacontentMedia *newMedia(new MediacontentMedia());
796 newMedia->setMediaType("OTHER");
797 readCommonDataFromMediaInfo(info, newMedia);
798 event->addMedia(newMedia);
805 LogDebug("event is NULL");
811 void MediacontentManager::OnRequestReceived(const IEventFindFolderPtr &eFolder)
815 if ( MEDIA_CONTENT_ERROR_NONE !=
816 media_folder_foreach_folder_from_db (NULL, mediaFolderCallback, eFolder.Get()))
818 LogError("error ( media_folder_foreach_folder_from_db ) : ");
819 eFolder->setResult(false);
823 eFolder->setResult(true);
830 void MediacontentManager::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
832 LogDebug("OnRequestReceived::IEventBrowseFolderPtr entered");
834 MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
835 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
836 int ret = MEDIA_CONTENT_ERROR_NONE;
839 filter_h filter = NULL;
841 if(eBrowse->getFilterIsSet() || eBrowse->getFolderIdIsSet() || eBrowse->getSortModesIsSet()
842 || eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
845 if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter))
847 if (eBrowse->getFilterIsSet())
850 FilterPtr jsFilter = eBrowse->getFilter();
852 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
853 bool success = jsFilter->validate(validator);
856 ThrowMsg(PlatformException, "Invalid attirbutes.");
858 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
860 jsFilter->travel(IVisitor);
861 condition = visitor->getResult();
863 LogDebug("execute condition [" << condition << "]");
864 media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT ); //set condition
867 if(eBrowse->getSortModesIsSet())
869 media_content_order_e order;
871 SortModePtr attr = eBrowse->getSortMode();
875 string attriName = attr->getAttributeName();
876 attriName = visitor->getPlatformAttr(attriName);
877 LogDebug("Attribute Name [" << attriName << "]");
879 if (attriName.compare("") != 0)
881 if (attr->getOrder() == DeviceAPI::Tizen::ASCENDING_SORT_ORDER)
883 order = MEDIA_CONTENT_ORDER_ASC;
887 order = MEDIA_CONTENT_ORDER_DESC;
890 if ( MEDIA_CONTENT_ERROR_NONE !=
891 media_filter_set_order(filter, order, attriName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT )) //set order
893 LogDebug("media_filter_set_order fail...");
900 if (eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
902 LogDebug("limit or offset");
907 if ( eBrowse->getLimitIsSet() )
909 count = eBrowse->getLimit();
910 LogDebug("limit is " << count);
913 if ( eBrowse->getOffsetIsSet() )
915 offset = eBrowse->getOffset();
916 LogDebug("offset is " << offset);
919 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_set_offset(filter, offset, count))
921 LogDebug("set limit or offset fail...");
929 LogError("error ( media filter create ) : ");
930 eBrowse->setResult(false);
934 if ( eBrowse->getFolderIdIsSet())
936 string folderID = eBrowse->getFolderID();
937 LogDebug("FolderID :" << folderID);
939 if ( MEDIA_CONTENT_ERROR_NONE !=
940 media_folder_foreach_media_from_db (folderID.c_str(), filter, mediaItemCallback, eBrowse.Get()))
942 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
943 eBrowse->setResult(false);
947 eBrowse->setResult(true);
952 if ( MEDIA_CONTENT_ERROR_NONE !=
953 media_info_foreach_media_from_db (filter, mediaItemCallback, eBrowse.Get()))
955 LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
956 eBrowse->setResult(false);
960 eBrowse->setResult(true);
967 if ( MEDIA_CONTENT_ERROR_NONE != media_filter_destroy(filter))
969 LogError("media_filter_create Error: " << ret);
974 catch(const Exception &ex){
975 LogError("Exception: " << ex.DumpToString());
976 eBrowse->setResult(false);
984 bool MediacontentManager::updateMediaToDB(MediacontentMediaPtr mediaPtr)
986 string type = mediaPtr->getMediaType(); //media type.
987 string mediaId = mediaPtr->getMediaUUID();
989 LogDebug("MediaId : " << mediaId);
990 media_info_h media = NULL;
994 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_from_db(mediaId.c_str(), &media))
996 if ( mediaPtr->isChangedRating())
998 if ( MEDIA_CONTENT_ERROR_NONE
999 != media_info_set_rating(media, mediaPtr->getRating()))
1001 LogDebug("Error: set rating");
1004 if ( mediaPtr->isChangedDescription() )
1006 if ( MEDIA_CONTENT_ERROR_NONE
1007 != media_info_set_description (media, mediaPtr->getDescription().c_str()))
1009 LogDebug("Error: set description");
1012 if( mediaPtr->isChangedDisplayName())
1014 if ( MEDIA_CONTENT_ERROR_NONE
1015 != media_info_set_display_name (media, mediaPtr->getDisplayName().c_str()))
1017 LogDebug("Error: set displayname");
1021 if(type.compare("IMAGE") ==0 )
1023 MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
1027 image_meta_h img=NULL;
1028 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img))
1030 if(imagePtr->isChangedOrientaion())
1032 if ( MEDIA_CONTENT_ERROR_NONE !=
1033 image_meta_set_orientation (img, convertToOrientation(imagePtr->getImageOrientation())))
1035 LogDebug("Error: set orientation");
1040 if ( MEDIA_CONTENT_ERROR_NONE !=
1041 media_info_set_latitude(media, imagePtr->getImageLatitude())
1044 LogDebug("Error: set Latitude");
1048 if ( MEDIA_CONTENT_ERROR_NONE !=
1049 media_info_set_longitude(media, imagePtr->getImageLongitude())
1052 LogDebug("Error: set Longitude");
1056 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_update_to_db (img) )
1058 LogDebug("Error: update db");
1062 if ( MEDIA_CONTENT_ERROR_NONE != image_meta_destroy(img))
1064 LogDebug("Error: destroy media info");
1073 LogDebug("Error: get Image from DB");
1080 if(type.compare("VIDEO") ==0 )
1082 MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
1086 video_meta_h video = NULL;
1087 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(media, &video))
1090 if ( videoPtr->isChangedPlayCount() )
1092 if ( MEDIA_CONTENT_ERROR_NONE !=
1093 video_meta_set_played_count (video, videoPtr->getVideoPlayCount()))
1095 LogDebug("Error: set play count");
1101 if (videoPtr->isChangedPlayedTime())
1103 if ( MEDIA_CONTENT_ERROR_NONE !=
1104 video_meta_set_played_position (video, videoPtr->getVideoPlayedTime()))
1106 LogDebug("Error: set played time");
1111 if (videoPtr->isChangedAlbum())
1113 LogDebug("Not support - Album API");
1117 if (videoPtr->isChangedArtists())
1119 LogDebug("Not support - Artist API");
1123 if ( MEDIA_CONTENT_ERROR_NONE !=
1124 media_info_set_latitude(media, videoPtr->getVideoLatitude())
1127 LogDebug("Error: set Latitude");
1131 if ( MEDIA_CONTENT_ERROR_NONE !=
1132 media_info_set_longitude(media, videoPtr->getVideoLongitude())
1135 LogDebug("Error: set Latitude");
1140 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_update_to_db (video) )
1142 LogDebug("Error: update db");
1146 if ( MEDIA_CONTENT_ERROR_NONE != video_meta_destroy(video))
1148 LogDebug("Error: destroy video meta");
1161 if(type.compare("AUDIO") ==0 )
1164 MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
1165 if (audioPtr && ( audioPtr->isChangedAudioArtist () || audioPtr->isChangedAudioAlbum()
1166 || audioPtr->isChangedAudioGenre() ||audioPtr->isChangedAudioComposer()
1167 || audioPtr->isChangedAudioTrackNumber()) )
1170 audio_meta_h audio=NULL;
1171 if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(media, &audio))
1174 if ( audioPtr->isChangedPlayCount() )
1176 if ( MEDIA_CONTENT_ERROR_NONE !=
1177 audio_meta_set_played_count (audio, audioPtr->getAudioPlayCount()))
1179 LogDebug("Error: set play count");
1184 if (audioPtr->isChangedPlayedTime())
1186 if ( MEDIA_CONTENT_ERROR_NONE !=
1187 audio_meta_set_played_position (audio, audioPtr->getAudioPlayedTime()))
1189 LogDebug("Error: set played time");
1194 if (audioPtr->isChangedAudioArtist())
1196 LogDebug("Not Support API");
1200 if (audioPtr->isChangedAudioAlbum())
1202 LogDebug("Not Support API");
1206 if (audioPtr->isChangedAudioGenre())
1208 LogDebug("Not Support API");
1212 if (audioPtr->isChangedAudioComposer())
1214 LogDebug("Not Support API");
1218 if (audioPtr->isChangedAudioTrackNumber())
1220 LogDebug("Not Support API");
1224 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_update_to_db (audio) )
1226 LogDebug("Error: update db");
1230 if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_destroy(audio))
1232 LogDebug("Error: destroy audio meta");
1244 if ( MEDIA_CONTENT_ERROR_NONE != media_info_update_to_db(media))
1246 LogDebug("Error: update to DB");
1253 if ( MEDIA_CONTENT_ERROR_NONE !=media_info_destroy(media))
1255 LogDebug("Error: destroy media info");
1263 void MediacontentManager::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
1265 LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
1268 MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
1270 if(updateMediaToDB(mediaPtr))
1272 eMedia->setResult(true);
1273 LogDebug("update success");
1277 eMedia->setResult(false);
1278 ThrowMsg(PlatformException, "DB operation is failed");
1281 catch (const Exception &ex)
1283 LogError("Exception: " << ex.DumpToString());
1284 eMedia->setResult(false);
1289 void MediacontentManager::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
1291 LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
1295 MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
1296 if (mediaListPtr->empty())
1298 LogDebug("Item vector is empty");
1302 for(unsigned int i=0; i<mediaListPtr->size(); i++)
1305 MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
1306 if(updateMediaToDB(mediaPtr))
1308 eItems->setResult(true);
1309 LogDebug("update success");
1313 eItems->setResult(false);
1314 ThrowMsg(PlatformException, "DB operation is failed");
1320 catch (const Exception &ex)
1322 LogError("Exception: " << ex.DumpToString());
1323 eItems->setResult(false);
1325 //eItems->setCancelAllowed(false);