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

Unified Diff: include/AdblockPlus/IFileSystem.h

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Updated implementation. Created June 2, 2017, 3:49 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
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;
/**
* 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,
+ 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;
}
#endif
« no previous file with comments | « include/AdblockPlus/FileSystem.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | lib/init.js » ('J')

Powered by Google App Engine
This is Rietveld