JackUtils 0.5
Provides simplified Jack API for clients :)
Loading...
Searching...
No Matches
ju_buffer.h
Go to the documentation of this file.
1/* FIFO Buffer Extension for jackutils library.
2 * Copyright (C) UtoECat 2022. All rights Reserved!
3
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
27#pragma once
28
29#include <ju_defs.h>
30#include <threads.h>
31
40typedef struct ju_buff_s ju_buff_t;
41
45struct ju_buff_s {
46 char* data; /*< raw buffer */
47 size_t pos; /*< position in buffer */
48 size_t len; /*< size of the buffer in bytes */
49 mtx_t lock; /*< mutex */
50 int (*except) (ju_buff_t*, ju_ssize_t); /*< owerflow/underflow handler */
51};
52
53#define JBU_API
54
61JBU_API void (ju_buff_init) (ju_buff_t* b, size_t s);
62
68JBU_API void (ju_buff_uninit)(ju_buff_t* b);
69
77JBU_API void (ju_buff_resize)(ju_buff_t* b, size_t s);
78
85JBU_API void (ju_buff_check_size)(ju_buff_t* b, size_t s);
86
101JBU_API void ju_buff_except(ju_buff_t* b, int (*cb) (ju_buff_t*, ju_ssize_t));
102
109JBU_API size_t (ju_buff_size)(ju_buff_t* b);
110
117JBU_API size_t (ju_buff_used)(ju_buff_t* b);
118
125JBU_API size_t (ju_buff_space)(ju_buff_t* b);
126
135JBU_API size_t (ju_buff_append)(ju_buff_t* b, const void* src, size_t size);
136
146JBU_API size_t (ju_buff_fill )(ju_buff_t* b, const void* src, size_t size, size_t n);
147
156JBU_API size_t (ju_buff_remove)(ju_buff_t*, void* dst, size_t size);
157
164JBU_API void (ju_buff_move) (ju_buff_t*, ju_ssize_t v);
165
169JBU_API size_t (ju_buff_read )(ju_buff_t*, int fd, size_t);
170
174JBU_API size_t (ju_buff_write)(ju_buff_t*, int fd, size_t);
175
181JBU_API void* (ju_buff_data)(ju_buff_t* b);
182
193JBU_API void (ju_buff_lock)(ju_buff_t* b);
194
199JBU_API void (ju_buff_unlock)(ju_buff_t* b);
200
signed long ju_ssize_t
Signed size type.
Definition: ju_defs.h:41
JBU_API void() ju_buff_move(ju_buff_t *, ju_ssize_t v)
Moves buffer data forwards or backwards...
Definition: ju_buffer.c:121
JBU_API size_t() ju_buff_append(ju_buff_t *b, const void *src, size_t size)
Adds data from array to te end of the buffer.
Definition: ju_buffer.c:79
JBU_API void *() ju_buff_data(ju_buff_t *b)
Returns buffer data from the beginning.
Definition: ju_buffer.c:161
JBU_API void() ju_buff_init(ju_buff_t *b, size_t s)
Initializes buffer structure.
Definition: ju_buffer.c:36
JBU_API size_t() ju_buff_fill(ju_buff_t *b, const void *src, size_t size, size_t n)
Adds data from src array copied N times to the end of the buffer.
Definition: ju_buffer.c:92
JBU_API void() ju_buff_resize(ju_buff_t *b, size_t s)
Resizes buffer structure.
Definition: ju_buffer.c:51
JBU_API void ju_buff_except(ju_buff_t *b, int(*cb)(ju_buff_t *, ju_ssize_t))
Underflow/owerflow exception handling.
Definition: ju_buffer.c:65
JBU_API void() ju_buff_check_size(ju_buff_t *b, size_t s)
Check size of buffer with requested, and resizes if there is not enough spce.
Definition: ju_buffer.c:58
JBU_API void() ju_buff_lock(ju_buff_t *b)
Locks buffer.
Definition: ju_buffer.c:165
JBU_API size_t() ju_buff_used(ju_buff_t *b)
Returns size of buffer busy part.
Definition: ju_buffer.c:72
JBU_API size_t() ju_buff_space(ju_buff_t *b)
Returns size of buffer empity part.
Definition: ju_buffer.c:75
JBU_API void() ju_buff_uninit(ju_buff_t *b)
Deinitializes buffer structure.
Definition: ju_buffer.c:45
JBU_API size_t() ju_buff_write(ju_buff_t *, int fd, size_t)
Similar to ju_buff_remove(), but writes values to the the file by descriptor.
Definition: ju_buffer.c:148
JBU_API size_t() ju_buff_read(ju_buff_t *, int fd, size_t)
Similar to ju_buff_append(), but reads values from the file by descriptor.
Definition: ju_buffer.c:136
JBU_API size_t() ju_buff_size(ju_buff_t *b)
Returns buffer summary size (used and unused).
Definition: ju_buffer.c:69
JBU_API size_t() ju_buff_remove(ju_buff_t *, void *dst, size_t size)
Removes data from start of buffer to the dst array.
Definition: ju_buffer.c:107
JBU_API void() ju_buff_unlock(ju_buff_t *b)
Unlocks buffer.
Definition: ju_buffer.c:168
Main header file with general definitions for the JackUtils API.
FIFO Buffer internal structure.
Definition: ju_buffer.h:45