[Common] Added FilesystemProvider interface for different profiles
authorPiotr Kosko <p.kosko@samsung.com>
Mon, 4 Jan 2016 13:24:36 +0000 (14:24 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 8 Jan 2016 08:12:12 +0000 (09:12 +0100)
Change-Id: Iccb3d1985be54f9c8f2bd6ea1c4a2ebaac1a3ba9
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
20 files changed:
src/archive/archive_instance.cc
src/common/common.gyp
src/common/filesystem/filesystem_provider.cc [new file with mode: 0644]
src/common/filesystem/filesystem_provider.h [new file with mode: 0644]
src/common/filesystem/filesystem_provider_deviced.cc [new file with mode: 0644]
src/common/filesystem/filesystem_provider_deviced.h [new file with mode: 0644]
src/common/filesystem/filesystem_provider_storage.cc
src/common/filesystem/filesystem_provider_storage.h
src/common/filesystem/filesystem_provider_types.h
src/common/filesystem/filesystem_storage.cc
src/content/content_instance.cc
src/content/content_manager.cc
src/download/download_instance.cc
src/filesystem/filesystem_instance.cc
src/filesystem/filesystem_manager.cc
src/filesystem/filesystem_manager.h
src/messaging/message.cc
src/messaging/message_attachment.cc
src/notification/status_notification.cc
src/systemsetting/systemsetting_instance.cc

index 30ec005e590490cb9b441d8cc06b8781f64349bc..97f3f395b4c9d459a60535133670df2c714d7292 100755 (executable)
@@ -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);
index bba10751db0897978778da261f2cdc50138f235c..e93b7cbd736bea4805942b7099f2b95aca702acb 100644 (file)
@@ -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',
       ],
         '-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 (file)
