Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include/AdblockPlus/IFileSystem.h

Issue 29508624: Issue 5473 - Update to use libadblockplus revision b4d6e55f2116 (Closed)
Patch Set: Created Aug. 7, 2017, 12:41 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/IFileSystem.h
diff --git a/include/AdblockPlus/FileSystem.h b/include/AdblockPlus/IFileSystem.h
similarity index 52%
copy from include/AdblockPlus/FileSystem.h
copy to include/AdblockPlus/IFileSystem.h
index 97277a802fa9c1966e868086b22539a1db5a4229..463be394e4e56f09d3d9b28d72e3eda2c70608ec 100644
--- a/include/AdblockPlus/FileSystem.h
+++ b/include/AdblockPlus/IFileSystem.h
@@ -15,20 +15,22 @@
* 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 <cstdint>
#include <string>
#include <memory>
+#include <vector>
+#include <functional>
namespace AdblockPlus
{
/**
* File system interface.
*/
- class FileSystem
+ class IFileSystem
{
public:
/**
@@ -65,44 +67,73 @@ namespace AdblockPlus
int64_t lastModified;
};
- virtual ~FileSystem() {}
+ virtual ~IFileSystem() {}
+
+ /** Type for the buffer used for IO */
+ typedef std::vector<uint8_t> IOBuffer;
+
+ /**
+ * 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(IOBuffer&&,
+ const std::string&)> ReadCallback;
/**
* 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 data The data to write.
+ * @param callback The function called on completion.
*/
virtual void Write(const std::string& path,
- std::istream& data) = 0;
+ const IOBuffer& data,
+ 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, const Callback& callback) = 0;
+
+ /**
+ * Callback type for the asynchronous Stat call.
+ * @param the StatResult data.
+ * @param an error string. Empty if no error.
*/
- virtual void Remove(const std::string& path) = 0;
+ 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.
@@ -113,9 +144,9 @@ namespace AdblockPlus
};
/**
- * 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;
}
#endif
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld