From d37cbb34aa3a28ad037e49747311611edcde5be9 Mon Sep 17 00:00:00 2001
From: Pawel Andruszkiewicz
Date: Wed, 29 Jul 2015 14:27:48 +0200
Subject: [PATCH] [Content] Error messages were not propagated properly.
[Verification] Mobile TCT pass rate: 230/230
Change-Id: I9e962ed0f985efe96f9889aeaee33e1805929bcc
Signed-off-by: Pawel Andruszkiewicz
---
src/content/content_instance.cc | 10 ++--
src/content/content_instance.h | 12 +++--
src/content/content_manager.cc | 88 ++++++++++-----------------------
3 files changed, 40 insertions(+), 70 deletions(-)
diff --git a/src/content/content_instance.cc b/src/content/content_instance.cc
index 175b47e4..1e7ec05a 100755
--- a/src/content/content_instance.cc
+++ b/src/content/content_instance.cc
@@ -84,7 +84,7 @@ static gboolean CompletedCallback(const std::shared_ptr& user
ReportSuccess(user_data->result, out);
} else {
LoggerE("Failed: user_data->isSuccess");
- ReportError(out);
+ ReportError(user_data->isSuccess, &out);
}
user_data->instance->PostMessage(picojson::value(out).serialize().c_str());
@@ -95,7 +95,6 @@ static gboolean CompletedCallback(const std::shared_ptr& user
static void* WorkThread(const std::shared_ptr& user_data) {
LoggerD("entered");
- user_data->isSuccess = true;
ContentCallbacks cbType = user_data->cbType;
switch(cbType) {
case ContentManagerUpdatebatchCallback: {
@@ -115,7 +114,8 @@ static void* WorkThread(const std::shared_ptr& user_data) {
int res = ContentManager::getInstance()->scanFile(contentURI);
if (res != MEDIA_CONTENT_ERROR_NONE) {
LOGGER(ERROR) << "Scan file failed, error: " << res;
- user_data->isSuccess = false;
+ common::PlatformResult err(common::ErrorCode::UNKNOWN_ERR, "Scan file failed.");
+ user_data->isSuccess = err;
}
break;
}
@@ -126,7 +126,6 @@ static void* WorkThread(const std::shared_ptr& user_data) {
case ContentManagerCreateplaylistCallback: {
if (user_data->args.contains("sourcePlaylist")) {
picojson::object playlist = user_data->args.get("sourcePlaylist").get();
- user_data->isSuccess = true;
user_data->result = picojson::value(playlist);
}
else{
@@ -164,8 +163,7 @@ static void* WorkThread(const std::shared_ptr& user_data) {
}
case ContentManagerErrorCallback: {
common::PlatformResult err(common::ErrorCode::UNKNOWN_ERR, "DB Connection is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
break;
}
default: {
diff --git a/src/content/content_instance.h b/src/content/content_instance.h
index be795028..c8f20c75 100755
--- a/src/content/content_instance.h
+++ b/src/content/content_instance.h
@@ -74,14 +74,20 @@ class ContentInstance : public common::ParsedInstance {
void PlaylistSetThumbnailUri(const picojson::value& args, picojson::object& out);
};
-typedef struct _ReplyCallbackData{
+typedef struct _ReplyCallbackData {
+ _ReplyCallbackData()
+ : instance(nullptr),
+ cbType(ContentManagerFindCallback),
+ callbackId(-1.0),
+ isSuccess(common::ErrorCode::NO_ERROR) {
+ }
ContentInstance* instance;
ContentCallbacks cbType;
double callbackId;
- bool isSuccess;
picojson::value args;
picojson::value result;
-}ReplyCallbackData;
+ common::PlatformResult isSuccess;
+} ReplyCallbackData;
} // namespace content
diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc
index e351a5f3..87efc065 100755
--- a/src/content/content_manager.cc
+++ b/src/content/content_manager.cc
@@ -698,12 +698,10 @@ void ContentManager::getDirectories(const std::shared_ptr& us
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: Getting the directories failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Getting the directories failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
- user_data->isSuccess = true;
user_data->result = picojson::value(pico_dirs);
}
@@ -787,13 +785,11 @@ void ContentManager::find(const std::shared_ptr& user_data) {
}
if (ret == MEDIA_CONTENT_ERROR_NONE) {
- user_data->isSuccess = true;
user_data->result = picojson::value(arrayContent);
} else {
LoggerE("The iteration failed in platform: %d", ret);
PlatformResult err(ErrorCode::UNKNOWN_ERR, "The iteration failed in platform");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
}
}
@@ -855,10 +851,10 @@ void ContentManager::createPlaylist(std::string name,
std::unique_ptr::type, int(*)(media_playlist_h)>
playlist_ptr(playlist, &media_playlist_destroy); // automatically release the memory
if(ret != MEDIA_CONTENT_ERROR_NONE) {
- LoggerE("Failed: creation of playlist is failed");
- PlatformResult err(ErrorCode::UNKNOWN_ERR, "creation of playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ LoggerE("Failed: creation of playlist is failed: %d", ret);
+ // MEDIA_CONTENT_ERROR_DB_FAILED means that playlist probably already exists
+ PlatformResult err(MEDIA_CONTENT_ERROR_DB_FAILED == ret ? ErrorCode::INVALID_VALUES_ERR : ErrorCode::UNKNOWN_ERR, "Creation of playlist has failed.");
+ user_data->isSuccess = err;
return;
}
picojson::value::object o;
@@ -874,8 +870,7 @@ void ContentManager::createPlaylist(std::string name,
else {
LoggerE("Failed: loading of playlist is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "loading of playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
if( media_playlist_get_thumbnail_path(playlist, &thumb_path) == MEDIA_CONTENT_ERROR_NONE) {
@@ -908,9 +903,8 @@ void ContentManager::createPlaylist(std::string name,
LoggerE("Invalid count for playlist.");
}
}
- user_data->isSuccess = true;
- user_data->result = picojson::value(o);
+ user_data->result = picojson::value(o);
}
void ContentManager::getPlaylists(const std::shared_ptr& user_data) {
@@ -928,10 +922,9 @@ void ContentManager::getPlaylists(const std::shared_ptr& user
if(ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: Getting playlist is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Getting playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
}
- user_data->isSuccess = true;
+
user_data->result = picojson::value(playlists);
}
@@ -943,8 +936,7 @@ void ContentManager::removePlaylist(std::string playlistId,
if(id == 0) {
LoggerE("Failed: PlaylistId is wrong");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "PlaylistId is wrong.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
@@ -952,8 +944,7 @@ void ContentManager::removePlaylist(std::string playlistId,
if(ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: Removal of playlist is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Removal of playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
}
}
@@ -1058,8 +1049,7 @@ void ContentManager::playlistAddbatch(const std::shared_ptr&
if(ret != MEDIA_CONTENT_ERROR_NONE && playlist == NULL) {
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Getting playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
@@ -1076,8 +1066,7 @@ void ContentManager::playlistAddbatch(const std::shared_ptr&
ret = media_playlist_update_to_db(playlist);
if(ret != MEDIA_CONTENT_ERROR_NONE ) {
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Adding playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
}
media_playlist_destroy(playlist);
}
@@ -1095,8 +1084,7 @@ void ContentManager::playlistGet(const std::shared_ptr& user_
if(ret != MEDIA_CONTENT_ERROR_NONE && playlist == NULL) {
LoggerE("Failed: Getting playlist is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Getting playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
@@ -1105,8 +1093,7 @@ void ContentManager::playlistGet(const std::shared_ptr& user_
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: Creating a filter is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Creating a filter is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
@@ -1127,14 +1114,12 @@ void ContentManager::playlistGet(const std::shared_ptr& user_
media_filter_destroy(filter);
if (ret == MEDIA_CONTENT_ERROR_NONE) {
- user_data->isSuccess = true;
user_data->result = picojson::value(arrayContent);
}
else {
LoggerE("Failed: Creating a filter is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Creating a filter is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
}
}
@@ -1148,8 +1133,7 @@ void ContentManager::playlistRemovebatch(const std::shared_ptrisSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
@@ -1168,11 +1152,7 @@ void ContentManager::playlistRemovebatch(const std::shared_ptrisSuccess = false;
- user_data->result = err.ToJSON();
- }
- else {
- user_data->isSuccess = true;
+ user_data->isSuccess = err;
}
}
@@ -1186,8 +1166,7 @@ void ContentManager::playlistSetOrder(const std::shared_ptr&
ret = media_playlist_get_playlist_from_db(std::stoi(playlist_id), &playlist);
if(ret != MEDIA_CONTENT_ERROR_NONE && playlist == NULL) {
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Getting playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
@@ -1199,16 +1178,14 @@ void ContentManager::playlistSetOrder(const std::shared_ptr&
{
LoggerE("Failed: media_playlist_get_media_count_from_db");
PlatformResult err = convertError(ret);
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
std::size_t members_size = members.size();
if (cnt < 0 || static_cast(cnt) != members_size ) {
LoggerE("Failed: The items array does not contain all items from the playlist");
PlatformResult err(ErrorCode::INVALID_VALUES_ERR, "The items array does not contain all items from the playlist.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
@@ -1224,11 +1201,7 @@ void ContentManager::playlistSetOrder(const std::shared_ptr&
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: Removing the contents is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Removing the contents is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
- }
- else {
- user_data->isSuccess = true;
+ user_data->isSuccess = err;
}
}
@@ -1241,8 +1214,7 @@ void ContentManager::playlistMove(const std::shared_ptr& user
if(ret != MEDIA_CONTENT_ERROR_NONE && playlist == NULL) {
LoggerE("Failed: Getting playlist is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Getting playlist is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
int old_order;
@@ -1252,8 +1224,7 @@ void ContentManager::playlistMove(const std::shared_ptr& user
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: The content can't find form playlist");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "The content can't find form playlist.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
int new_order = static_cast(old_order) + static_cast(delta);
@@ -1261,19 +1232,14 @@ void ContentManager::playlistMove(const std::shared_ptr& user
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: The content can't update play_order");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "The content can't update play_order.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
+ user_data->isSuccess = err;
return;
}
ret = media_playlist_update_to_db(playlist);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
LoggerE("Failed: Updateing play_order is failed");
PlatformResult err(ErrorCode::UNKNOWN_ERR, "Updateing play_order is failed.");
- user_data->isSuccess = false;
- user_data->result = err.ToJSON();
- }
- else {
- user_data->isSuccess = true;
+ user_data->isSuccess = err;
}
}
--
2.34.1