summaryrefslogtreecommitdiff
path: root/src/file_opener.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/file_opener.hh')
-rw-r--r--src/file_opener.hh33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/file_opener.hh b/src/file_opener.hh
new file mode 100644
index 0000000..7b01b9f
--- /dev/null
+++ b/src/file_opener.hh
@@ -0,0 +1,33 @@
+#ifndef FILE_OPENER_HH
+#define FILE_OPENER_HH
+
+#include "unique_fd.hh"
+
+#include <filesystem>
+#include <functional>
+#include <memory>
+
+class TaskRunner;
+
+class FileOpener {
+public:
+ virtual ~FileOpener() = default;
+
+ // All callbacks are posted to runner. open() and cancel() must be called
+ // on same thread as runner "runs" on.
+ static std::unique_ptr<FileOpener> create(std::shared_ptr<TaskRunner> runner,
+ size_t threads = 1);
+
+ // Never returns 0.
+ virtual uint32_t open(std::filesystem::path path,
+ std::function<void(uint32_t, unique_fd)> callback) = 0;
+
+ virtual void cancel(uint32_t id) = 0;
+
+protected:
+ FileOpener() = default;
+ FileOpener(FileOpener const&) = delete;
+ FileOpener& operator=(FileOpener const&) = delete;
+};
+
+#endif // FILE_OPENER_HH