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;
44  virtual std::string_view name() const = 0;
45 
46  virtual ~Requestor() noexcept {}
47  void request(std::shared_ptr<GatewayRequest>);
48  Requestor& or_else(std::shared_ptr<Requestor> p);
49  Requestor& api(std::shared_ptr<Client>);
50 
51  void TestAccess(void*);
52 
53  private:
54  std::shared_ptr<Requestor> next_;
55 };
56 } // namespace ipfs::gw
57 
58 #endif // IPFS_REQUESTOR_H_
Definition: requestor.h:22