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 Js_other, 76 } 77 /// the response struct passed to the response callback 78 extern(C) 79 struct Response { 80 Handle handle; 81 bool dispatched = false; 82 bool fetched = false; 83 bool paused = false; 84 bool finished = false; 85 bool failed = false; 86 bool cancelled = false; 87 Error error_code; 88 uint channel = 0; 89 uint lane = 0; 90 const(char)* path = null; 91 void* user_data = null; 92 uint data_offset = 0; 93 Range data; 94 Range buffer; 95 } 96 /// request parameters passed to sfetch_send() 97 extern(C) 98 struct Request { 99 uint channel = 0; 100 const(char)* path = null; 101 extern(C) void function(const Response *) callback = null; 102 uint chunk_size = 0; 103 Range buffer; 104 Range user_data; 105 } 106 /// setup sokol-fetch (can be called on multiple threads) 107 extern(C) void sfetch_setup(const Desc *) @system @nogc nothrow; 108 /// setup sokol-fetch (can be called on multiple threads) 109 void setup(scope ref Desc desc) @trusted @nogc nothrow { 110 sfetch_setup(&desc); 111 } 112 /// discard a sokol-fetch context 113 extern(C) void sfetch_shutdown() @system @nogc nothrow; 114 /// discard a sokol-fetch context 115 void shutdown() @trusted @nogc nothrow { 116 sfetch_shutdown(); 117 } 118 /// return true if sokol-fetch has been setup 119 extern(C) bool sfetch_valid() @system @nogc nothrow; 120 /// return true if sokol-fetch has been setup 121 bool valid() @trusted @nogc nothrow { 122 return sfetch_valid(); 123 } 124 /// get the desc struct that was passed to sfetch_setup() 125 extern(C) Desc sfetch_desc() @system @nogc nothrow; 126 /// get the desc struct that was passed to sfetch_setup() 127 Desc desc() @trusted @nogc nothrow { 128 return sfetch_desc(); 129 } 130 /// return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t)) 131 extern(C) int sfetch_max_userdata_bytes() @system @nogc nothrow; 132 /// return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t)) 133 int maxUserdataBytes() @trusted @nogc nothrow { 134 return sfetch_max_userdata_bytes(); 135 } 136 /// return the value of the SFETCH_MAX_PATH implementation config value 137 extern(C) int sfetch_max_path() @system @nogc nothrow; 138 /// return the value of the SFETCH_MAX_PATH implementation config value 139 int maxPath() @trusted @nogc nothrow { 140 return sfetch_max_path(); 141 } 142 /// send a fetch-request, get handle to request back 143 extern(C) Handle sfetch_send(const Request *) @system @nogc nothrow; 144 /// send a fetch-request, get handle to request back 145 Handle send(scope ref Request request) @trusted @nogc nothrow { 146 return sfetch_send(&request); 147 } 148 /// return true if a handle is valid *and* the request is alive 149 extern(C) bool sfetch_handle_valid(Handle) @system @nogc nothrow; 150 /// return true if a handle is valid *and* the request is alive 151 bool handleValid(Handle h) @trusted @nogc nothrow { 152 return sfetch_handle_valid(h); 153 } 154 /// do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks 155 extern(C) void sfetch_dowork() @system @nogc nothrow; 156 /// do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks 157 void dowork() @trusted @nogc nothrow { 158 sfetch_dowork(); 159 } 160 /// bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback 161 extern(C) void sfetch_bind_buffer(Handle, Range) @system @nogc nothrow; 162 /// bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback 163 void bindBuffer(Handle h, Range buffer) @trusted @nogc nothrow { 164 sfetch_bind_buffer(h, buffer); 165 } 166 /// clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback 167 extern(C) void* sfetch_unbind_buffer(Handle) @system @nogc nothrow; 168 /// clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback 169 scope void* unbindBuffer(Handle h) @trusted @nogc nothrow { 170 return sfetch_unbind_buffer(h); 171 } 172 /// cancel a request that's in flight (will call response callback with .cancelled + .finished) 173 extern(C) void sfetch_cancel(Handle) @system @nogc nothrow; 174 /// cancel a request that's in flight (will call response callback with .cancelled + .finished) 175 void cancel(Handle h) @trusted @nogc nothrow { 176 sfetch_cancel(h); 177 } 178 /// pause a request (will call response callback each frame with .paused) 179 extern(C) void sfetch_pause(Handle) @system @nogc nothrow; 180 /// pause a request (will call response callback each frame with .paused) 181 void pause(Handle h) @trusted @nogc nothrow { 182 sfetch_pause(h); 183 } 184 /// continue a paused request 185 extern(C) void sfetch_continue(Handle) @system @nogc nothrow; 186 /// continue a paused request 187 void continueFetching(Handle h) @trusted @nogc nothrow { 188 sfetch_continue(h); 189 }