summaryrefslogtreecommitdiff
path: root/include/llmr/platform/request.hpp
blob: 5ba00830b80e3070fd77005d2c42efdcc9bfc6f0 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef LLMR_PLATFORM_REQUEST
#define LLMR_PLATFORM_REQUEST

#include <string>
#include <functional>
#include <memory>
#include <atomic>

#include <llmr/util/noncopyable.hpp>

// Forward definition.
typedef struct uv_loop_s uv_loop_t;
typedef struct uv_async_s uv_async_t;

namespace uv {
class loop;
}

namespace llmr {
namespace platform {

struct Response;

class Request : public std::enable_shared_from_this<Request>, private util::noncopyable {
public:
    Request(const std::string &url,
            std::function<void(Response *)> callback,
            std::shared_ptr<uv::loop> loop);
    ~Request();

    void complete();

private:
    static void complete(uv_async_t *async);

public:
    const std::string url;
    std::unique_ptr<Response> res;
    std::atomic<bool> cancelled;

public:
    uv_async_t *async = nullptr;
    std::shared_ptr<uv::loop> loop;
};
}
}

#endif