summaryrefslogtreecommitdiff
path: root/src/file_opener.hh
blob: 7b01b9f4ca2c081c31a765d2af3c7cbc30c5c04c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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