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

Side by Side Diff: include/AdblockPlus/IFileSystem.h

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Rebased on https://codereview.adblockplus.org/29481704 Created July 6, 2017, 10:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #ifndef ADBLOCK_PLUS_FILE_SYSTEM_H 18 #ifndef ADBLOCK_PLUS_IFILE_SYSTEM_H
19 #define ADBLOCK_PLUS_FILE_SYSTEM_H 19 #define ADBLOCK_PLUS_IFILE_SYSTEM_H
20 20
21 #include <istream> 21 #include <istream>
22 #include <stdint.h> 22 #include <stdint.h>
23 #include <string> 23 #include <string>
24 #include <memory> 24 #include <memory>
25 #include <vector>
25 26
26 namespace AdblockPlus 27 namespace AdblockPlus
27 { 28 {
28 /** 29 /**
29 * File system interface. 30 * File system interface.
30 */ 31 */
31 class FileSystem 32 class IFileSystem
32 { 33 {
33 public: 34 public:
34 /** 35 /**
35 * Result of a stat operation, i.e.\ information about a file. 36 * Result of a stat operation, i.e.\ information about a file.
36 */ 37 */
37 struct StatResult 38 struct StatResult
38 { 39 {
39 StatResult() 40 StatResult()
40 { 41 {
41 exists = false; 42 exists = false;
(...skipping 16 matching lines...) Expand all
58 * File is a regular file. 59 * File is a regular file.
59 */ 60 */
60 bool isFile; 61 bool isFile;
61 62
62 /** 63 /**
63 * POSIX time of the last modification. 64 * POSIX time of the last modification.
64 */ 65 */
65 int64_t lastModified; 66 int64_t lastModified;
66 }; 67 };
67 68
69 virtual ~IFileSystem() {}
70
71 /** Type for the buffer used for IO */
68 typedef std::vector<uint8_t> IOBuffer; 72 typedef std::vector<uint8_t> IOBuffer;
69 73
70 virtual ~FileSystem() {} 74 /**
75 * Default callback type for asynchronous filesystem calls.
76 * @param An error string. Empty is success.
77 */
78 typedef std::function<void(const std::string&)> Callback;
79
80 /**
81 * Callback type for the asynchronous Read call.
82 * @param Output char array with file content.
83 * @param An error string. Empty if success.
84 */
85 typedef std::function<void(IOBuffer&&,
86 const std::string&)> ReadCallback;
71 87
72 /** 88 /**
73 * Reads from a file. 89 * Reads from a file.
74 * @param path File path. 90 * @param path File path.
75 * @return Buffer with the file content. 91 * @param callback The function called on completion with the input data.
76 */ 92 */
77 virtual IOBuffer 93 virtual void Read(const std::string& path,
78 Read(const std::string& path) const = 0; 94 const ReadCallback& callback) const = 0;
79 95
80 /** 96 /**
81 * Writes to a file. 97 * Writes to a file.
82 * @param path File path. 98 * @param path File path.
83 * @param data Buffer with the data to write. 99 * @param data The data to write.
100 * @param callback The function called on completion.
84 */ 101 */
85 virtual void Write(const std::string& path, 102 virtual void Write(const std::string& path,
86 const IOBuffer& data) = 0; 103 const IOBuffer& data,
104 const Callback& callback) = 0;
87 105
88 /** 106 /**
89 * Moves a file (i.e.\ renames it). 107 * Moves a file (i.e.\ renames it).
90 * @param fromPath Current path to the file. 108 * @param fromPath Current path to the file.
91 * @param toPath New path to the file. 109 * @param toPath New path to the file.
110 * @param callback The function called on completion.
92 */ 111 */
93 virtual void Move(const std::string& fromPath, 112 virtual void Move(const std::string& fromPath, const std::string& toPath,
94 const std::string& toPath) = 0; 113 const Callback& callback) = 0;
95 114
96 /** 115 /**
97 * Removes a file. 116 * Removes a file.
98 * @param path File path. 117 * @param path File path.
118 * @param callback The function called on completion.
99 */ 119 */
100 virtual void Remove(const std::string& path) = 0; 120 virtual void Remove(const std::string& path, const Callback& callback) = 0;
121
122 /**
123 * Callback type for the asynchronous Stat call.
124 * @param the StatResult data.
125 * @param an error string. Empty if no error.
126 */
127 typedef std::function<void(const StatResult&, const std::string&)> StatCallb ack;
101 128
102 /** 129 /**
103 * Retrieves information about a file. 130 * Retrieves information about a file.
104 * @param path File path. 131 * @param path File path.
105 * @return File information. 132 * @param callback The function called on completion.
106 */ 133 */
107 virtual StatResult Stat(const std::string& path) const = 0; 134 virtual void Stat(const std::string& path,
135 const StatCallback& callback) const = 0;
108 136
109 /** 137 /**
110 * Returns the absolute path to a file. 138 * Returns the absolute path to a file.
111 * @param path File path (can be relative or absolute). 139 * @param path File path (can be relative or absolute).
112 * @return Absolute file path. 140 * @return Absolute file path.
113 */ 141 */
114 virtual std::string Resolve(const std::string& path) const = 0; 142 virtual std::string Resolve(const std::string& path) const = 0;
115 }; 143 };
116 144
117 /** 145 /**
118 * Shared smart pointer to a `FileSystem` instance. 146 * Shared smart pointer to a `IFileSystem` instance.
119 */ 147 */
120 typedef std::shared_ptr<FileSystem> FileSystemPtr; 148 typedef std::shared_ptr<IFileSystem> FileSystemPtr;
121 } 149 }
122 150
123 #endif 151 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld