Index: include/AdblockPlus/IFileSystem.h |
=================================================================== |
copy from include/AdblockPlus/FileSystem.h |
copy to include/AdblockPlus/IFileSystem.h |
--- a/include/AdblockPlus/FileSystem.h |
+++ b/include/AdblockPlus/IFileSystem.h |
@@ -10,30 +10,31 @@ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
-#ifndef ADBLOCK_PLUS_FILE_SYSTEM_H |
-#define ADBLOCK_PLUS_FILE_SYSTEM_H |
+#ifndef ADBLOCK_PLUS_IFILE_SYSTEM_H |
+#define ADBLOCK_PLUS_IFILE_SYSTEM_H |
#include <istream> |
#include <stdint.h> |
#include <string> |
#include <memory> |
+#include <vector> |
namespace AdblockPlus |
{ |
/** |
* File system interface. |
*/ |
- class FileSystem |
+ class IFileSystem |
{ |
public: |
/** |
* Result of a stat operation, i.e.\ information about a file. |
*/ |
struct StatResult |
{ |
StatResult() |
@@ -60,62 +61,87 @@ |
bool isFile; |
/** |
* POSIX time of the last modification. |
*/ |
int64_t lastModified; |
}; |
- virtual ~FileSystem() {} |
+ virtual ~IFileSystem() {} |
+ |
+ /** |
+ * Default callback type for asynchronous filesystem calls. |
+ * @param An error string. Empty is success. |
+ */ |
+ typedef std::function<void(const std::string&)> Callback; |
+ |
+ /** |
+ * Callback type for the asynchronous Read call. |
+ * @param Output char array with file content. |
+ * @param An error string. Empty if success. |
+ */ |
+ typedef std::function<void(std::string&&, const std::string&)> ReadCallback; |
sergei
2017/06/16 15:05:54
I think that the data type for the read data shoul
hub
2017/06/16 21:52:53
I don't think it is better since further down in t
sergei
2017/07/03 09:25:53
I think we can have it but in general I disagree w
hub
2017/07/04 21:20:14
IMHO the C++ iostream interface isn't really conve
sergei
2017/07/05 10:03:20
It's not actually difficult, one has to firstly ob
|
/** |
* Reads from a file. |
* @param path File path. |
- * @return Input stream with the file's contents. |
+ * @param callback The function called on completion with the input data. |
*/ |
- virtual std::shared_ptr<std::istream> |
- Read(const std::string& path) const = 0; |
+ virtual void Read(const std::string& path, |
+ const ReadCallback& callback) const = 0; |
/** |
* Writes to a file. |
* @param path File path. |
* @param data Input stream with the data to write. |
+ * @param callback The function called on completion. |
*/ |
virtual void Write(const std::string& path, |
- std::istream& data) = 0; |
+ std::shared_ptr<std::istream> data, |
sergei
2017/06/16 15:05:54
Instead of `std::shared_ptr<std::istream>` it woul
hub
2017/06/16 21:52:54
I'd rather use std::string for the same reason as
|
+ const Callback& callback) = 0; |
/** |
* Moves a file (i.e.\ renames it). |
* @param fromPath Current path to the file. |
* @param toPath New path to the file. |
+ * @param callback The function called on completion. |
*/ |
- virtual void Move(const std::string& fromPath, |
- const std::string& toPath) = 0; |
+ virtual void Move(const std::string& fromPath, const std::string& toPath, |
+ const Callback& callback) = 0; |
/** |
* Removes a file. |
* @param path File path. |
+ * @param callback The function called on completion. |
*/ |
- virtual void Remove(const std::string& path) = 0; |
+ virtual void Remove(const std::string& path, const Callback& callback) = 0; |
+ |
+ /** |
+ * Callback type for the asynchronous Stat call. |
+ * @param the StatResult data. |
+ * @param an error string. Empty if no error. |
+ */ |
+ typedef std::function<void(const StatResult&, const std::string&)> StatCallback; |
/** |
* Retrieves information about a file. |
* @param path File path. |
- * @return File information. |
+ * @param callback The function called on completion. |
*/ |
- virtual StatResult Stat(const std::string& path) const = 0; |
+ virtual void Stat(const std::string& path, |
+ const StatCallback& callback) const = 0; |
/** |
* Returns the absolute path to a file. |
* @param path File path (can be relative or absolute). |
* @return Absolute file path. |
*/ |
virtual std::string Resolve(const std::string& path) const = 0; |
}; |
/** |
- * Shared smart pointer to a `FileSystem` instance. |
+ * Shared smart pointer to a `IFileSystem` instance. |
*/ |
- typedef std::shared_ptr<FileSystem> FileSystemPtr; |
+ typedef std::shared_ptr<IFileSystem> FileSystemPtr; |
sergei
2017/06/16 15:05:54
OK now, but in future I think it should be std::un
hub
2017/06/16 21:52:53
Acknowledged.
|
} |
#endif |