From 51fbc9e1c98647f5a1ae5bd56d9506bda42fde0f Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Thu, 7 Jul 2016 09:49:32 +0200 Subject: [PATCH] [Filesystem][Systeminfo] Changed storage handling [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 --- src/common/filesystem/filesystem_provider.cc | 5 ---- src/common/filesystem/filesystem_provider.h | 2 -- .../filesystem/filesystem_provider_deviced.cc | 14 ++++++----- .../filesystem/filesystem_provider_deviced.h | 1 - .../filesystem/filesystem_provider_storage.cc | 28 ++++----------------- .../filesystem/filesystem_provider_storage.h | 2 -- src/systeminfo/systeminfo_properties_manager.cc | 29 ++++++++-------------- 7 files changed, 23 insertions(+), 58 deletions(-) diff --git a/src/common/filesystem/filesystem_provider.cc b/src/common/filesystem/filesystem_provider.cc index 7cb6c1a..ff6c26e 100644 --- a/src/common/filesystem/filesystem_provider.cc +++ b/src/common/filesystem/filesystem_provider.cc @@ -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"); diff --git a/src/common/filesystem/filesystem_provider.h b/src/common/filesystem/filesystem_provider.h index 69030d5..1b3dd92 100644 --- a/src/common/filesystem/filesystem_provider.h +++ b/src/common/filesystem/filesystem_provider.h @@ -36,7 +36,6 @@ class IFilesystemProvider { virtual Storages GetStorages() = 0; virtual VirtualRoots GetVirtualPaths() = 0; virtual VirtualStorages GetAllStorages() = 0; - virtual std::shared_ptr GetInternalStorage() = 0; }; typedef IFilesystemProvider& FilesystemProviderRef; @@ -52,7 +51,6 @@ class FilesystemProvider { Storages GetStorages(); VirtualRoots GetVirtualPaths(); VirtualStorages GetAllStorages(); - std::shared_ptr GetInternalStorage(); std::string GetRealPath(const std::string& path_or_uri); std::string GetVirtualPath(const std::string& real_path) const; diff --git a/src/common/filesystem/filesystem_provider_deviced.cc b/src/common/filesystem/filesystem_provider_deviced.cc index cf6a7ad..81bb570 100644 --- a/src/common/filesystem/filesystem_provider_deviced.cc +++ b/src/common/filesystem/filesystem_provider_deviced.cc @@ -195,10 +195,6 @@ void FilesystemProviderDeviced::UnregisterDeviceChangeState() { device_changed_callback_ = nullptr; } -std::shared_ptr FilesystemProviderDeviced::GetInternalStorage() { - return virtual_roots_provider_.GetInternalStorage(); -} - std::shared_ptr FilesystemProviderDeviced::GetStorage(const DeviceListElem& elem) { LoggerD("Entered"); return std::make_shared(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) { diff --git a/src/common/filesystem/filesystem_provider_deviced.h b/src/common/filesystem/filesystem_provider_deviced.h index bae0ea5..388e6c5 100644 --- a/src/common/filesystem/filesystem_provider_deviced.h +++ b/src/common/filesystem/filesystem_provider_deviced.h @@ -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: diff --git a/src/common/filesystem/filesystem_provider_storage.cc b/src/common/filesystem/filesystem_provider_storage.cc index d58d644..a26cc3f 100644 --- a/src/common/filesystem/filesystem_provider_storage.cc +++ b/src/common/filesystem/filesystem_provider_storage.cc @@ -90,22 +90,10 @@ bool OnForeachStorage(int storage_id, storage_type_e type, FilesystemProviderStorage* provider = static_cast(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_id, type_, TranslateCoreStorageState(state), path)); - if (type_ == StorageType::kInternal) { - // TODO check internal storage - //provider->internal_storage_ = std::make_shared(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_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"); diff --git a/src/common/filesystem/filesystem_provider_storage.h b/src/common/filesystem/filesystem_provider_storage.h index 133f801..2198200 100644 --- a/src/common/filesystem/filesystem_provider_storage.h +++ b/src/common/filesystem/filesystem_provider_storage.h @@ -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 internal_storage_; }; } // namespace common diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc index 94b4fa5..33b639d 100644 --- a/src/systeminfo/systeminfo_properties_manager.cc +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -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(); - // handling internal storage - array.push_back(picojson::value(picojson::object())); - picojson::object& internal_obj = array.back().get(); - - 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(); 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); + } } } -- 2.7.4