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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <cstdint>
23 #include <string> 23 #include <string>
24 #include <memory> 24 #include <memory>
25 #include <vector>
26 #include <functional>
25 27
26 namespace AdblockPlus 28 namespace AdblockPlus
27 { 29 {
28 /** 30 /**
29 * File system interface. 31 * File system interface.
30 */ 32 */
31 class FileSystem 33 class IFileSystem
32 { 34 {
33 public: 35 public:
34 /** 36 /**
35 * Result of a stat operation, i.e.\ information about a file. 37 * Result of a stat operation, i.e.\ information about a file.
36 */ 38 */
37 struct StatResult 39 struct StatResult
38 { 40 {
39 StatResult() 41 StatResult()
40 { 42 {
41 exists = false; 43 exists = false;
(...skipping 16 matching lines...) Expand all
58 * File is a regular file. 60 * File is a regular file.
59 */ 61 */
60 bool isFile; 62 bool isFile;
61 63
62 /** 64 /**
63 * POSIX time of the last modification. 65 * POSIX time of the last modification.
64 */ 66 */
65 int64_t lastModified; 67 int64_t lastModified;
66 }; 68 };
67 69
68 virtual ~FileSystem() {} 70 virtual ~IFileSystem() {}
71
72 /** Type for the buffer used for IO */
73 typedef std::vector<uint8_t> IOBuffer;
74
75 /**
76 * Default callback type for asynchronous filesystem calls.
77 * @param An error string. Empty is success.
78 */
79 typedef std::function<void(const std::string&)> Callback;
80
81 /**
82 * Callback type for the asynchronous Read call.
83 * @param Output char array with file content.
84 * @param An error string. Empty if success.
85 */
86 typedef std::function<void(IOBuffer&&,
87 const std::string&)> ReadCallback;
69 88
70 /** 89 /**
71 * Reads from a file. 90 * Reads from a file.
72 * @param path File path. 91 * @param path File path.
73 * @return Input stream with the file's contents. 92 * @param callback The function called on completion with the input data.
74 */ 93 */
75 virtual std::shared_ptr<std::istream> 94 virtual void Read(const std::string& path,
76 Read(const std::string& path) const = 0; 95 const ReadCallback& callback) const = 0;
77 96
78 /** 97 /**
79 * Writes to a file. 98 * Writes to a file.
80 * @param path File path. 99 * @param path File path.
81 * @param data Input stream with the data to write. 100 * @param data The data to write.
101 * @param callback The function called on completion.
82 */ 102 */
83 virtual void Write(const std::string& path, 103 virtual void Write(const std::string& path,
84 std::istream& data) = 0; 104 const IOBuffer& data,
105 const Callback& callback) = 0;
85 106
86 /** 107 /**
87 * Moves a file (i.e.\ renames it). 108 * Moves a file (i.e.\ renames it).
88 * @param fromPath Current path to the file. 109 * @param fromPath Current path to the file.
89 * @param toPath New path to the file. 110 * @param toPath New path to the file.
111 * @param callback The function called on completion.
90 */ 112 */
91 virtual void Move(const std::string& fromPath, 113 virtual void Move(const std::string& fromPath, const std::string& toPath,
92 const std::string& toPath) = 0; 114 const Callback& callback) = 0;
93 115
94 /** 116 /**
95 * Removes a file. 117 * Removes a file.
96 * @param path File path. 118 * @param path File path.
119 * @param callback The function called on completion.
97 */ 120 */
98 virtual void Remove(const std::string& path) = 0; 121 virtual void Remove(const std::string& path, const Callback& callback) = 0;
122
123 /**
124 * Callback type for the asynchronous Stat call.
125 * @param the StatResult data.
126 * @param an error string. Empty if no error.
127 */
128 typedef std::function<void(const StatResult&, const std::string&)> StatCallb ack;
99 129
100 /** 130 /**
101 * Retrieves information about a file. 131 * Retrieves information about a file.
102 * @param path File path. 132 * @param path File path.
103 * @return File information. 133 * @param callback The function called on completion.
104 */ 134 */
105 virtual StatResult Stat(const std::string& path) const = 0; 135 virtual void Stat(const std::string& path,
136 const StatCallback& callback) const = 0;
106 137
107 /** 138 /**
108 * Returns the absolute path to a file. 139 * Returns the absolute path to a file.
109 * @param path File path (can be relative or absolute). 140 * @param path File path (can be relative or absolute).
110 * @return Absolute file path. 141 * @return Absolute file path.
111 */ 142 */
112 virtual std::string Resolve(const std::string& path) const = 0; 143 virtual std::string Resolve(const std::string& path) const = 0;
113 }; 144 };
114 145
115 /** 146 /**
116 * Shared smart pointer to a `FileSystem` instance. 147 * Shared smart pointer to a `IFileSystem` instance.
117 */ 148 */
118 typedef std::shared_ptr<FileSystem> FileSystemPtr; 149 typedef std::shared_ptr<IFileSystem> FileSystemPtr;
119 } 150 }
120 151
121 #endif 152 #endif
OLDNEW
« 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