[Filesystem] Fix addStorageStateChangeListener method
authorPiotr Czaja <p.czaja@samsung.com>
Wed, 20 May 2015 09:25:52 +0000 (11:25 +0200)
committerHyunjin Park <hj.na.park@samsung.com>
Wed, 3 Jun 2015 02:36:25 +0000 (11:36 +0900)
[Verification] Following TCT are fixed:
- FileSystemManager_addStorageStateChangeListener
- FileSystemManager_addStorageStateChangeListener_with_onerror
- FileSystemManager_removeStorageStateChangeListener

Change-Id: I799686ee07c0481cb2d93f12fc90de67aa104494
Signed-off-by: Piotr Czaja <p.czaja@samsung.com>
src/filesystem/filesystem_instance.cc
src/filesystem/filesystem_manager.cc
src/filesystem/filesystem_manager.h

index d2154598f46fe0745530a45bd20168bf4e20d73a..5e4d10b9b3ea414f7e8f2963db195a806187c358 100755 (executable)
@@ -75,6 +75,8 @@ FilesystemInstance::FilesystemInstance() {
 
 FilesystemInstance::~FilesystemInstance() {
   LoggerD("enter");
+  FilesystemManager::GetInstance().StopListening();
+  FilesystemManager::GetInstance().RemoveListener();
 }
 
 #define CHECK_EXIST(args, name, out)                                       \
index a9cdf9cc391ff3a56a94b0cbe490e24b58073c06..17fb2252e6b76b2f2606568ff899d8b9656da4bb 100755 (executable)
@@ -204,17 +204,23 @@ FilesystemError make_directory_worker(const std::string& path) {
 }
 }  // namespace
 
+std::vector<common::VirtualStorage> FilesystemManager::FillStorages() {
+    LoggerD("entered");
+    auto virtualStorages = common::VirtualFs::GetInstance().GetStorages();
+    if (ids_.empty()) {
+        for (auto storage : virtualStorages) {
+          if (storage.id_ >= 0) {
+            ids_.insert(storage.id_);
+          }
+        }
+    }
+    return virtualStorages;
+}
+
 void FilesystemManager::FetchStorages(
     const std::function<void(const std::vector<common::VirtualStorage>&)>& success_cb,
     const std::function<void(FilesystemError)>& error_cb) {
-  auto result = common::VirtualFs::GetInstance().GetStorages();
-
-  for (auto storage : result) {
-    if (storage.id_ >= 0) {
-      ids_.insert(storage.id_);
-    }
-  }
-
+  auto result = FillStorages();
   success_cb(result);
 }
 
@@ -420,6 +426,7 @@ void FilesystemManager::FileWrite(
 
 void FilesystemManager::StartListening() {
   LoggerD("enter");
+  FillStorages();
 
   if (!is_listener_registered_ && !ids_.empty()) {
     int result = STORAGE_ERROR_NONE;
@@ -475,5 +482,10 @@ void FilesystemManager::AddListener(FilesystemStateChangeListener* listener) {
   LoggerD("enter");
   listener_ = listener;
 }
+
+void FilesystemManager::RemoveListener() {
+  LoggerD("enter");
+  listener_ = NULL;
+}
 }  // namespace filesystem
 }  // namespace extension
index 474d7407508b2a5ef047bcf2bd6fcd9e7fd44c0e..0492d345f864dacd8b01bac7a853f5efb15c024e 100755 (executable)
@@ -59,6 +59,7 @@ class FilesystemManager {
                 const std::function<void(const FilesystemStat&)>& success_cb,
                 const std::function<void(FilesystemError)>& error_cb);
 
+  std::vector<common::VirtualStorage> FillStorages();
   void FetchStorages(
       const std::function<void(const std::vector<common::VirtualStorage>&)>& success_cb,
       const std::function<void(FilesystemError)>& error_cb);
@@ -110,6 +111,7 @@ void CopyTo(const std::string& originFilePath,
   void StartListening();
   void StopListening();
   void AddListener(FilesystemStateChangeListener* listener);
+  void RemoveListener();
 };
 }  // namespace filesystem
 }  // namespace extension