ipfs-chromium
requestor.h
1 #ifndef IPFS_REQUESTOR_H_
2 #define IPFS_REQUESTOR_H_
3 
4 #include <functional>
5 #include <memory>
6 #include <string_view>
7 
8 namespace ipfs::ipld {
9 class DagNode;
10 }
11 namespace ipfs {
12 class Client;
13 struct Response;
14 } // namespace ipfs
15 
16 namespace ipfs::gw {
17 class GatewayRequest;
18 using RequestPtr = std::shared_ptr<GatewayRequest>;
19 
20 class Requestor : public std::enable_shared_from_this<Requestor> {
21  public:
22  enum class HandleOutcome : char {
23  NOT_HANDLED = 'N',
24  PENDING = 'P',
25  DONE = 'D',
26  PARALLEL = 'L',
27  MAYBE_LATER = 'M'
28  };
29 
30  protected:
31  Requestor() {}
32 
33  virtual HandleOutcome handle(RequestPtr) = 0;
34 
35  void definitive_failure(RequestPtr) const;
36  void forward(RequestPtr) const;
37 
38  std::shared_ptr<Client> api_;
39 
40  public:
41  using RequestPtr = ::ipfs::gw::RequestPtr;
42  virtual std::string_view name() const = 0;
43 
44  virtual ~Requestor() noexcept {}
45  void request(std::shared_ptr<GatewayRequest>);
46  Requestor& or_else(std::shared_ptr<Requestor> p);
47  Requestor& api(std::shared_ptr<Client>);
48 
49  void TestAccess(void*);
50 
51  private:
52  std::shared_ptr<Requestor> next_;
53 };
54 } // namespace ipfs::gw
55 
56 #endif // IPFS_REQUESTOR_H_
Definition: requestor.h:20