summaryrefslogtreecommitdiff
path: root/include/mbgl/storage/http_request_baton.hpp
blob: 74c0ff498ed44011e62e265b209a03f4c8d762e2 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef MBGL_STORAGE_HTTP_REQUEST_BATON
#define MBGL_STORAGE_HTTP_REQUEST_BATON

#include "response.hpp"
#include <mbgl/util/ptr.hpp>

#include <string>
#include <thread>

typedef struct uv_async_s uv_async_t;

namespace mbgl {

class HTTPRequest;

enum class HTTPResponseType : int8_t {
    // This error probably won't be resolved by retrying anytime soon. We are giving up.
    PermanentError = -5,

    // This error might be resolved by waiting some time (e.g. server issues).
    // We are going to do an exponential back-off and will try again in a few seconds.
    TemporaryError = -4,

    // This error was caused by a temporary error and it is likely that it will be resolved
    // immediately. We are going to try again right away. This is like the TemporaryError, except
    // that we will not perform exponential back-off.
    SingularError = -3,

    // This error might be resolved once the network reachability status changes.
    // We are going to watch the network status for changes and will retry as soon as the operating
    // system notifies us of a network status change.
    ConnectionError = -2,

    // The request was canceled programatically.
    Canceled = -1,

    // The request is still in progress.
    Unknown = 0,

    // The request returned data successfully. We retrieved and decoded the data successfully.
    Successful = 1,

    // The request confirmed that the data wasn't changed. We already have the data.
    NotModified = 2,
};

struct HTTPRequestBaton {
    HTTPRequestBaton(const std::string &path);
    ~HTTPRequestBaton();

    const std::thread::id thread_id;
    const std::string path;

    HTTPRequest *request = nullptr;
    uv_async_t *async = nullptr;

    HTTPResponseType type = HTTPResponseType::Unknown;
    std::unique_ptr<Response> response;

    // Implementation specific use.
    void *ptr = nullptr;

    // IMPLEMENT THESE 3 PLATFORM SPECIFIC FUNCTIONS:

    // Begin the HTTP request. Platform-specific implementation.
    static void start(const util::ptr<HTTPRequestBaton> &ptr);

    // This will be called to stop/cancel the HTTP request (if possible). Platform-specific implementation.
    static void stop(const util::ptr<HTTPRequestBaton> &ptr);
};

}

#endif