summaryrefslogtreecommitdiff
path: root/include/llmr/platform/platform.hpp
blob: 4536bf045357ad6ad2273e29cdec0ca09a42f45a (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_PLATFORM
#define LLMR_PLATFORM_PLATFORM

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

namespace llmr {

extern const char *kSpriteURL;

namespace platform {

// Restarts painting. This could for example trigger the event loop of the controlling application.
void restart();

class Request;


struct Response {

    int16_t code = -1;
    std::string body;

    std::string error_message;
};

// Makes an HTTP request of a URL on a background thread, calls a function with the results in
// another thread, then calls the foreground callback in the original main thread.
// Returns a cancellable request.
std::shared_ptr<Request> request_http(const std::string &url,
                                      std::function<void(Response *)> background_function,
                                      std::function<void()> foreground_callback);

// Cancels an HTTP request.
void cancel_request_http(const std::shared_ptr<Request> &req);

// Returns a relative timestamp in seconds. This value must be monotonic.
double elapsed();

// Shows an RGBA image with the specified dimensions in a named window.
void show_debug_image(std::string name, const char *data, size_t width, size_t height);

}

}

#endif