void ContentInstance::ContentManagerUpdate(const picojson::value& args, picojson::object& out) {
int ret;
- if(ContentManager::getInstance()->isConnected()) {
+ if (ContentManager::getInstance()->isConnected()) {
ret = ContentManager::getInstance()->update(args);
- if(ret != 0) {
- ReportError(ContentManager::getInstance()->convertError(ret),out);
+ if (ret != 0) {
+ ReportError(ContentManager::getInstance()->convertError(ret), out);
}
- }
- else {
- ReportError(common::UnknownException("DB connection is failed."),out);
+ } else {
+ ReportError(common::UnknownException("DB connection is failed."), out);
}
}
+
void ContentInstance::ContentManagerUpdatebatch(const picojson::value& args, picojson::object& out) {
LoggerE("entered");
double callbackId = args.get("callbackId").get<double>();
#include <algorithm>
#include <cstring>
-#include <dlog.h>
#include <map>
#include <metadata_extractor.h>
#include <sstream>
}
}
-static int setContent(media_info_h media, picojson::value content) {
+static int setContent(media_info_h media, const picojson::value& content) {
+ LOGGER(DEBUG) << "entered";
int ret;
std::string name = content.get("name").to_str();
std::string description = content.get("description").to_str();
- std::string rating = content.get("rating").to_str();
- std::string is_fav = content.get("isFavorite").to_str();
- if (media != NULL) {
- media_content_type_e type;
- ret = media_info_get_media_type(media, &type);
- if (ret != MEDIA_CONTENT_ERROR_NONE ) {
- return ret;
- }
- ret = media_info_set_display_name(media, name.c_str());
- if ( ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerD("Updating name is failed.");
- }
- ret = media_info_set_description(media, description.c_str());
- if ( ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerD("Updating description is failed.");
- }
- ret = media_info_set_rating(media, std::stoi(rating));
- if ( ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerD("Updating rating is failed.");
- }
+ int rating = std::stoi(content.get("rating").to_str());
+ bool is_fav = content.get("isFavorite").get<bool>();
- if (is_fav == "true") {
- ret = media_info_set_favorite(media, true);
- }
- else if (is_fav == "false") {
- ret = media_info_set_favorite(media, false);
- }
+ if (NULL == media) {
+ return MEDIA_CONTENT_ERROR_DB_FAILED;
+ }
- if ( ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerD("Updating favorite is failed.");
- }
- if (type == MEDIA_CONTENT_TYPE_IMAGE) {
- std::string orientation = content.get("orientation").to_str();
- auto orientationToSet = orientationMap.find(orientation);
-
- if (orientationToSet != orientationMap.end()) {
- image_meta_h img;
- if(MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img) &&
- MEDIA_CONTENT_ERROR_NONE == image_meta_set_orientation(img, orientationToSet->second) &&
- MEDIA_CONTENT_ERROR_NONE == image_meta_update_to_db(img)) {
- LoggerD("orientation update was successful");
- } else {
- LoggerD("orientation update failed");
- }
- }
- }
- if (type == MEDIA_CONTENT_TYPE_IMAGE || type == MEDIA_CONTENT_TYPE_VIDEO) {
- picojson::value geo = content.get("geolocation");
- double latitude = atof(geo.get("latitude").to_str().c_str());
- double longitude = atof(geo.get("longitude").to_str().c_str());
- ret = media_info_set_latitude(media, latitude);
- if ( ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerD("Updating geolocation is failed.");
- }
- ret = media_info_set_longitude(media, longitude);
- if ( ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerD("Updating geolocation is failed.");
+ media_content_type_e type;
+ ret = media_info_get_media_type(media, &type);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ return ret;
+ }
+
+ ret = media_info_set_display_name(media, name.c_str());
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerD("Updating name failed.");
+ }
+
+ ret = media_info_set_description(media, description.c_str());
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerD("Updating description failed.");
+ }
+
+ ret = media_info_set_rating(media, rating);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerD("Updating rating failed.");
+ }
+
+ ret = media_info_set_favorite(media, is_fav);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerD("Updating isFavorite failed.");
+ }
+
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerD("Updating favorite failed.");
+ }
+
+ if (type == MEDIA_CONTENT_TYPE_IMAGE) {
+ std::string orientation = content.get("orientation").to_str();
+ auto orientationToSet = orientationMap.find(orientation);
+
+ if (orientationToSet != orientationMap.end()) {
+ image_meta_h img;
+ if (MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img) &&
+ MEDIA_CONTENT_ERROR_NONE == image_meta_set_orientation(img, orientationToSet->second) &&
+ MEDIA_CONTENT_ERROR_NONE == image_meta_update_to_db(img)) {
+ LoggerD("orientation update was successful");
+ } else {
+ LoggerD("orientation update failed");
}
}
- ret = MEDIA_CONTENT_ERROR_NONE;
}
- else {
- ret = MEDIA_CONTENT_ERROR_DB_FAILED;
+
+ if (type == MEDIA_CONTENT_TYPE_IMAGE || type == MEDIA_CONTENT_TYPE_VIDEO) {
+ picojson::value geo = content.get("geolocation");
+ double latitude = atof(geo.get("latitude").to_str().c_str());
+ double longitude = atof(geo.get("longitude").to_str().c_str());
+ ret = media_info_set_latitude(media, latitude);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerD("Updating geolocation is failed.");
+ }
+ ret = media_info_set_longitude(media, longitude);
+ if (ret != MEDIA_CONTENT_ERROR_NONE) {
+ LoggerD("Updating geolocation is failed.");
+ }
}
- return ret;
+
+ return MEDIA_CONTENT_ERROR_NONE;
}
static bool media_foreach_directory_cb(media_folder_h folder, void *user_data) {
}
int ContentManager::update(picojson::value args) {
+ LOGGER(DEBUG) << "entered";
+
int ret;
picojson::value content = args.get("content");
std::string id = content.get("id").to_str();
media_info_h media = NULL;
- ret = media_info_get_media_from_db (id.c_str(), &media);
- if (media != NULL) {
+ ret = media_info_get_media_from_db(id.c_str(), &media);
+ if (ret == MEDIA_CONTENT_ERROR_NONE) {
setContent(media, content);
ret = media_info_update_to_db(media);
+ media_info_destroy(media);
}
- else {
- LoggerD("There is no content(%s)",id.c_str());
- ret = MEDIA_CONTENT_ERROR_NONE;
- }
+
return ret;
}
var SCHEMA = 'file://';
+function createContentObject_(data) {
+ switch (data.type) {
+ case ContentType.IMAGE:
+ return new ImageContent(data);
+ break;
+ case ContentType.AUDIO:
+ return new AudioContent(data);
+ break;
+ case ContentType.VIDEO:
+ return new VideoContent(data);
+ break;
+ case ContentType.OTHER:
+ return new Content(data);
+ break;
+ }
+
+ throw new WebAPIException(WebAPIException.UNKNOWN_ERR, 'Undefined content type');
+}
+
function convertUriToPath_(uri) {
if (0 === uri.indexOf(SCHEMA)) {
return uri.substring(SCHEMA.length);
}
-function VideoContent() {
+function VideoContent(data) {
+ Content.call(this, data);
+
// TODO(r.galka)
//this.geolocation = null;
//SetReadOnlyProperty(this, 'album', null); // read only property
}
-function AudioContent() {
+function AudioContent(data) {
+ Content.call(this, data);
+
// TODO(r.galka)
//SetReadOnlyProperty(this, 'album', null); // read only property
//SetReadOnlyProperty(this, 'genres', null); // read only property
AudioContent.prototype.constructor = AudioContent;
-function ImageContent() {
- // TODO(r.galka)
+function ImageContent(data) {
+ Content.call(this, data);
+
+ var geolocation;
+ var width;
+ var height;
+ var orientation;
+
//this.geolocation = null;
//SetReadOnlyProperty(this, 'width', null); // read only property
//SetReadOnlyProperty(this, 'height', null); // read only property
function _ContentManagerChangeCallback(result) {
if (result.state === 'oncontentadded' || result.state === 'oncontentupdated') {
var content = native_.getResultObject(result);
- native_.callIfPossible(this[result.state], new Content(content));
+ native_.callIfPossible(this[result.state], createContentObject_(content));
}
if (result.state === 'oncontentremoved') {
native_.callIfPossible(this.oncontentremoved, native_.getResultObject(result));
ContentManager.prototype.update = function(content) {
var args = validator_.validateArgs(arguments, [
- {name: 'content', type: types_.PLATFORM_OBJECT, values: tizen.Content}
+ {name: 'content', type: types_.PLATFORM_OBJECT, values: Content}
]);
var data = {
ContentManager.prototype.updateBatch = function(contents, successCallback, errorCallback) {
var args = validator_.validateArgs(arguments, [
- {name: 'contents', type: types_.PLATFORM_OBJECT, values: tizen.Content},
+ {name: 'contents', type: types_.PLATFORM_OBJECT, values: Content},
{name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true},
{name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
]);
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- native_.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback, native_.getResultObject(result));
};
native_.call('ContentManager_getDirectories', data, callback);
return;
}
- native_.callIfPossible(args.successCallback, native_.getResultObject(result));
+ var out = [];
+ result = native_.getResultObject(result);
+ for (var i = 0, max = result.length; i < max; i++) {
+ out.push(createContentObject_(result[i]));
+ }
+
+ native_.callIfPossible(args.successCallback, out);
};
native_.call('ContentManager_find', data, callback);
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- native_.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback, native_.getResultObject(result));
};
native_.call('ContentManager_getPlaylists', data, callback);
{name: 'name', type: types_.STRING},
{name: 'successCallback', type: types_.FUNCTION},
{name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true},
- {name: 'sourcePlaylist', type: types_.PLATFORM_OBJECT, values: tizen.Playlist, optional: true, nullable: true}
+ {name: 'sourcePlaylist', type: types_.PLATFORM_OBJECT, values: Playlist, optional: true, nullable: true}
]);
var data = {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- native_.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback, native_.getResultObject(result));
};
native_.call('ContentManager_createPlaylist', data, callback);
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- native_.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback, native_.getResultObject(result));
};
native_.call('Playlist_get', data, callback);