RetroArch
nbio.h
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (nbio.h).
5  * ---------------------------------------------------------------------------------------
6  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
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.
21  */
22 
23 #ifndef __LIBRETRO_SDK_NBIO_H
24 #define __LIBRETRO_SDK_NBIO_H
25 
26 #include <stddef.h>
27 #include <boolean.h>
28 
29 #include <retro_common_api.h>
30 
32 
33 #ifndef NBIO_READ
34 #define NBIO_READ 0
35 #endif
36 
37 #ifndef NBIO_WRITE
38 #define NBIO_WRITE 1
39 #endif
40 
41 #ifndef NBIO_UPDATE
42 #define NBIO_UPDATE 2
43 #endif
44 
45 /* these two are blocking; nbio_iterate always returns true, but that operation (or something earlier) may take arbitrarily long */
46 #ifndef BIO_READ
47 #define BIO_READ 3
48 #endif
49 
50 #ifndef BIO_WRITE
51 #define BIO_WRITE 4
52 #endif
53 
54 typedef struct nbio_intf
55 {
56  void *(*open)(const char * filename, unsigned mode);
57 
58  void (*begin_read)(void *data);
59 
60  void (*begin_write)(void *data);
61 
62  bool (*iterate)(void *data);
63 
64  void (*resize)(void *data, size_t len);
65 
66  void *(*get_ptr)(void *data, size_t* len);
67 
68  void (*cancel)(void *data);
69 
70  void (*free)(void *data);
71 
72  /* Human readable string. */
73  const char *ident;
74 } nbio_intf_t;
75 
76 /*
77  * Creates an nbio structure for performing the
78  * given operation on the given file.
79  */
80 void *nbio_open(const char * filename, unsigned mode);
81 
82 /*
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.
85  */
86 void nbio_begin_read(void *data);
87 
88 /*
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.
91  */
92 void nbio_begin_write(void *data);
93 
94 /*
95  * Performs part of the requested operation, or checks how it's going.
96  * When it returns true, it's done.
97  */
98 bool nbio_iterate(void *data);
99 
100 /*
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.
103  */
104 void nbio_resize(void *data, size_t len);
105 
106 /*
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.
109  */
110 void* nbio_get_ptr(void *data, size_t* len);
111 
112 /*
113  * Stops any pending operation, allowing the object to be freed.
114  */
115 void nbio_cancel(void *data);
116 
117 /*
118  * Deletes the nbio structure and its associated pointer.
119  */
120 void nbio_free(void *data);
121 
123 
124 #endif
void nbio_begin_read(void *data)
Definition: nbio_intf.c:52
GLenum mode
Definition: glext.h:6857
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
void * nbio_get_ptr(void *data, size_t *len)
Definition: nbio_intf.c:72
GLenum GLsizei len
Definition: glext.h:7389
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
Definition: ibxm.h:9
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
typedef bool(RETRO_CALLCONV *retro_replace_image_index_t)(unsigned index
Definition: nbio.h:54
struct nbio_intf nbio_intf_t
void(* free)(void *data)
Definition: nbio.h:70
bool(* iterate)(void *data)
Definition: nbio.h:62
void nbio_resize(void *data, size_t len)
Definition: nbio_intf.c:67
void(* resize)(void *data, size_t len)
Definition: nbio.h:64
void nbio_cancel(void *data)
Definition: nbio_intf.c:77
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
void(* cancel)(void *data)
Definition: nbio.h:68
void * nbio_open(const char *filename, unsigned mode)
Definition: nbio_intf.c:47
bool nbio_iterate(void *data)
Definition: nbio_intf.c:62
const char * ident
Definition: nbio.h:73
void nbio_begin_write(void *data)
Definition: nbio_intf.c:57
void nbio_free(void *data)
Definition: nbio_intf.c:82
void(* begin_write)(void *data)
Definition: nbio.h:60
void(* begin_read)(void *data)
Definition: nbio.h:58