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

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

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created May 26, 2017, 12:43 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
(...skipping 10 matching lines...) Expand all
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 25
26 namespace AdblockPlus 26 namespace AdblockPlus
27 { 27 {
28 /** 28 /**
29 * File system interface. 29 * File system interface.
30 */ 30 */
31 class FileSystem 31 class FileSystem
sergei 2017/05/26 13:32:04 I expected to have a completely new interface with
32 { 32 {
33 public: 33 public:
34 /** 34 /**
35 * Result of a stat operation, i.e.\ information about a file. 35 * Result of a stat operation, i.e.\ information about a file.
36 */ 36 */
37 struct StatResult 37 struct StatResult
38 { 38 {
39 StatResult() 39 StatResult()
40 { 40 {
41 exists = false; 41 exists = false;
(...skipping 18 matching lines...) Expand all
60 bool isFile; 60 bool isFile;
61 61
62 /** 62 /**
63 * POSIX time of the last modification. 63 * POSIX time of the last modification.
64 */ 64 */
65 int64_t lastModified; 65 int64_t lastModified;
66 }; 66 };
67 67
68 virtual ~FileSystem() {} 68 virtual ~FileSystem() {}
69 69
70 typedef std::function<void (void)> Callback;
sergei 2017/05/26 13:32:04 Not sure whether we use a space between return typ
sergei 2017/05/26 13:32:04 We need a documentation for public things.
sergei 2017/05/26 13:32:04 Could you please not use (void), it's equivalent t
hub 2017/06/02 16:04:16 I would put a space, but then elsewhere it doesn't
hub 2017/06/02 16:04:16 Acknowledged.
71 typedef std::function<void (std::shared_ptr<std::istream>)> ReadCallback;
sergei 2017/05/26 13:32:04 I would propose to change the signature to std::fu
72
70 /** 73 /**
71 * Reads from a file. 74 * Reads from a file.
72 * @param path File path. 75 * @param path File path.
73 * @return Input stream with the file's contents. 76 * @return Input stream with the file's contents.
74 */ 77 */
75 virtual std::shared_ptr<std::istream> 78 virtual std::shared_ptr<std::istream>
76 Read(const std::string& path) const = 0; 79 Read(const std::string& path) const = 0;
80 virtual void Read(const std::string& path,
81 const ReadCallback& callback) const = 0;
77 82
78 /** 83 /**
79 * Writes to a file. 84 * Writes to a file.
80 * @param path File path. 85 * @param path File path.
81 * @param data Input stream with the data to write. 86 * @param data Input stream with the data to write.
82 */ 87 */
83 virtual void Write(const std::string& path, 88 virtual void Write(const std::string& path,
84 std::istream& data) = 0; 89 std::istream& data) = 0;
90 virtual void Write(const std::string& path,
91 std::istream& data,
92 const Callback& callback) = 0;
85 93
86 /** 94 /**
87 * Moves a file (i.e.\ renames it). 95 * Moves a file (i.e.\ renames it).
88 * @param fromPath Current path to the file. 96 * @param fromPath Current path to the file.
89 * @param toPath New path to the file. 97 * @param toPath New path to the file.
90 */ 98 */
91 virtual void Move(const std::string& fromPath, 99 virtual void Move(const std::string& fromPath,
92 const std::string& toPath) = 0; 100 const std::string& toPath) = 0;
101 virtual void Move(const std::string& fromPath,
102 const std::string& toPath,
103 const Callback& callback) = 0;
93 104
94 /** 105 /**
95 * Removes a file. 106 * Removes a file.
96 * @param path File path. 107 * @param path File path.
97 */ 108 */
98 virtual void Remove(const std::string& path) = 0; 109 virtual void Remove(const std::string& path) = 0;
110 virtual void Remove(const std::string& path, const Callback& callback) = 0;
99 111
112 typedef std::function<void (const StatResult&)> StatCallback;
100 /** 113 /**
101 * Retrieves information about a file. 114 * Retrieves information about a file.
102 * @param path File path. 115 * @param path File path.
103 * @return File information. 116 * @return File information.
104 */ 117 */
105 virtual StatResult Stat(const std::string& path) const = 0; 118 virtual StatResult Stat(const std::string& path) const = 0;
119 virtual void Stat(const std::string& path,
120 const StatCallback& callback) const = 0;
106 121
122 typedef std::function<void (const std::string&)> ResolveCallback;
107 /** 123 /**
108 * Returns the absolute path to a file. 124 * Returns the absolute path to a file.
109 * @param path File path (can be relative or absolute). 125 * @param path File path (can be relative or absolute).
110 * @return Absolute file path. 126 * @return Absolute file path.
111 */ 127 */
112 virtual std::string Resolve(const std::string& path) const = 0; 128 virtual std::string Resolve(const std::string& path) const = 0;
129 virtual void Resolve(const std::string& path,
sergei 2017/05/26 13:32:04 I'm not sure whether resolve should be asynchronou
hub 2017/06/02 16:04:16 I thought twice about that. I looked at NodeJS for
130 const ResolveCallback& callback) const = 0;
113 }; 131 };
114 132
115 /** 133 /**
116 * Shared smart pointer to a `FileSystem` instance. 134 * Shared smart pointer to a `FileSystem` instance.
117 */ 135 */
118 typedef std::shared_ptr<FileSystem> FileSystemPtr; 136 typedef std::shared_ptr<FileSystem> FileSystemPtr;
119 } 137 }
120 138
121 #endif 139 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld