[Filesystem][Systeminfo] Changed storage handling 70/78870/1
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 7 Jul 2016 07:49:32 +0000 (09:49 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 7 Jul 2016 07:54:56 +0000 (09:54 +0200)
[Feature] Deviced is used for handling only removable devices,
  internal storages are handled with storage api.

[Verification] Code compiles without error.
  TCT for filesystem, systeminfo and archive 100% passrate (Auto and Manual)

Change-Id: If5609ff4f22383efd018a445f6a56760983b9818
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/common/filesystem/filesystem_provider.cc
src/common/filesystem/filesystem_provider.h
src/common/filesystem/filesystem_provider_deviced.cc
src/common/filesystem/filesystem_provider_deviced.h
src/common/filesystem/filesystem_provider_storage.cc
src/common/filesystem/filesystem_provider_storage.h
src/systeminfo/systeminfo_properties_manager.cc

index 7cb6c1a27ce456f644c96e619a1f5f04c510ff62..ff6c26ef06ddabd4093aaa1a24bae0fa01b3e528 100644 (file)
@@ -71,11 +71,6 @@ VirtualStorages FilesystemProvider::GetAllStorages() {
   return provider_.GetAllStorages();
 }
 
-std::shared_ptr< Storage > FilesystemProvider::GetInternalStorage(){
-  LoggerD("Entered");
-  return provider_.GetInternalStorage();
-}
-
 std::string FilesystemProvider::GetRealPath(
     const std::string& path_or_uri) {
   LoggerD("Entered");
index 69030d513c79f4dd6ed4ab518063384384c41a6c..1b3dd921f2d5a94b5c677ec8a13a06d90fd4a985 100644 (file)
@@ -36,7 +36,6 @@ class IFilesystemProvider {
   virtual Storages GetStorages() = 0;
   virtual VirtualRoots GetVirtualPaths() = 0;
   virtual VirtualStorages GetAllStorages() = 0;
-  virtual std::shared_ptr<Storage> GetInternalStorage() = 0;
 };
 
 typedef IFilesystemProvider& FilesystemProviderRef;
@@ -52,7 +51,6 @@ class FilesystemProvider {
   Storages GetStorages();
   VirtualRoots GetVirtualPaths();
   VirtualStorages GetAllStorages();
-  std::shared_ptr<Storage> GetInternalStorage();
 
   std::string GetRealPath(const std::string& path_or_uri);
   std::string GetVirtualPath(const std::string& real_path) const;
index cf6a7ad5b5a5b3ab332569b7dcc8d43879819f13..81bb5705dc1b299535a6b7ee2f0be0fff204c88a 100644 (file)
@@ -195,10 +195,6 @@ void FilesystemProviderDeviced::UnregisterDeviceChangeState() {
   device_changed_callback_ = nullptr;
 }
 
-std::shared_ptr<Storage> FilesystemProviderDeviced::GetInternalStorage() {
-  return virtual_roots_provider_.GetInternalStorage();
-}
-
 std::shared_ptr<Storage> FilesystemProviderDeviced::GetStorage(const DeviceListElem& elem) {
   LoggerD("Entered");
   return std::make_shared<Storage>(GetIdFromUUID(elem.fs_uuid_enc),
@@ -230,7 +226,6 @@ int FilesystemProviderDeviced::GetIdFromUUID(const char* const char_uuid) {
 
 Storages FilesystemProviderDeviced::GetStorages() {
   LoggerD("Entered");
-
   if(!is_initialized_) {
     LoggerE("DeviceD Core api not initialized");
     return Storages();
@@ -253,7 +248,14 @@ Storages FilesystemProviderDeviced::GetStorages() {
     LoggerE("Failed to call GetDeviceList method - %s", message.c_str());
     return Storages();
   }
-  return GetStoragesFromGVariant(variant);
+  // internal storages are gathered with storage api
+  Storages internal = virtual_roots_provider_.GetStorages();
+  // external storages are gathered using deviced implementation
+  Storages result = GetStoragesFromGVariant(variant);
+
+  // merging internal and external results together, but internal on the beginning
+  result.insert(result.begin(), internal.begin(), internal.end());
+  return result;
 }
 
 Storages FilesystemProviderDeviced::GetStoragesFromGVariant(GVariant* variant) {
index bae0ea5b6ba2704e011e489a93065463475e319b..388e6c5c1985a23d71d0e7555cc99aa538c6da17 100644 (file)
@@ -44,7 +44,6 @@ class FilesystemProviderDeviced : public IFilesystemProvider {
   virtual VirtualRoots GetVirtualPaths();
   virtual Storages GetStorages();
   virtual VirtualStorages GetAllStorages();
-  virtual std::shared_ptr< Storage > GetInternalStorage();
   static FilesystemProviderDeviced& Create();
 
  private:
index d58d64471000cbf85c518e8c4bd40b22664dd496..a26cc3f2adea70b00e55b33b3e50e572137b2930 100644 (file)
@@ -90,22 +90,10 @@ bool OnForeachStorage(int storage_id, storage_type_e type,
   FilesystemProviderStorage* provider =
       static_cast<FilesystemProviderStorage*>(user_data);
 
-  int err = storage_set_state_changed_cb(storage_id, OnStorageChange, provider);
-  if (STORAGE_ERROR_NONE != err) {
-    LoggerW("Failed to add listener");
-  }
-
-  StorageType type_ =
-      type == STORAGE_TYPE_INTERNAL ?
-          StorageType::kInternal : StorageType::kMmc;
-
-  provider->AddStorage(
-      std::make_shared<Storage>(storage_id, type_, TranslateCoreStorageState(state), path));
-  if (type_ == StorageType::kInternal) {
-    // TODO check internal storage
-    //provider->internal_storage_ = std::make_shared<Storage>(Storage(storage_id, type_, state_, path, kVirtualRootMedia));
-    // if internal storage is supported, we can add also virtual paths:
-    // downloads, documents etc
+  // handling only internal storages (external are handled with deviced api)
+  if (STORAGE_TYPE_INTERNAL == type) {
+    provider->AddStorage(
+        std::make_shared<Storage>(storage_id, StorageType::kInternal, TranslateCoreStorageState(state), path));
     provider->FillVirtualPaths(storage_id);
   }
   return true;
@@ -119,8 +107,7 @@ DeviceChangeStateFun FilesystemProviderStorage::GetListener() {
   return listener_;
 }
 
-FilesystemProviderStorage::FilesystemProviderStorage() :
-    internal_storage_(nullptr) {
+FilesystemProviderStorage::FilesystemProviderStorage() {
   LoggerD("Entered");
   int err = storage_foreach_device_supported(OnForeachStorage, this);
   if (err != STORAGE_ERROR_NONE) {
@@ -209,11 +196,6 @@ std::string FilesystemProviderStorage::GetRealPath(
   return realpath;
 }
 
-std::shared_ptr< Storage > FilesystemProviderStorage::GetInternalStorage(){
-  LoggerD("Entered");
-  return internal_storage_;
-}
-
 std::string FilesystemProviderStorage::GetVirtualPath(
     const std::string& real_path) const {
   LoggerD("Enter");
index 133f8010ee1de57678c04c43d175fc3c7b9911b9..2198200c340b821985d30c9dd7eb1e2b727faee8 100644 (file)
@@ -35,7 +35,6 @@ class FilesystemProviderStorage : public IFilesystemProvider {
   virtual Storages GetStorages();
   virtual VirtualRoots GetVirtualPaths();
   virtual VirtualStorages GetAllStorages();
-  virtual std::shared_ptr< Storage > GetInternalStorage();
 
   std::string GetRealPath(const std::string& path_or_uri);
   std::string GetVirtualPath(const std::string& real_path) const;
@@ -54,7 +53,6 @@ class FilesystemProviderStorage : public IFilesystemProvider {
   DeviceChangeStateFun listener_;
   Storages storages_;
   VirtualRoots virtual_paths_;
-  std::shared_ptr<Storage> internal_storage_;
 };
 
 }  // namespace common
index 94b4fa5e843260ec67c2843111b335b41b68abae..33b639dcd21bcfcee644ab15dc7d516f58ac9684 100644 (file)
@@ -1167,6 +1167,8 @@ static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojs
 
 static std::string FromStorageTypeToStringType(common::StorageType type) {
   switch(type) {
+    case common::StorageType::kInternal:
+      return kTypeInternal;
     case common::StorageType::kUsbDevice:
       return kTypeUsbDevice;
     case common::StorageType::kUsbHost:
@@ -1185,18 +1187,7 @@ PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out)
   picojson::value result = picojson::value(picojson::array());
   picojson::array& array = result.get<picojson::array>();
 
-  // handling internal storage
-  array.push_back(picojson::value(picojson::object()));
-  picojson::object& internal_obj = array.back().get<picojson::object>();
-
-  if (statfs(kStorageInternalPath.c_str(), &fs) < 0) {
-    return LogAndCreateResult(
-              ErrorCode::UNKNOWN_ERR, "There are no storage units detected");
-  }
-  CreateStorageInfo(kTypeInternal, fs, &internal_obj);
-  manager_.SetAvailableCapacityInternal(fs.f_bavail);
-
-  // handling external storages
+  // handling storages from provider
   common::FilesystemProvider& provider(common::FilesystemProvider::Create());
   auto storages = provider.GetStorages();
   LoggerD("Storages found %d", storages.size());
@@ -1209,13 +1200,13 @@ PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out)
       array.push_back(picojson::value(picojson::object()));
       picojson::object& external_obj = array.back().get<picojson::object>();
       CreateStorageInfo(FromStorageTypeToStringType(storage->type()), fs, &external_obj);
-#ifdef TIZEN_TV
-      // TODO some tracking of available capacity of usb storages should be applied
-#else
-      // Only one storage would be tracked, if more than one SD card would be supported on device
-      // different mechanism should be applied
-      manager_.SetAvailableCapacityMmc(fs.f_bavail);
-#endif
+
+      //TODO change implementation to support all types of storages and not limited number
+      if (common::StorageType::kInternal == storage->type()) {
+        manager_.SetAvailableCapacityInternal(fs.f_bavail);
+      } else if (common::StorageType::kMmc == storage->type()) {
+        manager_.SetAvailableCapacityMmc(fs.f_bavail);
+      }
     }
   }