BSB Developer Docs
Loading...
Searching...
No Matches
pipe.h
Go to the documentation of this file.
1
11#pragma once
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#include <furi.h>
18#include <stddef.h>
19
27typedef enum {
28 PipeRoleAlice,
29 PipeRoleBob,
30} PipeRole;
31
45typedef enum {
46 PipeStateOpen,
47 PipeStateBroken,
48} PipeState;
49
50typedef struct PipeSide PipeSide;
51
52typedef struct {
53 PipeSide* alices_side;
54 PipeSide* bobs_side;
56
57typedef struct {
58 size_t capacity;
59 size_t trigger_level;
61
78PipeSideBundle pipe_alloc(size_t capacity, size_t trigger_level);
79
97
109
123
137void pipe_close(PipeSide* pipe);
138
148void pipe_free(PipeSide* pipe);
149
164
177void pipe_set_state_check_period(PipeSide* pipe, FuriWait check_period);
178
192size_t pipe_receive(PipeSide* pipe, void* data, size_t length);
193
207size_t pipe_send(PipeSide* pipe, const void* data, size_t length);
208
215size_t pipe_bytes_available(PipeSide* pipe);
216
224size_t pipe_spaces_available(PipeSide* pipe);
225
233void pipe_attach_to_event_loop(PipeSide* pipe, FuriEventLoop* event_loop);
234
242
249typedef void (*PipeSideDataArrivedCallback)(PipeSide* pipe, void* context);
250
257typedef void (*PipeSideSpaceFreedCallback)(PipeSide* pipe, void* context);
258
266typedef void (*PipeSideBrokenCallback)(PipeSide* pipe, void* context);
267
274void pipe_set_callback_context(PipeSide* pipe, void* context);
275
289 PipeSide* pipe,
291 FuriEventLoopEvent event);
292
306 PipeSide* pipe,
308 FuriEventLoopEvent event);
309
324 PipeSide* pipe,
325 PipeSideBrokenCallback callback,
326 FuriEventLoopEvent event);
327
328#ifdef __cplusplus
329}
330#endif
void pipe_set_data_arrived_callback(PipeSide *pipe, PipeSideDataArrivedCallback callback, FuriEventLoopEvent event)
Sets the callback for when data arrives.
Definition pipe.c:248
PipeSideBundle pipe_alloc_ex(PipeSideReceiveSettings alice, PipeSideReceiveSettings bob)
Allocates two connected sides of one pipe.
Definition pipe.c:44
PipeRole
The role of a pipe side.
Definition pipe.h:27
void pipe_set_state_check_period(PipeSide *pipe, FuriWait check_period)
Sets the state check period for send and receive operations.
Definition pipe.c:146
PipeSideBundle pipe_alloc(size_t capacity, size_t trigger_level)
Allocates two connected sides of one pipe.
Definition pipe.c:36
void pipe_attach_to_event_loop(PipeSide *pipe, FuriEventLoop *event_loop)
Attaches a PipeSide to a FuriEventLoop, allowing to attach callbacks to the PipeSide.
Definition pipe.c:224
PipeRole pipe_role(PipeSide *pipe)
Gets the role of a pipe side.
Definition pipe.c:78
PipeState
The state of a pipe.
Definition pipe.h:45
void(* PipeSideBrokenCallback)(PipeSide *pipe, void *context)
Callback for when the opposite PipeSide is freed, making the pipe broken.
Definition pipe.h:266
void pipe_close(PipeSide *pipe)
Marks a pipe as broken without freeing memory.
Definition pipe.c:90
void pipe_set_space_freed_callback(PipeSide *pipe, PipeSideSpaceFreedCallback callback, FuriEventLoopEvent event)
Sets the callback for when data is read out of the opposite PipeSide.
Definition pipe.c:267
void pipe_install_as_stdio(PipeSide *pipe)
Connects the pipe to the stdin and stdout of the current thread.
Definition pipe.c:140
void(* PipeSideSpaceFreedCallback)(PipeSide *pipe, void *context)
Callback for when data is read out of the opposite PipeSide.
Definition pipe.h:257
size_t pipe_spaces_available(PipeSide *pipe)
Determines how many space there is in the pipe for data to be written into.
Definition pipe.c:190
void pipe_detach_from_event_loop(PipeSide *pipe)
Detaches a PipeSide from the FuriEventLoop that it was previously attached to.
Definition pipe.c:232
PipeState pipe_state(PipeSide *pipe)
Gets the state of a pipe.
Definition pipe.c:83
size_t pipe_bytes_available(PipeSide *pipe)
Determines how many bytes there are in the pipe available to be read.
Definition pipe.c:185
void pipe_set_callback_context(PipeSide *pipe, void *context)
Sets the custom context for all callbacks.
Definition pipe.c:243
void pipe_set_broken_callback(PipeSide *pipe, PipeSideBrokenCallback callback, FuriEventLoopEvent event)
Sets the callback for when the opposite PipeSide is freed, making the pipe broken.
Definition pipe.c:286
size_t pipe_send(PipeSide *pipe, const void *data, size_t length)
Sends data into the pipe.
Definition pipe.c:168
size_t pipe_receive(PipeSide *pipe, void *data, size_t length)
Receives data from the pipe.
Definition pipe.c:151
void pipe_free(PipeSide *pipe)
Frees a side of a pipe.
Definition pipe.c:99
void(* PipeSideDataArrivedCallback)(PipeSide *pipe, void *context)
Callback for when data arrives to a PipeSide.
Definition pipe.h:249
Definition pipe.h:52
There are two PipeSides per pipe.
Definition pipe.c:22
Definition pipe.h:57