1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (nbio.h).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __LIBRETRO_SDK_NBIO_H
24 #define __LIBRETRO_SDK_NBIO_H
29 #include <retro_common_api.h>
45 /* these two are blocking; nbio_iterate always returns true, but that operation (or something earlier) may take arbitrarily long */
54 typedef struct nbio_intf
56 void *(*open)(const char * filename, unsigned mode);
58 void (*begin_read)(void *data);
60 void (*begin_write)(void *data);
62 bool (*iterate)(void *data);
64 void (*resize)(void *data, size_t len);
66 void *(*get_ptr)(void *data, size_t* len);
68 void (*cancel)(void *data);
70 void (*free)(void *data);
72 /* Human readable string. */
77 * Creates an nbio structure for performing the
78 * given operation on the given file.
80 void *nbio_open(const char * filename, unsigned mode);
83 * Starts reading the given file. When done, it will be available in nbio_get_ptr.
84 * Can not be done if the structure was created with {N,}BIO_WRITE.
86 void nbio_begin_read(void *data);
89 * Starts writing to the given file. Before this, you should've copied the data to nbio_get_ptr.
90 * Can not be done if the structure was created with {N,}BIO_READ.
92 void nbio_begin_write(void *data);
95 * Performs part of the requested operation, or checks how it's going.
96 * When it returns true, it's done.
98 bool nbio_iterate(void *data);
101 * Resizes the file up to the given size; cannot shrink.
102 * Can not be done if the structure was created with {N,}BIO_READ.
104 void nbio_resize(void *data, size_t len);
107 * Returns a pointer to the file data. Writable only if structure was not created with {N,}BIO_READ.
108 * If any operation is in progress, the pointer will be NULL, but len will still be correct.
110 void* nbio_get_ptr(void *data, size_t* len);
113 * Stops any pending operation, allowing the object to be freed.
115 void nbio_cancel(void *data);
118 * Deletes the nbio structure and its associated pointer.
120 void nbio_free(void *data);