James Kuszmaul | 28cc825 | 2021-01-17 11:32:21 -0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | #include "code.h" |
| 3 | #include <re.h> |
| 4 | |
| 5 | /// Handler for buffered messages. |
| 6 | /// |
| 7 | /// Return `true` if the message has been handled successfully and can |
| 8 | /// be unlinked, `false` to stop processing messages and keep the current |
| 9 | /// message in the list. |
| 10 | typedef bool(rawrtc_message_buffer_handler)( |
| 11 | struct mbuf* const buffer, void* const context, void* const arg); |
| 12 | |
| 13 | /// Create a message buffer and add it to a list. |
| 14 | enum rawrtc_code rawrtc_message_buffer_append( |
| 15 | struct list* const message_buffer, |
| 16 | struct mbuf* const buffer, // referenced |
| 17 | void* const context // referenced, nullable |
| 18 | ); |
| 19 | |
| 20 | /// Apply a receive handler to buffered messages. |
| 21 | /// |
| 22 | /// Will stop iterating and return `RAWRTC_CODE_STOP_ITERATION` in case |
| 23 | /// the message handler returned `false`. |
| 24 | enum rawrtc_code rawrtc_message_buffer_clear( |
| 25 | struct list* const message_buffer, |
| 26 | rawrtc_message_buffer_handler* const message_handler, |
| 27 | void* arg); |