[Content] - fixing problem with added/removed directory callbacks
authorAndrzej Popowski <a.popowski@samsung.com>
Fri, 11 Sep 2015 10:09:35 +0000 (12:09 +0200)
committerAndrzej Popowski <a.popowski@samsung.com>
Mon, 14 Sep 2015 11:15:01 +0000 (13:15 +0200)
Change-Id: Ib4266ead72a58788455df5918f8628301ce9399b
Signed-off-by: Andrzej Popowski <a.popowski@samsung.com>
src/content/content_instance.cc
src/content/content_instance.h
src/content/content_manager.cc
src/content/content_manager.h

index 3ea89ca..12a384a 100755 (executable)
@@ -27,6 +27,7 @@
 #include "common/picojson.h"
 #include "common/platform_result.h"
 #include "common/task-queue.h"
+#include "common/virtual_fs.h"
 #include "content/content_manager.h"
 
 namespace extension {
@@ -35,7 +36,7 @@ namespace content {
 using common::tools::ReportSuccess;
 using common::tools::ReportError;
 
-ContentInstance::ContentInstance() {
+ContentInstance::ContentInstance() : noti_handle_(nullptr) {
   using std::placeholders::_1;
   using std::placeholders::_2;
 
@@ -73,6 +74,10 @@ ContentInstance::ContentInstance() {
 
 ContentInstance::~ContentInstance() {
   LoggerD("entered");
+  if (noti_handle_) {
+    media_content_unset_db_updated_cb_v2(noti_handle_);
+    noti_handle_ = nullptr;
+  }
 }
 
 static gboolean CompletedCallback(const std::shared_ptr<ReplyCallbackData>& user_data) {
@@ -112,7 +117,8 @@ static void* WorkThread(const std::shared_ptr<ReplyCallbackData>& user_data) {
     }
     case ContentManagerScanfileCallback: {
       std::string contentURI = user_data->args.get("contentURI").get<std::string>();
-      int res = ContentManager::getInstance()->scanFile(contentURI);
+      std::string real_path = common::VirtualFs::GetInstance().GetRealPath(contentURI);
+      int res = ContentManager::getInstance()->scanFile(real_path);
       if (res != MEDIA_CONTENT_ERROR_NONE) {
         LOGGER(ERROR) << "Scan file failed, error: " << res;
         common::PlatformResult err(common::ErrorCode::UNKNOWN_ERR, "Scan file failed.");
@@ -260,7 +266,7 @@ static void changedContentCallback(media_content_error_e error,
       }
     } else {
       ReportSuccess(picojson::value(std::string(uuid)), obj);
-      obj["state"] = picojson::value("oncontendirremoved");
+      obj["state"] = picojson::value("oncontentdirremoved");
     }
   } else {
     LOGGER(DEBUG) << "Media item is not a file and not directory, skipping.";
@@ -415,14 +421,16 @@ void ContentInstance::ContentManagerSetchangelistener(const picojson::value& arg
     cbData->cbType = ContentManagerErrorCallback;
   }
 
-  if (ContentManager::getInstance()->setChangeListener(changedContentCallback, static_cast<void*>(cbData)).IsError()) {
+  if (ContentManager::getInstance()->setChangeListener(&noti_handle_,
+                                                       changedContentCallback,
+                                                       static_cast<void*>(cbData)).IsError()) {
     ReportError(common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "The callback did not register properly"), &out);
   }
 }
 
 void ContentInstance::ContentManagerUnsetchangelistener(const picojson::value& args, picojson::object& out) {
   LoggerD("entered");
-  if (ContentManager::getInstance()->unSetChangeListener().IsError()) {
+  if (ContentManager::getInstance()->unSetChangeListener(&noti_handle_).IsError()) {
     LoggerD("unsuccesfull deregistering of callback");
   }
 }
index 34cfc35..2a3b6b3 100755 (executable)
@@ -17,6 +17,7 @@
 #ifndef CONTENT_CONTENT_INSTANCE_H_
 #define CONTENT_CONTENT_INSTANCE_H_
 
+#include <media_content_internal.h>
 #include "common/extension.h"
 
 namespace extension {
@@ -73,6 +74,8 @@ class ContentInstance : public common::ParsedInstance {
   void PlaylistGetThumbnailUri(const picojson::value& args, picojson::object& out);
   void PlaylistSetThumbnailUri(const picojson::value& args, picojson::object& out);
   void PlaylistGetNumberOfTracks(const picojson::value& args, picojson::object& out);
+
+  media_content_noti_h noti_handle_;
 };
 
 typedef struct _ReplyCallbackData {
index 3d6de5e..cefdbe3 100755 (executable)
@@ -28,6 +28,7 @@
 #include "common/converter.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
+#include "common/virtual_fs.h"
 #include "content/content_filter.h"
 
 using namespace std;
@@ -807,9 +808,11 @@ int ContentManager::scanFile(std::string& uri) {
 PlatformResult ContentManager::scanDirectory(media_scan_completed_cb callback, ReplyCallbackData* cbData) {
   LoggerD("Enter");
   const std::string& contentDirURI = cbData->args.get("contentDirURI").get<std::string>();
+  std::string real_path = common::VirtualFs::GetInstance().GetRealPath(contentDirURI);
   const bool recursive = cbData->args.get("recursive").get<bool>();
 
-  int ret = media_content_scan_folder(contentDirURI.c_str(), recursive, callback, (void*) cbData);
+  int ret = media_content_scan_folder(real_path.c_str(), recursive, callback, (void*) cbData);
+
   if (ret != MEDIA_CONTENT_ERROR_NONE) {
     LoggerE("Scan folder failed in platform: %d", ret);
     if (MEDIA_CONTENT_ERROR_INVALID_PARAMETER == ret) {
@@ -832,23 +835,42 @@ PlatformResult ContentManager::cancelScanDirectory(const std::string& content_di
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult ContentManager::setChangeListener(media_content_db_update_cb callback, void *user_data) {
+PlatformResult ContentManager::setChangeListener(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(callback, user_data);
   if(ret != MEDIA_CONTENT_ERROR_NONE) {
     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() {
+PlatformResult ContentManager::unSetChangeListener(media_content_noti_h* noti_handle) {
   LoggerD("Enter");
+
   int ret = media_content_unset_db_updated_cb();
   if(ret != MEDIA_CONTENT_ERROR_NONE) {
     LoggerE("Failed: unregistering the listener is failed");
     return PlatformResult(ErrorCode::UNKNOWN_ERR, ("unregistering the listener is failed."));
   }
+
+  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."));
+  }
+  *noti_handle = nullptr;
+
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
index 95290b6..f2d4f04 100755 (executable)
@@ -52,8 +52,10 @@ 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_db_update_cb callback, void *user_data);
-  common::PlatformResult unSetChangeListener();
+  common::PlatformResult setChangeListener(media_content_noti_h* noti_handler,
+                                           media_content_db_update_cb callback,
+                                           void *user_data);
+  common::PlatformResult unSetChangeListener(media_content_noti_h* noti_handler);
 
 //Lyrics
   int getLyrics(const picojson::value& args,picojson::object& result);