[Content] Divided listener for files and directories
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 17 Sep 2015 06:42:00 +0000 (08:42 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 17 Sep 2015 08:17:23 +0000 (10:17 +0200)
[Feature] Divided listeners for files and directories in c++ layer.

[Verification] Code compiles without errors.
  Listener calls checked for add, update, remove of files and dirs.
  TCT passrate didn't change.

Change-Id: If9e5d8962358f532276f46d910b5cc89836262d2
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/content/content_instance.cc
src/content/content_manager.cc
src/content/content_manager.h

index 06630282ea3884de2d38854d8c42d14b4673bc76..990905268d31ac915fa93a748d7b68c1a58ad4a9 100755 (executable)
@@ -216,25 +216,25 @@ static void changedContentCallback(media_content_error_e error,
                                    char* path,
                                    char* mime_type,
                                    void* user_data) {
-  LoggerD("Enter");
-
-  ReplyCallbackData* cbData = static_cast<ReplyCallbackData*>(user_data);
-
-  if (!uuid) {
-    LOGGER(ERROR) << "Provided uuid is NULL, ignoring";
-    return;
-  }
+  LoggerD("Entered file change callback");
 
   if (error != MEDIA_CONTENT_ERROR_NONE) {
     LOGGER(ERROR) << "Media content changed callback error: " << error;
     return;
   }
 
-  int ret;
-  picojson::value result = picojson::value(picojson::object());
-  picojson::object& obj = result.get<picojson::object>();
-
   if (update_item == MEDIA_ITEM_FILE) {
+    if (!uuid) {
+      LOGGER(ERROR) << "Provided uuid is NULL, ignoring";
+      return;
+    }
+
+    ReplyCallbackData* cbData = static_cast<ReplyCallbackData*>(user_data);
+
+    int ret;
+    picojson::value result = picojson::value(picojson::object());
+    picojson::object& obj = result.get<picojson::object>();
+
     if (update_type == MEDIA_CONTENT_INSERT || update_type == MEDIA_CONTENT_UPDATE) {
       media_info_h media = NULL;
       ret = media_info_get_media_from_db(uuid, &media);
@@ -256,7 +256,43 @@ static void changedContentCallback(media_content_error_e error,
       ReportSuccess(picojson::value(std::string(uuid)), obj);
       obj["state"] = picojson::value("oncontentremoved");
     }
-  } else if (update_item == MEDIA_ITEM_DIRECTORY) {
+
+    obj["listenerId"] = cbData->args.get("listenerId");
+    common::Instance::PostMessage(cbData->instance, result.serialize().c_str());
+  } else {
+    LOGGER(DEBUG) << "Media item is not a file, skipping.";
+    return;
+  }
+}
+
+static void changedContentV2Callback(media_content_error_e error,
+                                   int pid,
+                                   media_content_db_update_item_type_e update_item,
+                                   media_content_db_update_type_e update_type,
+                                   media_content_type_e media_type,
+                                   char* uuid,
+                                   char* path,
+                                   char* mime_type,
+                                   void* user_data) {
+  LoggerD("Entered directory change callback");
+
+  if (error != MEDIA_CONTENT_ERROR_NONE) {
+    LOGGER(ERROR) << "Media content changed v2 callback error: " << error;
+    return;
+  }
+
+  if (update_item == MEDIA_ITEM_DIRECTORY) {
+    if (!uuid) {
+      LOGGER(ERROR) << "Provided uuid is NULL, ignoring";
+      return;
+    }
+
+    ReplyCallbackData* cbData = static_cast<ReplyCallbackData*>(user_data);
+
+    int ret;
+    picojson::value result = picojson::value(picojson::object());
+    picojson::object& obj = result.get<picojson::object>();
+
     if (update_type == MEDIA_CONTENT_INSERT || update_type == MEDIA_CONTENT_UPDATE) {
       media_folder_h folder = NULL;
       ret = media_folder_get_folder_from_db(uuid, &folder);
@@ -278,16 +314,15 @@ static void changedContentCallback(media_content_error_e error,
       ReportSuccess(picojson::value(std::string(uuid)), obj);
       obj["state"] = picojson::value("oncontentdirremoved");
     }
+
+    obj["listenerId"] = cbData->args.get("listenerId");
+    common::Instance::PostMessage(cbData->instance, result.serialize().c_str());
   } else {
-    LOGGER(DEBUG) << "Media item is not a file and not directory, skipping.";
+    LOGGER(DEBUG) << "Media item is not directory, skipping.";
     return;
   }
-
-  obj["listenerId"] = cbData->args.get("listenerId");
-  common::Instance::PostMessage(cbData->instance, result.serialize().c_str());
 }
 
-
 #define CHECK_EXIST(args, name, out) \
   if (!args.contains(name)) {\
     ReportError(common::PlatformResult(common::ErrorCode::TYPE_MISMATCH_ERR, (name" is required argument")), &out);\
@@ -432,8 +467,12 @@ void ContentInstance::ContentManagerSetchangelistener(const picojson::value& arg
     listener_data_->cbType = ContentManagerErrorCallback;
   }
 
-  if (ContentManager::getInstance()->setChangeListener(&noti_handle_,
-                                                       changedContentCallback,
+  if (ContentManager::getInstance()->setChangeListener(changedContentCallback,
+                                                       static_cast<void*>(listener_data_)).IsError()) {
+    ReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "The callback did not register properly"), &out);
+  }
+  if (ContentManager::getInstance()->setV2ChangeListener(&noti_handle_,
+                                                       changedContentV2Callback,
                                                        static_cast<void*>(listener_data_)).IsError()) {
     ReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "The callback did not register properly"), &out);
   }
@@ -441,7 +480,10 @@ void ContentInstance::ContentManagerSetchangelistener(const picojson::value& arg
 
 void ContentInstance::ContentManagerUnsetchangelistener(const picojson::value& args, picojson::object& out) {
   LoggerD("entered");
-  if (ContentManager::getInstance()->unSetChangeListener(&noti_handle_).IsError()) {
+  if (ContentManager::getInstance()->unSetChangeListener().IsError()) {
+    LoggerD("unsuccesfull deregistering of callback");
+  }
+  if (ContentManager::getInstance()->unSetV2ChangeListener(&noti_handle_).IsError()) {
     LoggerD("unsuccesfull deregistering of callback");
   }
 }
index 9a7553d9e9367eadca92d3b751dc5a67ccd6faee..f06efa810bd3b73bea8de9219cd7f257c240616c 100755 (executable)
@@ -840,8 +840,7 @@ PlatformResult ContentManager::cancelScanDirectory(const std::string& content_di
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult ContentManager::setChangeListener(media_content_noti_h* noti_handle,
-                                                 media_content_db_update_cb callback,
+PlatformResult ContentManager::setChangeListener(media_content_db_update_cb callback,
                                                  void *user_data) {
   LoggerD("Enter");
 
@@ -850,17 +849,10 @@ PlatformResult ContentManager::setChangeListener(media_content_noti_h* noti_hand
     LoggerE("Failed: registering the listener is failed");
     return PlatformResult(ErrorCode::UNKNOWN_ERR, ("registering the listener is failed."));
   }
-
-  ret = media_content_set_db_updated_cb_v2(noti_handle, callback, user_data);
-  if(ret != MEDIA_CONTENT_ERROR_NONE) {
-    LoggerE("Failed: registering the listener of cb_v2 is failed");
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, ("registering the listener is failed."));
-  }
-
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult ContentManager::unSetChangeListener(media_content_noti_h* noti_handle) {
+PlatformResult ContentManager::unSetChangeListener() {
   LoggerD("Enter");
 
   int ret = media_content_unset_db_updated_cb();
@@ -868,8 +860,27 @@ PlatformResult ContentManager::unSetChangeListener(media_content_noti_h* noti_ha
     LoggerE("Failed: unregistering the listener is failed");
     return PlatformResult(ErrorCode::UNKNOWN_ERR, ("unregistering the listener is failed."));
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ContentManager::setV2ChangeListener(media_content_noti_h* noti_handle,
+                                                 media_content_db_update_cb callback,
+                                                 void *user_data) {
+  LoggerD("Enter");
+
+  int ret = media_content_set_db_updated_cb_v2(noti_handle, callback, user_data);
+  if(ret != MEDIA_CONTENT_ERROR_NONE) {
+    LoggerE("Failed: registering the listener of cb_v2 is failed");
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, ("registering the listener is failed."));
+  }
 
-  ret = media_content_unset_db_updated_cb_v2(*noti_handle);
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult ContentManager::unSetV2ChangeListener(media_content_noti_h* noti_handle) {
+  LoggerD("Enter");
+
+  int ret = media_content_unset_db_updated_cb_v2(*noti_handle);
   if(ret != MEDIA_CONTENT_ERROR_NONE) {
     LoggerE("Failed: unregistering the listener of cb_v2 is failed");
     return PlatformResult(ErrorCode::UNKNOWN_ERR, ("unregistering the listener is failed."));
@@ -879,6 +890,7 @@ PlatformResult ContentManager::unSetChangeListener(media_content_noti_h* noti_ha
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+
 void ContentManager::createPlaylist(std::string name,
   const std::shared_ptr<ReplyCallbackData>& user_data) {
   LoggerD("Enter");
index f2d4f04bc40c6be7bf52e7bb137ab4dfb0c6cb74..36b52d58730aa4cd97b396818443af0af2c25973 100755 (executable)
@@ -52,10 +52,13 @@ class ContentManager {
   int scanFile(std::string& uri);
   common::PlatformResult scanDirectory(media_scan_completed_cb callback, ReplyCallbackData* cbData);
   common::PlatformResult cancelScanDirectory(const std::string& content_dir_uri);
-  common::PlatformResult setChangeListener(media_content_noti_h* noti_handler,
+  common::PlatformResult setChangeListener(media_content_db_update_cb callback,
+                                           void *user_data);
+  common::PlatformResult unSetChangeListener();
+  common::PlatformResult setV2ChangeListener(media_content_noti_h* noti_handler,
                                            media_content_db_update_cb callback,
                                            void *user_data);
-  common::PlatformResult unSetChangeListener(media_content_noti_h* noti_handler);
+  common::PlatformResult unSetV2ChangeListener(media_content_noti_h* noti_handler);
 
 //Lyrics
   int getLyrics(const picojson::value& args,picojson::object& result);