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 
22 class Requestor : public std::enable_shared_from_this<Requestor> {
23  public:
24  enum class HandleOutcome : char {
25  NOT_HANDLED = 'N',
26  PENDING = 'P',
27  DONE = 'D',
28  PARALLEL = 'L',
29  MAYBE_LATER = 'M'
30  };
31 
32  protected:
33  Requestor() {}
34 
35  virtual HandleOutcome handle(RequestPtr) = 0;
36 
37  static void definitive_failure(RequestPtr) ;
38  void forward(RequestPtr) const;
39 
40  std::shared_ptr<Client> api_;
41 
42  public:
43  using RequestPtr = ::ipfs::gw::RequestPtr;
47  virtual std::string_view name() const = 0;
48 
49  virtual ~Requestor() noexcept {}
50  void request(std::shared_ptr<GatewayRequest>);
51  Requestor& or_else(std::shared_ptr<Requestor> p);
52  Requestor& api(std::shared_ptr<Client>);
53 
54  void TestAccess(void*);
55 
56  private:
57  std::shared_ptr<Requestor> next_;
58 };
59 } // namespace ipfs::gw
60 
61 #endif // IPFS_REQUESTOR_H_
Definition: requestor.h:22
virtual std::string_view name() const =0