1 // machine generated, do not edit
2 
3 module sokol.fetch;
4 
5 enum LogItem {
6     Ok,
7     Malloc_failed,
8     File_path_utf8_decoding_failed,
9     Send_queue_full,
10     Request_channel_index_too_big,
11     Request_path_is_null,
12     Request_path_too_long,
13     Request_callback_missing,
14     Request_chunk_size_greater_buffer_size,
15     Request_userdata_ptr_is_set_but_userdata_size_is_null,
16     Request_userdata_ptr_is_null_but_userdata_size_is_not,
17     Request_userdata_size_too_big,
18     Clamping_num_channels_to_max_channels,
19     Request_pool_exhausted,
20 }
21 /// sfetch_logger_t
22 /// 
23 /// Used in sfetch_desc_t to provide a custom logging and error reporting
24 /// callback to sokol-fetch
25 extern(C)
26 struct Logger {
27     extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null;
28     void* user_data = null;
29 }
30 /// sfetch_range_t
31 /// 
32 /// A pointer-size pair struct to pass memory ranges into and out of sokol-fetch.
33 /// When initialized from a value type (array or struct) you can use the
34 /// SFETCH_RANGE() helper macro to build an sfetch_range_t struct
35 extern(C)
36 struct Range {
37     const(void)* ptr = null;
38     size_t size = 0;
39 }
40 /// sfetch_allocator_t
41 /// 
42 /// Used in sfetch_desc_t to provide custom memory-alloc and -free functions
43 /// to sokol_fetch.h. If memory management should be overridden, both the
44 /// alloc and free function must be provided (e.g. it's not valid to
45 /// override one function but not the other)
46 extern(C)
47 struct Allocator {
48     extern(C) void* function(size_t, void*) alloc_fn = null;
49     extern(C) void function(void*, void*) free_fn = null;
50     void* user_data = null;
51 }
52 /// configuration values for sfetch_setup()
53 extern(C)
54 struct Desc {
55     uint max_requests = 0;
56     uint num_channels = 0;
57     uint num_lanes = 0;
58     Allocator allocator;
59     Logger logger;
60 }
61 /// a request handle to identify an active fetch request, returned by sfetch_send()
62 extern(C)
63 struct Handle {
64     uint id = 0;
65 }
66 /// error codes
67 enum Error {
68     No_error,
69     File_not_found,
70     No_buffer,
71     Buffer_too_small,
72     Unexpected_eof,
73     Invalid_http_status,
74     Cancelled,
75 }
76 /// the response struct passed to the response callback
77 extern(C)
78 struct Response {
79     Handle handle;
80     bool dispatched = false;
81     bool fetched = false;
82     bool paused = false;
83     bool finished = false;
84     bool failed = false;
85     bool cancelled = false;
86     Error error_code;
87     uint channel = 0;
88     uint lane = 0;
89     const(char)* path = null;
90     void* user_data = null;
91     uint data_offset = 0;
92     Range data;
93     Range buffer;
94 }
95 /// request parameters passed to sfetch_send()
96 extern(C)
97 struct Request {
98     uint channel = 0;
99     const(char)* path = null;
100     extern(C) void function(const Response *) callback = null;
101     uint chunk_size = 0;
102     Range buffer;
103     Range user_data;
104 }
105 /// setup sokol-fetch (can be called on multiple threads)
106 extern(C) void sfetch_setup(const Desc *) @system @nogc nothrow;
107 /// setup sokol-fetch (can be called on multiple threads)
108 void setup(scope ref Desc desc) @trusted @nogc nothrow {
109     sfetch_setup(&desc);
110 }
111 /// discard a sokol-fetch context
112 extern(C) void sfetch_shutdown() @system @nogc nothrow;
113 /// discard a sokol-fetch context
114 void shutdown() @trusted @nogc nothrow {
115     sfetch_shutdown();
116 }
117 /// return true if sokol-fetch has been setup
118 extern(C) bool sfetch_valid() @system @nogc nothrow;
119 /// return true if sokol-fetch has been setup
120 bool valid() @trusted @nogc nothrow {
121     return sfetch_valid();
122 }
123 /// get the desc struct that was passed to sfetch_setup()
124 extern(C) Desc sfetch_desc() @system @nogc nothrow;
125 /// get the desc struct that was passed to sfetch_setup()
126 Desc desc() @trusted @nogc nothrow {
127     return sfetch_desc();
128 }
129 /// return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t))
130 extern(C) int sfetch_max_userdata_bytes() @system @nogc nothrow;
131 /// return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t))
132 int maxUserdataBytes() @trusted @nogc nothrow {
133     return sfetch_max_userdata_bytes();
134 }
135 /// return the value of the SFETCH_MAX_PATH implementation config value
136 extern(C) int sfetch_max_path() @system @nogc nothrow;
137 /// return the value of the SFETCH_MAX_PATH implementation config value
138 int maxPath() @trusted @nogc nothrow {
139     return sfetch_max_path();
140 }
141 /// send a fetch-request, get handle to request back
142 extern(C) Handle sfetch_send(const Request *) @system @nogc nothrow;
143 /// send a fetch-request, get handle to request back
144 Handle send(scope ref Request request) @trusted @nogc nothrow {
145     return sfetch_send(&request);
146 }
147 /// return true if a handle is valid *and* the request is alive
148 extern(C) bool sfetch_handle_valid(Handle) @system @nogc nothrow;
149 /// return true if a handle is valid *and* the request is alive
150 bool handleValid(Handle h) @trusted @nogc nothrow {
151     return sfetch_handle_valid(h);
152 }
153 /// do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks
154 extern(C) void sfetch_dowork() @system @nogc nothrow;
155 /// do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks
156 void dowork() @trusted @nogc nothrow {
157     sfetch_dowork();
158 }
159 /// bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback
160 extern(C) void sfetch_bind_buffer(Handle, Range) @system @nogc nothrow;
161 /// bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback
162 void bindBuffer(Handle h, Range buffer) @trusted @nogc nothrow {
163     sfetch_bind_buffer(h, buffer);
164 }
165 /// clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback
166 extern(C) void* sfetch_unbind_buffer(Handle) @system @nogc nothrow;
167 /// clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback
168 scope void* unbindBuffer(Handle h) @trusted @nogc nothrow {
169     return sfetch_unbind_buffer(h);
170 }
171 /// cancel a request that's in flight (will call response callback with .cancelled + .finished)
172 extern(C) void sfetch_cancel(Handle) @system @nogc nothrow;
173 /// cancel a request that's in flight (will call response callback with .cancelled + .finished)
174 void cancel(Handle h) @trusted @nogc nothrow {
175     sfetch_cancel(h);
176 }
177 /// pause a request (will call response callback each frame with .paused)
178 extern(C) void sfetch_pause(Handle) @system @nogc nothrow;
179 /// pause a request (will call response callback each frame with .paused)
180 void pause(Handle h) @trusted @nogc nothrow {
181     sfetch_pause(h);
182 }
183 /// continue a paused request
184 extern(C) void sfetch_continue(Handle) @system @nogc nothrow;
185 /// continue a paused request
186 void continueFetching(Handle h) @trusted @nogc nothrow {
187     sfetch_continue(h);
188 }