[Mediacontroller] Fixed issue with invalid name of enum 20/212320/3 accepted/tizen/unified/20190821.064558 submit/tizen/20190820.115734
authorPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/삼성전자 <p.kosko@samsung.com>
Tue, 20 Aug 2019 08:09:05 +0000 (10:09 +0200)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/삼성전자 <p.kosko@samsung.com>
Tue, 20 Aug 2019 10:41:32 +0000 (12:41 +0200)
[Bug]
1. wrong value of enum NONE instead of NO_CATEGORY
2. invalid parsing of empty keyword, which caused crash

[Verification] Code compiles without errors.
  Tested in chrome console with code:
var server = tizen.mediacontroller.createServer();
function searchRequestListener(clientName, request)
{
  console.log("search command received");
  return new tizen.mediacontroller.RequestReply(new tizen.Bundle({"key": "value"}), 5);
}
server.setSearchRequestListener(searchRequestListener);
server.updatePlaybackState("PLAY");

/* Client-side code */
var client = tizen.mediacontroller.getClient();
var sinfo = client.getLatestServerInfo();

var query = [
  new tizen.mediacontroller.SearchFilter("MUSIC")
];

sinfo.sendSearchRequest(query, function(reply)
{
  console.log("reply status: " + reply.code);
  console.log("reply data: " + reply.data);
});

Change-Id: Ie522f07286bf4604fe43428b716d6d808abbea07

src/mediacontroller/mediacontroller_api.js
src/mediacontroller/mediacontroller_client.cc
src/mediacontroller/mediacontroller_server.cc
src/mediacontroller/mediacontroller_utils.cc

index 0f3fe43..aef8c56 100755 (executable)
@@ -1545,13 +1545,16 @@ MediaControllerServerInfo.prototype.sendSearchRequest = function(
         listenerId: ReplyCommandListener.listenerName
     };
 
-    var replyListenerId = ReplyCommandListener.addListener(callback);
     var result = native_.callSync(
         'MediaControllerServerInfo_sendSearchRequest',
         nativeData,
         callback
     );
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
 
+    var replyListenerId = ReplyCommandListener.addListener(callback);
     ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
 };
 
index 2346c2a..cce9ce4 100644 (file)
@@ -599,8 +599,14 @@ PlatformResult MediaControllerClient::SendSearchRequest(const std::string& serve
                                 ("JsonToBundle() error message: %s", result.message().c_str()));
     }
 
-    ret = mc_search_set_condition(search_request, content_type_e, search_category_e,
-                                  filter.at("keyword").get<std::string>().c_str(), bundle_data);
+    // keyword
+    // null is valid search keyword in case of NO_CATEGORY
+    char* search_keyword = nullptr;
+    if (filter.at("keyword").is<std::string>()) {
+      search_keyword = (char*)filter.at("keyword").get<std::string>().c_str();
+    }
+    ret = mc_search_set_condition(search_request, content_type_e, search_category_e, search_keyword,
+                                  bundle_data);
 
     if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
       return LogAndCreateResult(
index ef3c0fd..37e6212 100644 (file)
@@ -342,7 +342,12 @@ void MediaControllerServer::OnSearchRequestReceived(const char* client_name, con
     }
     object["category"] = picojson::value(temp);
 
-    object["keyword"] = picojson::value(std::string(keyword));
+    if (keyword) {
+      object["keyword"] = picojson::value(std::string(keyword));
+    } else {
+      // null is valid search keyword in case of NO_CATEGORY
+      object["keyword"] = picojson::value();
+    }
 
     picojson::value data_json;
     result = common::BundleToJson(data, &data_json);
index 2f3aaa5..7df8487 100644 (file)
@@ -88,8 +88,12 @@ const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum{
     {"UNDECIDED", MC_CONTENT_TYPE_UNDECIDED}};
 
 const common::PlatformEnum<mc_search_category_e> MediaControllerSearchCategoryEnum{
-    {"NONE", MC_SEARCH_NO_CATEGORY}, {"TITLE", MC_SEARCH_TITLE}, {"ARTIST", MC_SEARCH_ARTIST},
-    {"ALBUM", MC_SEARCH_ALBUM},      {"GENRE", MC_SEARCH_GENRE}, {"TPO", MC_SEARCH_TPO}};
+    {"NO_CATEGORY", MC_SEARCH_NO_CATEGORY},
+    {"TITLE", MC_SEARCH_TITLE},
+    {"ARTIST", MC_SEARCH_ARTIST},
+    {"ALBUM", MC_SEARCH_ALBUM},
+    {"GENRE", MC_SEARCH_GENRE},
+    {"TPO", MC_SEARCH_TPO}};
 
 PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state) {
   ScopeLogger();