EasyGUI
gui_buff.h
1 
6 /*
7  * Copyright (c) 2019 Tilen MAJERLE
8  *
9  * Permission is hereby granted, free of charge, to any person
10  * obtaining a copy of this software and associated documentation
11  * files (the "Software"), to deal in the Software without restriction,
12  * including without limitation the rights to use, copy, modify, merge,
13  * publish, distribute, sublicense, and/or sell copies of the Software,
14  * and to permit persons to whom the Software is furnished to do so,
15  * subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  *
29  * This file is part of EasyGUI library.
30  *
31  * Author: Tilen Majerle <tilen@majerle.eu>
32  */
33 #ifndef GUI_HDR_BUFF_H
34 #define GUI_HDR_BUFF_H
35 
36 /* C++ detection */
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
48 #include "gui_utils.h"
49 #include <stdlib.h>
50 #include <string.h>
51 #include <stdint.h>
52 
53 #define GUI_BUFFER_INITIALIZED 0x01
54 #define GUI_BUFFER_MALLOC 0x02
59 typedef struct gui_buff_t {
60  uint32_t size;
61  uint32_t in;
62  uint32_t out;
63  uint8_t* buff;
64  uint8_t flags;
65  void* arg;
66 } gui_buff_t;
67 
68 uint8_t gui_buffer_init(gui_buff_t* buff, uint32_t size, void* buff_ptr);
69 void gui_buffer_free(gui_buff_t* buff);
70 uint32_t gui_buffer_write(gui_buff_t* buff, const void* data, uint32_t count);
71 uint32_t gui_buffer_read(gui_buff_t* buff, void* data, uint32_t count);
72 uint32_t gui_buffer_getfree(gui_buff_t* buff);
73 uint32_t gui_buffer_getfull(gui_buff_t* buff);
74 void gui_buffer_reset(gui_buff_t* buff);
75 
80 /* C++ detection */
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif /* GUI_HDR_BUFF_H */
void gui_buffer_free(gui_buff_t *buff)
Free memory for buffer allocated using dynamic memory allocation.
Definition: gui_buff.c:76
uint8_t gui_buffer_init(gui_buff_t *buff, uint32_t size, void *buff_ptr)
Initializes buffer structure for work.
Definition: gui_buff.c:47
uint32_t in
Definition: gui_buff.h:61
void gui_buffer_reset(gui_buff_t *buff)
Resets (clears) buffer pointers.
Definition: gui_buff.c:229
uint32_t gui_buffer_getfull(gui_buff_t *buff)
Gets number of elements in buffer.
Definition: gui_buff.c:206
void * arg
Definition: gui_buff.h:65
uint32_t out
Definition: gui_buff.h:62
uint8_t * buff
Definition: gui_buff.h:63
uint32_t gui_buffer_write(gui_buff_t *buff, const void *data, uint32_t count)
Writes data to buffer.
Definition: gui_buff.c:95
uint8_t flags
Definition: gui_buff.h:64
uint32_t size
Definition: gui_buff.h:60
uint32_t gui_buffer_getfree(gui_buff_t *buff)
Gets number of free elements in buffer.
Definition: gui_buff.c:182
uint32_t gui_buffer_read(gui_buff_t *buff, void *data, uint32_t count)
Reads data from buffer.
Definition: gui_buff.c:140
Buffer structure.
Definition: gui_buff.h:59