index 0000000..f2a69e7
--- /dev/null
@@ -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 (file)
index 0000000..69030d5
--- /dev/null
@@ -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 <functional>
+#include <vector>
+#include <memory>
+#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<Storage> 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<Storage> 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 (file)
index 0000000..ac08abc
--- /dev/null
@@ -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 <gio/gio.h>
+#include <functional>
+#include <list>
+#include <map>
+#include <algorithm>
+#include <memory>
+#include <utility>
+
+#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<FilesystemProviderDeviced*>(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> 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<Storage> FilesystemProviderDeviced::GetInternalStorage() {
+  return virtual_roots_provider_.GetInternalStorage();
+}
+
+std::shared_ptr<Storage> FilesystemProviderDeviced::GetStorage(const DeviceListElem& elem) {
+  LoggerD("Entered");
+  return std::make_shared<Storage>(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<int>(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<std::mutex> 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<VirtualRoot>(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 (file)
index 0000000..c309445
--- /dev/null
@@ -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 <gio/gio.h>
+
+#include <functional>
+#include <list>
+#include <string>
+#include <map>
+#include <memory>
+#include <mutex>
+
+#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<Storage> GetStorage(const DeviceListElem& elem);
+  static Storages GetStoragesFromGVariant(GVariant* variant);
+  GDBusConnection* dbus_;
+  GDBusProxy* proxy_;
+
+  DeviceChangeStateFun device_changed_callback_;
+  guint block_signal_subscribe_id_;
+  std::map<std::string, StorageState> previous_device_state_map_;
+  FilesystemProviderRef virtual_roots_provider_;
+  std::mutex mutex_;
+
+  bool is_initialized_;
+};
+
+}  // namespace common
+
+#endif /* DEVICED_H */
index 74108863a49f4cff525b9c44744258ec4196a031..4db8a28d0fff1094fefb36cc6f48bd89fff07fc5 100644 (file)
@@ -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<storage_directory_e, const std::string*> 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<FilesystemProviderStorage*>(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>(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
     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_) {
index a486a5d1e7bfbb682a46bc2be4fa1c2455b456a2..fad628a878bc643803866ebd927e356717569ffe 100644 (file)
 #include <string>
 #include <memory>
 #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<Storage> internal_storage_;
 };
 
 }  // namespace common
index cb0695be43012b4134faefbfe8107d1570a5f1c1..ca3c5c6d693aa7f35b4145cdea4e70651b4f45a9 100644 (file)
@@ -11,10 +11,9 @@ namespace common {
 typedef std::function<
     void(common::Storage, common::StorageState,
          common::StorageState)> DeviceChangeStateFun;
-typedef std::vector<common::Storage> Storages;
+typedef std::vector<std::shared_ptr<common::Storage> > Storages;
 typedef std::vector<common::VirtualRoot> VirtualRoots;
 typedef std::vector<std::shared_ptr<common::VirtualStorage> > VirtualStorages;
-
 }  // namespace common
 
-#endif  // COMMON_FILESYSTEM_FILESYSTEM_PROVIDER_TYPES_H_
\ No newline at end of file
+#endif  // COMMON_FILESYSTEM_FILESYSTEM_PROVIDER_TYPES_H_
index 3d737a1d770189d71c05414cd97d13c0bdcd65e0..0427c81002fb0bd00111742ac55836e740d54cd0 100644 (file)
@@ -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<picojson::object>();
 
@@ -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<picojson::object>();
   obj["storage_id"] = picojson::value(static_cast<double>(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";
index 4dffe567df41ea59a314cc0dc9d666d714d04160..659c4f1ca0b933f9788bf4afe9ea4afb2eefbfd7 100755 (executable)
@@ -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<ReplyCallbackData>& user_data) {
     }
     case ContentManagerScanfileCallback: {
       std::string contentURI = user_data->args.get("contentURI").get<std::string>();
-      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(
index 1099b868d80e4d95c38f99329c5c1f385c602b9f..6aa319d1f919f69064e911eed63385127522e1e1 100644 (file)
@@ -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>();
-  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<bool>();
 
   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) {
index a10618e6839b50ad9bc0c08613ef881e0b46475e..964d9437147a4ba3531f8449b94cba66b1c90264 100755 (executable)
@@ -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<double>(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<picojson::null>()) {
     if (args.get("destination").get<std::string>() != "") {
       diPtr->destination = args.get("destination").get<std::string>();
-      diPtr->destination = common::FilesystemProviderStorage::Create().GetRealPath(diPtr->destination);
+      diPtr->destination = common::FilesystemProvider::Create().GetRealPath(diPtr->destination);
     }
   }
 
index 1f5718eefcb0440344587bfb61696d38f68b14d1..af69172256f41cae7c0a99e004288f1dcea01776 100644 (file)
@@ -344,12 +344,12 @@ void FilesystemInstance::FileSystemManagerFetchStorages(
     picojson::object& out) {
   LoggerD("enter");
 
-  auto onSuccess = [&](const std::vector<common::Storage>& 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);
   };
index b0d282ff787dc588f2fa55f03774e12bc783fcb3..468a095dda14d1cd8127532f3543557ca1504b97 100644 (file)
@@ -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() {
index 514e0a02b365189b9e7632901486d75f15719df6..d455ed9a4b0ff5fd3e11e3dd7d917465098b1424 100644 (file)
 #include <set>
 #include <memory>
 
-#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:
 
index 991a745e6e92214761bd37277bf22644cbcedebf..4444387de01bf1b548fd30095ca0c394696e0dd3 100755 (executable)
@@ -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,
index 67db11784763fc867b8d5566b24d51fc18fa969b..9d1fc23156719e2086b20cb102f845d0922df0ed 100755 (executable)
@@ -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;
 }
 
index f0944683858bb727bcaf27113a1b7558220b0ff3..cdb8e0a245af431dbe7c844f0c8a9f4dc85e78ea 100644 (file)
@@ -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<std::string>(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<std::string>(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<std::string>(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<std::string>(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<std::string>(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()) {
index dcc63294dee65d5f9feb472fe38befd354b36c24..c95fbcae3fe7400e2a11385c997941e5d8573195 100644 (file)
@@ -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 <system_settings.h>
@@ -152,7 +152,7 @@ void SystemSettingInstance::setProperty(const picojson::value& args, picojson::o
 
   auto get = [this, type, value, callback_id](const std::shared_ptr<picojson::value>& 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<picojson::object>();
     if (status.IsSuccess()) {