| 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,63 +61,91 @@ | 
| bool isFile; | 
| /** | 
| * POSIX time of the last modification. | 
| */ | 
| int64_t lastModified; | 
| }; | 
| + virtual ~IFileSystem() {} | 
| + | 
| + /** Type for the buffer used for IO */ | 
| typedef std::vector<uint8_t> IOBuffer; | 
| - virtual ~FileSystem() {} | 
| + /** | 
| + * 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 Buffer with the file content. | 
| + * @param callback The function called on completion with the input data. | 
| */ | 
| - virtual IOBuffer 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 Buffer 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, | 
| - const IOBuffer& 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) = 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 |