From: Piotr Kosko Date: Mon, 4 Jan 2016 13:24:36 +0000 (+0100) Subject: [Common] Added FilesystemProvider interface for different profiles X-Git-Tag: submit/tizen/20160113.110151^2~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8bfafc9f00a7e4b44ceba5cf1198cff41287f4e9;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Added FilesystemProvider interface for different profiles Change-Id: Iccb3d1985be54f9c8f2bd6ea1c4a2ebaac1a3ba9 Signed-off-by: Piotr Kosko --- diff --git a/src/archive/archive_instance.cc b/src/archive/archive_instance.cc index 30ec005e..97f3f395 100755 --- a/src/archive/archive_instance.cc +++ b/src/archive/archive_instance.cc @@ -24,7 +24,7 @@ #include "common/current_application.h" #include "common/picojson.h" #include "common/logger.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" #include "common/tools.h" #include "archive_callback_data.h" #include "archive_manager.h" @@ -620,7 +620,7 @@ void ArchiveInstance::FetchVirtualRoots(const picojson::value& args, picojson::o LoggerD("Entered"); picojson::array roots; - for (const auto& root : common::FilesystemProviderStorage::Create().GetVirtualPaths() ) { + for (const auto& root : common::FilesystemProvider::Create().GetVirtualPaths() ) { roots.push_back(root.ToJson()); } ReportSuccess(picojson::value(roots), out); diff --git a/src/common/common.gyp b/src/common/common.gyp index bba10751..e93b7cbd 100644 --- a/src/common/common.gyp +++ b/src/common/common.gyp @@ -49,6 +49,8 @@ 'filesystem/filesystem_storage_types.h', 'filesystem/filesystem_storage.h', 'filesystem/filesystem_storage.cc', + 'filesystem/filesystem_provider.h', + 'filesystem/filesystem_provider.cc', 'filesystem/filesystem_provider_storage.h', 'filesystem/filesystem_provider_storage.cc', ], @@ -56,6 +58,12 @@ '-fvisibility=default', ], 'conditions': [ + ['extension_host_os == "tv"', { + 'sources': [ + 'filesystem/filesystem_provider_deviced.h', + 'filesystem/filesystem_provider_deviced.cc', + ] + }], ['tizen == 1', { 'variables': { 'packages': [ diff --git a/src/common/filesystem/filesystem_provider.cc b/src/common/filesystem/filesystem_provider.cc new file mode 100644 index 00000000..f2a69e7e --- /dev/null +++ b/src/common/filesystem/filesystem_provider.cc @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common/filesystem/filesystem_provider.h" +#ifdef TIZEN_TV +#include "common/filesystem/filesystem_provider_deviced.h" +#endif +#include "common/filesystem/filesystem_provider_storage.h" + +namespace common { + +IFilesystemProvider::IFilesystemProvider() { + LoggerD("enter"); + +} + +IFilesystemProvider::~IFilesystemProvider() { + LoggerD("enter"); +} + + +FilesystemProvider::FilesystemProvider() : +#ifdef TIZEN_TV + provider_ (FilesystemProviderDeviced::Create()) +#else + provider_ (FilesystemProviderStorage::Create()) +#endif +{ +} + +FilesystemProvider& FilesystemProvider::Create() { + LoggerD("Entered"); + static FilesystemProvider instance; + return instance; +} + +FilesystemProvider::~FilesystemProvider() { + LoggerD("Entered"); +} + +void FilesystemProvider::RegisterDeviceChangeState( + DeviceChangeStateFun callback) { + LoggerD("Entered"); + provider_.RegisterDeviceChangeState(callback); +} + +void FilesystemProvider::UnregisterDeviceChangeState() { + LoggerD("Entered"); + provider_.UnregisterDeviceChangeState(); +} + +Storages FilesystemProvider::GetStorages() { + LoggerD("Entered"); + return provider_.GetStorages(); +} + +VirtualRoots FilesystemProvider::GetVirtualPaths() { + LoggerD("Entered"); + return provider_.GetVirtualPaths(); +} + +VirtualStorages FilesystemProvider::GetAllStorages() { + LoggerD("Entered"); + 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"); + return FilesystemProviderStorage::Create().GetRealPath(path_or_uri); +} + +std::string FilesystemProvider::GetVirtualPath( + const std::string& real_path) const { + LoggerD("Entered"); + return FilesystemProviderStorage::Create().GetVirtualPath(real_path); +} + +} // namespace common diff --git a/src/common/filesystem/filesystem_provider.h b/src/common/filesystem/filesystem_provider.h new file mode 100644 index 00000000..69030d51 --- /dev/null +++ b/src/common/filesystem/filesystem_provider.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMMON_FILESYSTEM_FILESYSTEM_PROVIDER_H_ +#define COMMON_FILESYSTEM_FILESYSTEM_PROVIDER_H_ + +#include +#include +#include +#include "common/filesystem/filesystem_storage.h" +#include "common/filesystem/filesystem_provider_types.h" + +namespace common { + +class IFilesystemProvider { + public: + IFilesystemProvider(); + virtual ~IFilesystemProvider(); + + virtual void RegisterDeviceChangeState(DeviceChangeStateFun _callback) = 0; + virtual void UnregisterDeviceChangeState() = 0; + + virtual Storages GetStorages() = 0; + virtual VirtualRoots GetVirtualPaths() = 0; + virtual VirtualStorages GetAllStorages() = 0; + virtual std::shared_ptr GetInternalStorage() = 0; +}; + +typedef IFilesystemProvider& FilesystemProviderRef; + +class FilesystemProvider { + public: + static FilesystemProvider& Create(); + virtual ~FilesystemProvider(); + + void RegisterDeviceChangeState(DeviceChangeStateFun _callback); + void UnregisterDeviceChangeState(); + + 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; + private: + FilesystemProvider(); + FilesystemProvider(const FilesystemProvider&) = delete; + FilesystemProvider& operator=(const FilesystemProvider&) = delete; + FilesystemProvider(FilesystemProvider&&) = delete; + FilesystemProvider& operator=(FilesystemProvider&&) = delete; + FilesystemProviderRef provider_; +}; + +} // namespace common + +#endif // COMMON_FILESYSTEM_FILESYSTEM_PROVIDER_H_ diff --git a/src/common/filesystem/filesystem_provider_deviced.cc b/src/common/filesystem/filesystem_provider_deviced.cc new file mode 100644 index 00000000..ac08abc1 --- /dev/null +++ b/src/common/filesystem/filesystem_provider_deviced.cc @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common/filesystem/filesystem_provider_deviced.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "common/filesystem/filesystem_storage.h" +#include "common/logger.h" + +namespace { +static const char* kIface = "org.tizen.system.deviced.BlockManager"; +static const char* kPath = "/Org/Tizen/System/DeviceD/Block/Manager"; +} // namespace + +namespace common { + +struct DeviceListElem { + DeviceListElem() + : block_type(0), + devnode(nullptr), + syspath(nullptr), + fs_usage(nullptr), + fs_type(nullptr), + fs_version(nullptr), + fs_uuid_enc(nullptr), + readonly(0), + mount_point(nullptr), + state(0), + primary(false) {} + + int block_type; + char* devnode; + char* syspath; + char* fs_usage; + char* fs_type; + char* fs_version; + char* fs_uuid_enc; + int readonly; + char* mount_point; + int state; + bool primary; +}; + +FilesystemProviderDeviced::~FilesystemProviderDeviced() { + LoggerD("Entered"); + UnregisterDeviceChangeState(); +} + +FilesystemProviderDeviced::FilesystemProviderDeviced() : + dbus_(nullptr), + proxy_(nullptr), + device_changed_callback_(nullptr), + block_signal_subscribe_id_(0), + virtual_roots_provider_(FilesystemProviderStorage::Create()), + is_initialized_(false) { + LoggerD("Entered"); + + GError* error = nullptr; + + dbus_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error); + if (error != NULL) { + LoggerE("Could not get dbus connection: %s", error->message); + } else { + if (!dbus_) { + LoggerE("Dbus handle is null"); + } else { + LoggerE("Dbus connection set"); + const gchar* unique_name = g_dbus_connection_get_unique_name(dbus_); + proxy_ = g_dbus_proxy_new_sync(dbus_, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + nullptr, unique_name, kPath, kIface, nullptr, + &error); + if (!proxy_ || error) { + LoggerE("Could not get dbus proxy. %s", error->message); + } else { + is_initialized_ = true; + } + } + } +} + +FilesystemProviderDeviced& FilesystemProviderDeviced::Create() { + LoggerD("Entered"); + + static FilesystemProviderDeviced instance; + + return instance; +} + +void FilesystemProviderDeviced::BlockSignalProxy( + GDBusConnection* connection, const gchar* sender_name, + const gchar* object_path, const gchar* interface_name, + const gchar* signal_name, GVariant* parameters, gpointer user_data) { + LoggerD("Entered"); + + FilesystemProviderDeviced* instance = + static_cast(user_data); + DeviceListElem elem; + g_variant_get(parameters, "(issssssisib)", &elem.block_type, &elem.devnode, + &elem.syspath, &elem.fs_usage, &elem.fs_type, &elem.fs_version, + &elem.fs_uuid_enc, &elem.readonly, &elem.mount_point, + &elem.state, &elem.primary); + instance->BlockSignalCallback(elem); +} + +void FilesystemProviderDeviced::BlockSignalCallback(DeviceListElem elem) { + LoggerD("Entered"); + StorageState previous_state = StorageState::kUnmounted; + auto it = previous_device_state_map_.find(elem.syspath); + if (it == previous_device_state_map_.end()) { + previous_device_state_map_[elem.syspath] = previous_state = + (elem.state ? StorageState::kMounted : StorageState::kUnmounted); + } else { + previous_state = it->second; + } + if (device_changed_callback_ != nullptr) { + std::shared_ptr storage = GetStorage(elem); + device_changed_callback_(*storage, previous_state, storage->state_); + } +} + +void FilesystemProviderDeviced::RegisterDeviceChangeState( + DeviceChangeStateFun _callback) { + LoggerD("Entered"); + + if(!is_initialized_) { + LoggerE("DeviceD Core api not initialized"); + return; + } + + if (device_changed_callback_ == nullptr) { + LoggerD("Registering dbus signal subscription"); + block_signal_subscribe_id_ = g_dbus_connection_signal_subscribe( + dbus_, nullptr, "org.tizen.system.deviced.Block", "DeviceChanged", + nullptr, nullptr, G_DBUS_SIGNAL_FLAGS_NONE, BlockSignalProxy, this, + nullptr); + } + device_changed_callback_ = _callback; +} + +void FilesystemProviderDeviced::UnregisterDeviceChangeState() { + LoggerD("Entered"); + + if(!is_initialized_) { + LoggerE("DeviceD Core api not initialized"); + return; + } + + if (0 != block_signal_subscribe_id_) { + LoggerD("Dbus signal handling unsubscription"); + g_dbus_connection_signal_unsubscribe (dbus_, block_signal_subscribe_id_); + } + 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(Storage(GetIdFromUUID(elem.fs_uuid_enc), StorageType::kExternal, + (elem.state ? StorageState::kMounted : StorageState::kUnmounted), + elem.syspath, GetNameFromPath(elem.devnode))); +} + +std::string FilesystemProviderDeviced::GetNameFromPath( + const char* const char_path) { + LoggerD("Entered"); + std::string path = char_path; + std::string name = "removable_"; + std::size_t last_slash_pos = path.find_last_of("/"); + if (last_slash_pos + 1 >= path.size()) { + name += path; + LoggerW("Failed to get device name from device syspath"); + } else { + name += path.substr(last_slash_pos + 1); + } + return name; +} + +int FilesystemProviderDeviced::GetIdFromUUID(const char* const char_uuid) { + LoggerD("Entered"); + std::string uuid = char_uuid; + size_t hyphen = uuid.find("-"); + std::string clear_uuid = uuid.substr(0, hyphen) + uuid.substr(hyphen + 1); + return static_cast(std::stoul(clear_uuid, 0, 16)); +} + +Storages FilesystemProviderDeviced::GetStorages() { + LoggerD("Entered"); + + if(!is_initialized_) { + LoggerE("DeviceD Core api not initialized"); + return Storages(); + } + + GError* error = nullptr; + GVariant* variant = g_dbus_proxy_call_sync( + proxy_, "GetDeviceList", g_variant_new("(s)", "all"), + G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error); + if (!variant || error) { + LoggerE("Failed to call GetDeviceList method - %s", error->message); + return Storages(); + } + LoggerD("GetDeviceList called"); + return GetStoragesFromGVariant(variant); +} + +Storages FilesystemProviderDeviced::GetStoragesFromGVariant(GVariant* variant) { + LoggerD("Entered"); + Storages storages; + GVariantIter iter; + GVariant* tuple = nullptr; + g_variant_iter_init(&iter, variant); + while ((tuple = g_variant_iter_next_value(&iter))) { + DeviceListElem elem; + g_variant_get(tuple, "(issssssisib)", &elem.block_type, &elem.devnode, + &elem.syspath, &elem.fs_usage, &elem.fs_type, + &elem.fs_version, &elem.fs_uuid_enc, &elem.readonly, + &elem.mount_point, &elem.state, &elem.primary); + storages.push_back(GetStorage(elem)); + g_variant_unref(tuple); + } + return storages; +} + +VirtualRoots FilesystemProviderDeviced::GetVirtualPaths() { + LoggerD("Entered"); + + if(!is_initialized_) { + LoggerE("DeviceD Core api not initialized"); + return VirtualRoots(); + } + + return virtual_roots_provider_.GetVirtualPaths(); +} + +VirtualStorages FilesystemProviderDeviced::GetAllStorages() { + LoggerD("Entered"); + + if(!is_initialized_) { + LoggerE("DeviceD Core api not initialized"); + return VirtualStorages(); + } + + std::lock_guard lock(mutex_); + VirtualStorages vs; + for (auto storage : GetStorages()) { + vs.push_back(storage); + } + + for (auto virtual_root : virtual_roots_provider_.GetVirtualPaths()) { + vs.push_back(std::make_shared(virtual_root)); + } + + return vs; +} + +} // namespace common diff --git a/src/common/filesystem/filesystem_provider_deviced.h b/src/common/filesystem/filesystem_provider_deviced.h new file mode 100644 index 00000000..c3094454 --- /dev/null +++ b/src/common/filesystem/filesystem_provider_deviced.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMMON_FILESYSTEM_PROVIDER_DEVICED_H +#define COMMON_FILESYSTEM_PROVIDER_DEVICED_H + +#include + +#include +#include +#include +#include +#include +#include + +#include "common/filesystem/filesystem_storage.h" +#include "common/filesystem/filesystem_provider.h" +#include "common/filesystem/filesystem_provider_storage.h" + +namespace common { + +struct DeviceListElem; + +class FilesystemProviderDeviced : public IFilesystemProvider { + public: + + virtual ~FilesystemProviderDeviced(); + virtual void RegisterDeviceChangeState(DeviceChangeStateFun _callback); + virtual void UnregisterDeviceChangeState(); + virtual VirtualRoots GetVirtualPaths(); + virtual Storages GetStorages(); + virtual VirtualStorages GetAllStorages(); + virtual std::shared_ptr< Storage > GetInternalStorage(); + static FilesystemProviderDeviced& Create(); + + private: + FilesystemProviderDeviced(); + + static void BlockSignalProxy(GDBusConnection* connection, + const gchar* sender_name, const gchar* object_path, + const gchar* interface_name, + const gchar* signal_name, GVariant* parameters, + gpointer user_data); + void BlockSignalCallback(DeviceListElem elem); + + static std::string GetNameFromPath(const char* const char_path); + static int GetIdFromUUID(const char* const char_uuid); + static std::shared_ptr GetStorage(const DeviceListElem& elem); + static Storages GetStoragesFromGVariant(GVariant* variant); + GDBusConnection* dbus_; + GDBusProxy* proxy_; + + DeviceChangeStateFun device_changed_callback_; + guint block_signal_subscribe_id_; + std::map previous_device_state_map_; + FilesystemProviderRef virtual_roots_provider_; + std::mutex mutex_; + + bool is_initialized_; +}; + +} // namespace common + +#endif /* DEVICED_H */ diff --git a/src/common/filesystem/filesystem_provider_storage.cc b/src/common/filesystem/filesystem_provider_storage.cc index 74108863..4db8a28d 100644 --- a/src/common/filesystem/filesystem_provider_storage.cc +++ b/src/common/filesystem/filesystem_provider_storage.cc @@ -33,6 +33,7 @@ const std::string kVirtualRootVideos = "videos"; const std::string kVirtualRootWgtPackage = "wgt-package"; const std::string kVirtualRootWgtPrivate = "wgt-private"; const std::string kVirtualRootWgtPrivateTmp = "wgt-private-tmp"; +const std::string kVirtualRootMedia = "internal0"; const std::map kStorageDirectories = { { STORAGE_DIRECTORY_CAMERA, &kVirtualRootCamera }, { @@ -51,6 +52,7 @@ namespace common { StorageState TranslateCoreStorageState( storage_state_e coreStorageState) { + LoggerD("Entered"); StorageState state = StorageState::kUnknown; if (coreStorageState == STORAGE_STATE_REMOVED) { state = StorageState::kUnmounted; @@ -70,11 +72,11 @@ void OnStorageChange(int storage_id, storage_state_e state, void* user_data) { FilesystemProviderStorage* provider = static_cast(user_data); for (auto &storage : provider->GetStorages()) { - if (storage.id_ == storage_id) { - StorageState previous_state = storage.state_; - storage.state_ = TranslateCoreStorageState(state); + if (storage->id_ == storage_id) { + StorageState previous_state = storage->state_; + storage->state_ = TranslateCoreStorageState(state); if (provider->GetListener()) { - provider->GetListener()(storage, previous_state, storage.state_); + provider->GetListener()(*storage, previous_state, storage->state_); } break; } @@ -98,8 +100,10 @@ bool OnForeachStorage(int storage_id, storage_type_e type, StorageType::kInternal : StorageType::kExternal; provider->GetStorages().push_back( - Storage(storage_id, type_, TranslateCoreStorageState(state), path)); + 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 provider->FillVirtualPaths(storage_id); @@ -111,7 +115,8 @@ DeviceChangeStateFun FilesystemProviderStorage::GetListener() { return listener_; } -FilesystemProviderStorage::FilesystemProviderStorage() { +FilesystemProviderStorage::FilesystemProviderStorage() : + internal_storage_(nullptr) { LoggerD("Entered"); int err = storage_foreach_device_supported(OnForeachStorage, this); if (err != STORAGE_ERROR_NONE) { @@ -120,11 +125,13 @@ FilesystemProviderStorage::FilesystemProviderStorage() { } FilesystemProviderStorage& FilesystemProviderStorage::Create() { + LoggerD("Entered"); static FilesystemProviderStorage fs; return fs; } FilesystemProviderStorage::~FilesystemProviderStorage() { + LoggerD("Entered"); } void FilesystemProviderStorage::FillVirtualPaths(int storage_id) { @@ -163,10 +170,12 @@ void FilesystemProviderStorage::UnregisterDeviceChangeState() { } Storages FilesystemProviderStorage::GetStorages() { + LoggerD("Entered"); return storages_; } VirtualRoots FilesystemProviderStorage::GetVirtualPaths() { + LoggerD("Entered"); return virtual_paths_; } @@ -196,6 +205,11 @@ 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"); @@ -208,9 +222,10 @@ std::string FilesystemProviderStorage::GetVirtualPath( } VirtualStorages FilesystemProviderStorage::GetAllStorages() { + LoggerD("Entered"); VirtualStorages vs; for (auto storage : storages_) { - vs.push_back(std::make_shared < Storage > (storage)); + vs.push_back(storage); } for (auto virtualRoot : virtual_paths_) { diff --git a/src/common/filesystem/filesystem_provider_storage.h b/src/common/filesystem/filesystem_provider_storage.h index a486a5d1..fad628a8 100644 --- a/src/common/filesystem/filesystem_provider_storage.h +++ b/src/common/filesystem/filesystem_provider_storage.h @@ -20,10 +20,11 @@ #include #include #include "common/filesystem/filesystem_provider_types.h" +#include "common/filesystem/filesystem_provider.h" namespace common { -class FilesystemProviderStorage { +class FilesystemProviderStorage : public IFilesystemProvider { public: static FilesystemProviderStorage& Create(); virtual ~FilesystemProviderStorage(); @@ -34,6 +35,7 @@ class FilesystemProviderStorage { 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; @@ -51,6 +53,7 @@ class FilesystemProviderStorage { DeviceChangeStateFun listener_; Storages storages_; VirtualRoots virtual_paths_; + std::shared_ptr internal_storage_; }; } // namespace common diff --git a/src/common/filesystem/filesystem_provider_types.h b/src/common/filesystem/filesystem_provider_types.h index cb0695be..ca3c5c6d 100644 --- a/src/common/filesystem/filesystem_provider_types.h +++ b/src/common/filesystem/filesystem_provider_types.h @@ -11,10 +11,9 @@ namespace common { typedef std::function< void(common::Storage, common::StorageState, common::StorageState)> DeviceChangeStateFun; -typedef std::vector Storages; +typedef std::vector > Storages; typedef std::vector VirtualRoots; typedef std::vector > VirtualStorages; - } // namespace common -#endif // COMMON_FILESYSTEM_FILESYSTEM_PROVIDER_TYPES_H_ \ No newline at end of file +#endif // COMMON_FILESYSTEM_FILESYSTEM_PROVIDER_TYPES_H_ diff --git a/src/common/filesystem/filesystem_storage.cc b/src/common/filesystem/filesystem_storage.cc index 3d737a1d..0427c810 100644 --- a/src/common/filesystem/filesystem_storage.cc +++ b/src/common/filesystem/filesystem_storage.cc @@ -26,6 +26,7 @@ VirtualRoot::VirtualRoot(std::string const& name, std::string const& path, path_(path), type_(type), state_(state) { + LoggerD("Entered"); } Storage::Storage(int id, StorageType type, StorageState state, @@ -53,6 +54,7 @@ Storage::Storage(int id, StorageType type, StorageState state, } picojson::value VirtualRoot::ToJson() const { + LoggerD("Entered"); picojson::value v { picojson::object { } }; picojson::object& obj = v.get(); @@ -65,6 +67,7 @@ picojson::value VirtualRoot::ToJson() const { } picojson::value Storage::ToJson() const { + LoggerD("Entered"); picojson::value value = VirtualRoot::ToJson(); picojson::object& obj = value.get(); obj["storage_id"] = picojson::value(static_cast(id_)); @@ -73,10 +76,12 @@ picojson::value Storage::ToJson() const { Storage::Storage(Storage const& other) : VirtualRoot(other) { + LoggerD("Entered"); this->id_ = other.id_; } VirtualRoot::VirtualRoot(VirtualRoot const& other) { + LoggerD("Entered"); this->path_ = other.path_; this->name_ = other.name_; this->state_ = other.state_; @@ -84,6 +89,7 @@ VirtualRoot::VirtualRoot(VirtualRoot const& other) { } std::string VirtualRoot::ToString(StorageType type) { + LoggerD("Entered"); switch (type) { case StorageType::kInternal: return "INTERNAL"; @@ -98,6 +104,7 @@ std::string VirtualRoot::ToString(StorageType type) { } std::string VirtualRoot::ToString(StorageState state) { + LoggerD("Entered"); switch (state) { case StorageState::kUnmounted: return "REMOVED"; diff --git a/src/content/content_instance.cc b/src/content/content_instance.cc index 4dffe567..659c4f1c 100755 --- a/src/content/content_instance.cc +++ b/src/content/content_instance.cc @@ -29,7 +29,7 @@ #include "common/tools.h" #include "content/content_manager.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" namespace extension { namespace content { @@ -137,7 +137,7 @@ static void* WorkThread(const std::shared_ptr& user_data) { } case ContentManagerScanfileCallback: { std::string contentURI = user_data->args.get("contentURI").get(); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(contentURI); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(contentURI); ret = ContentManager::getInstance()->scanFile(real_path); if (ret != MEDIA_CONTENT_ERROR_NONE) { PlatformResult err = LogAndCreateResult( diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc index 1099b868..6aa319d1 100644 --- a/src/content/content_manager.cc +++ b/src/content/content_manager.cc @@ -29,7 +29,7 @@ #include "common/logger.h" #include "common/scope_exit.h" #include "common/tools.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" #include "content/content_filter.h" @@ -820,7 +820,7 @@ 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 real_path = common::FilesystemProviderStorage::Create().GetRealPath(contentDirURI); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(contentDirURI); const bool recursive = cbData->args.get("recursive").get(); int ret = media_content_scan_folder(real_path.c_str(), recursive, callback, (void*) cbData); @@ -1568,7 +1568,7 @@ int ContentManager::setThumbnailUri(int id, const std::string& thb_uri) media_playlist_h playlist_handle = getPlaylistHandle(id); PlaylistUniquePtr playlist_ptr(playlist_handle, destroyMediaPlaylistHandle); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(thb_uri); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(thb_uri); const int ret_code = media_playlist_set_thumbnail_path(playlist_handle, real_path.c_str()); if(MEDIA_CONTENT_ERROR_NONE != ret_code) { diff --git a/src/download/download_instance.cc b/src/download/download_instance.cc index a10618e6..964d9437 100755 --- a/src/download/download_instance.cc +++ b/src/download/download_instance.cc @@ -24,7 +24,7 @@ #include "common/picojson.h" #include "common/logger.h" #include "common/typeutil.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" namespace extension { namespace download { @@ -319,7 +319,7 @@ gboolean DownloadInstance::OnFinished(void* user_data) { out["callbackId"] = picojson::value(static_cast(callback_id)); - out["fullPath"] = picojson::value(common::FilesystemProviderStorage::Create().GetVirtualPath(fullPath)); + out["fullPath"] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(fullPath)); Instance::PostMessage(downCbPtr->instance, picojson::value(out).serialize().c_str()); downCbPtr->instance->download_callbacks.erase(callback_id); @@ -446,7 +446,7 @@ void DownloadInstance::DownloadManagerStart if (!args.get("destination").is()) { if (args.get("destination").get() != "") { diPtr->destination = args.get("destination").get(); - diPtr->destination = common::FilesystemProviderStorage::Create().GetRealPath(diPtr->destination); + diPtr->destination = common::FilesystemProvider::Create().GetRealPath(diPtr->destination); } } diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 1f5718ee..af691722 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -344,12 +344,12 @@ void FilesystemInstance::FileSystemManagerFetchStorages( picojson::object& out) { LoggerD("enter"); - auto onSuccess = [&](const std::vector& result) { + auto onSuccess = [&](const common::Storages& result) { LoggerD("enter"); picojson::array storages; storages.reserve(result.size()); - for (const auto& storage : result) { - storages.push_back(storage.ToJson()); + for (const auto storage : result) { + storages.push_back(storage->ToJson()); } ReportSuccess(picojson::value(storages), out); }; diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc index b0d282ff..468a095d 100644 --- a/src/filesystem/filesystem_manager.cc +++ b/src/filesystem/filesystem_manager.cc @@ -235,7 +235,8 @@ void FilesystemManager::FetchStorages( FilesystemManager::FilesystemManager() : listener_(nullptr), - fs_provider_(common::FilesystemProviderStorage::Create()) { + fs_provider_(common::FilesystemProvider::Create()) { + LoggerD("enter"); } FilesystemManager::~FilesystemManager() { diff --git a/src/filesystem/filesystem_manager.h b/src/filesystem/filesystem_manager.h index 514e0a02..d455ed9a 100644 --- a/src/filesystem/filesystem_manager.h +++ b/src/filesystem/filesystem_manager.h @@ -23,13 +23,11 @@ #include #include -#include "common/filesystem/filesystem_provider_storage.h" - #include "filesystem/filesystem_stat.h" #include "filesystem/filesystem_utils.h" #include "common/filesystem/filesystem_storage.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" namespace extension { namespace filesystem { @@ -47,7 +45,7 @@ class FilesystemManager { FilesystemManager(); FilesystemStateChangeListener* listener_; - common::FilesystemProviderStorage& fs_provider_; + common::FilesystemProvider& fs_provider_; public: diff --git a/src/messaging/message.cc b/src/messaging/message.cc index 991a745e..4444387d 100755 --- a/src/messaging/message.cc +++ b/src/messaging/message.cc @@ -30,7 +30,7 @@ #include "message_mms.h" #include "short_message_manager.h" #include "messaging_util.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" using common::ErrorCode; using common::PlatformResult; @@ -423,7 +423,7 @@ PlatformResult copyFileToTemp(const std::string& sourcePath, std::string* result std::string dirPath = "/tmp/" + std::string(buf); if ( sourcePath[0] != '/' ) { - attPath = common::FilesystemProviderStorage::Create().GetRealPath(sourcePath); + attPath = common::FilesystemProvider::Create().GetRealPath(sourcePath); } else { // Assuming that the path is a real path attPath = sourcePath; } @@ -786,7 +786,7 @@ PlatformResult Message::addMMSBodyAndAttachmentsToStruct(const AttachmentPtrVect if (attach.at(i)->isFilePathSet()) { std::string filepath = attach.at(i)->getFilePath(); LoggerD("att[%d]: org filepath: %s", i, filepath.c_str()); - filepath = common::FilesystemProviderStorage::Create().GetRealPath(filepath); + filepath = common::FilesystemProvider::Create().GetRealPath(filepath); LoggerD("att[%d]: org virtual filepath: %s", i, filepath.c_str()); msg_set_str_value(tmpAtt, MSG_MMS_ATTACH_FILEPATH_STR, diff --git a/src/messaging/message_attachment.cc b/src/messaging/message_attachment.cc index 67db1178..9d1fc231 100755 --- a/src/messaging/message_attachment.cc +++ b/src/messaging/message_attachment.cc @@ -20,7 +20,7 @@ #include "message_attachment.h" #include "common/logger.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" namespace extension { namespace messaging { @@ -143,7 +143,7 @@ void MessageAttachment::setFilePath(const std::string &value) { LoggerD("Entered"); - m_filePath = common::FilesystemProviderStorage::Create().GetRealPath(value); + m_filePath = common::FilesystemProvider::Create().GetRealPath(value); m_isFilePathSet = true; } diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc index f0944683..cdb8e0a2 100644 --- a/src/notification/status_notification.cc +++ b/src/notification/status_notification.cc @@ -23,7 +23,7 @@ #include "common/converter.h" #include "common/logger.h" #include "common/scope_exit.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" namespace extension { namespace notification { @@ -529,7 +529,7 @@ PlatformResult StatusNotification::GetThumbnails(notification_h noti_handle, break; //CHECK GetVirtualPath ?? - out->push_back(picojson::value(common::FilesystemProviderStorage::Create().GetVirtualPath(text))); + out->push_back(picojson::value(common::FilesystemProvider::Create().GetVirtualPath(text))); } return PlatformResult(ErrorCode::NO_ERROR); @@ -543,7 +543,7 @@ PlatformResult StatusNotification::SetThumbnails(notification_h noti_handle, size_t thumbnails_map_size = thumbnails_map_.size(); for (auto& item : value) { const std::string& text = JsonCast(item); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(text); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(text); PlatformResult status = SetImage(noti_handle, thumbnails_map_.at(idx), real_path); @@ -1015,14 +1015,14 @@ PlatformResult StatusNotification::ToJson(int id, if (status.IsError()) return status; if (value_str.length()) { - out["iconPath"] = picojson::value(common::FilesystemProviderStorage::Create().GetVirtualPath(value_str)); + out["iconPath"] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str)); } status = GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, &value_str); if (status.IsError()) return status; if (value_str.length()) { - out["subIconPath"] = picojson::value(common::FilesystemProviderStorage::Create().GetVirtualPath(value_str)); + out["subIconPath"] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str)); } long number; @@ -1061,7 +1061,7 @@ PlatformResult StatusNotification::ToJson(int id, if (status.IsError()) return status; if (value_str.length()) { - out["backgroundImagePath"] = picojson::value(common::FilesystemProviderStorage::Create().GetVirtualPath(value_str)); + out["backgroundImagePath"] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str)); } picojson::array thumbnails = picojson::array(); @@ -1076,7 +1076,7 @@ PlatformResult StatusNotification::ToJson(int id, if (status.IsError()) return status; if (value_str.length()) { - out["soundPath"] = picojson::value(common::FilesystemProviderStorage::Create().GetVirtualPath(value_str)); + out["soundPath"] = picojson::value(common::FilesystemProvider::Create().GetVirtualPath(value_str)); } bool vibration; @@ -1184,7 +1184,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, picojson::value val(noti_obj); if (val.contains("iconPath") && !IsNull(noti_obj, "iconPath")) { const std::string& value_str = common::FromJson(noti_obj, "iconPath"); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(value_str); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON, real_path); if (status.IsError()) { @@ -1195,7 +1195,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, if (val.contains("subIconPath") && !IsNull(noti_obj, "subIconPath")) { const std::string& value_str = common::FromJson(noti_obj, "subIconPath"); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(value_str); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_ICON_SUB, real_path); if (status.IsError()) { @@ -1246,7 +1246,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, if (val.contains("backgroundImagePath") && !IsNull(noti_obj, "backgroundImagePath")) { const std::string& value_str = common::FromJson(noti_obj, "backgroundImagePath"); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(value_str); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); status = SetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_BACKGROUND, real_path); if (status.IsError()) { @@ -1264,7 +1264,7 @@ PlatformResult StatusNotification::FromJson(const picojson::object& args, if (val.contains("soundPath") && !IsNull(noti_obj, "soundPath")) { const std::string& value_str = common::FromJson(noti_obj, "soundPath"); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(value_str); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(value_str); status = SetSoundPath(noti_handle, real_path); if (status.IsError()) { diff --git a/src/systemsetting/systemsetting_instance.cc b/src/systemsetting/systemsetting_instance.cc index dcc63294..c95fbcae 100644 --- a/src/systemsetting/systemsetting_instance.cc +++ b/src/systemsetting/systemsetting_instance.cc @@ -21,7 +21,7 @@ #include "common/logger.h" #include "common/picojson.h" #include "common/task-queue.h" -#include "common/filesystem/filesystem_provider_storage.h" +#include "common/filesystem/filesystem_provider.h" #include "common/tools.h" #include @@ -152,7 +152,7 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o auto get = [this, type, value, callback_id](const std::shared_ptr& response) -> void { LoggerD("Setting platform value"); - std::string real_path = common::FilesystemProviderStorage::Create().GetRealPath(value); + std::string real_path = common::FilesystemProvider::Create().GetRealPath(value); PlatformResult status = setPlatformPropertyValue(type, real_path); picojson::object& obj = response->get(); if (status.IsSuccess()) {