2a830977cf50a1a99022c255b64a385502b96ff2
[platform/core/api/webapi-plugins.git] / src / filesystem / filesystem_manager.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef FILESYSTEM_FILESYSTEM_MANAGER_H
18 #define FILESYSTEM_FILESYSTEM_MANAGER_H
19
20 #include <functional>
21 #include <memory>
22 #include <set>
23 #include <string>
24 #include <vector>
25
26 #include "filesystem/filesystem_stat.h"
27 #include "filesystem/filesystem_utils.h"
28
29 #include "common/filesystem/filesystem_provider.h"
30 #include "common/filesystem/filesystem_storage.h"
31
32 namespace extension {
33 namespace filesystem {
34
35 class FilesystemStateChangeListener {
36  public:
37   virtual ~FilesystemStateChangeListener() {
38   }
39   virtual void onFilesystemStateChangeSuccessCallback(const common::Storage& storage) = 0;
40   virtual void onFilesystemStateChangeErrorCallback() = 0;
41 };
42
43 class FilesystemManager {
44  private:
45   FilesystemManager();
46   FilesystemStateChangeListener* listener_;
47
48   common::FilesystemProvider& fs_provider_;
49
50  public:
51   virtual ~FilesystemManager();
52
53   static FilesystemManager& GetInstance();
54
55   void UnlinkFile(const std::string& path, const std::function<void()>& success_cb,
56                   const std::function<void(FilesystemError)>& error_cb);
57
58   void StatPath(const std::string& path,
59                 const std::function<void(const FilesystemStat&)>& success_cb,
60                 const std::function<void(FilesystemError)>& error_cb);
61
62   void FetchStorages(const std::function<void(const common::Storages&)>& success_cb,
63                      const std::function<void(FilesystemError)>& error_cb);
64
65   void FetchAllStorages(const std::function<void(const common::VirtualStorages&)>& success_cb,
66                        const std::function<void(FilesystemError)>& error_cb);
67
68   void CreateFile(const std::string& path,
69                   const std::function<void(const FilesystemStat&)>& success_cb,
70                   const std::function<void(FilesystemError)>& error_cb);
71
72   void Rename(const std::string& oldPath, const std::string& newPath,
73               const std::function<void(const FilesystemStat&)>& success_cb,
74               const std::function<void(FilesystemError)>& error_cb);
75
76   void MakeDirectory(const std::string& path,
77                      const std::function<void(FilesystemError)>& result_cb);
78
79   void ReadDir(const std::string& path,
80                const std::function<void(const std::vector<std::string>&)>& success_cb,
81                const std::function<void(FilesystemError)>& error_cb);
82
83   void RemoveDirectory(const std::string& path, const std::function<void()>& success_cb,
84                        const std::function<void(FilesystemError)>& error_cb);
85
86   void CopyTo(const std::string& originFilePath, const std::string& destinationFilePath,
87               const bool overwrite, const std::function<void()>& success_cb,
88               const std::function<void(FilesystemError)>& error_cb);
89
90   void StartListening();
91   void StopListening();
92   void OnStorageDeviceChanged(common::Storage const& _virtualStorage, common::StorageState _old,
93                               common::StorageState _new);
94   void AddListener(FilesystemStateChangeListener* listener);
95   void RemoveListener();
96
97   void GetCanonicalPath(const std::string& path,
98                         const std::function<void(const std::string&)>& success_cb,
99                         const std::function<void(FilesystemError)>& error_cb);
100 };
101 }  // namespace filesystem
102 }  // namespace extension
103
104 #endif  // FILESYSTEM_FILESYSTEM_MANAGER_H