rbstream.h (2834B)
1 /* 2 * libdivecomputer 3 * 4 * Copyright (C) 2016 Jef Driesen 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301 USA 20 */ 21 22 #ifndef DC_RBSTREAM_H 23 #define DC_RBSTREAM_H 24 25 #include <libdivecomputer/device.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif /* __cplusplus */ 30 31 /** 32 * Opaque object representing a ringbuffer stream. 33 */ 34 typedef struct dc_rbstream_t dc_rbstream_t; 35 36 /** 37 * The ringbuffer read direction. 38 */ 39 typedef enum dc_rbstream_direction_t { 40 DC_RBSTREAM_FORWARD, 41 DC_RBSTREAM_BACKWARD 42 } dc_rbstream_direction_t; 43 44 /** 45 * Create a new ringbuffer stream. 46 * 47 * @param[out] rbstream A location to store the ringbuffer stream. 48 * @param[in] device A valid device object. 49 * @param[in] pagesize The page size in bytes. 50 * @param[in] packetsize The packet size in bytes. 51 * @param[in] begin The ringbuffer begin address. 52 * @param[in] end The ringbuffer end address. 53 * @param[in] address The stream start address. 54 * @param[in] direction The ringbuffer read direction. 55 * @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code 56 * on failure. 57 */ 58 dc_status_t 59 dc_rbstream_new (dc_rbstream_t **rbstream, dc_device_t *device, unsigned int pagesize, unsigned int packetsize, unsigned int begin, unsigned int end, unsigned int address, dc_rbstream_direction_t direction); 60 61 /** 62 * Read data from the ringbuffer stream. 63 * 64 * @param[in] rbstream A valid ringbuffer stream. 65 * @param[in] progress An (optional) progress event structure. 66 * @param[out] data The memory buffer to read the data into. 67 * @param[in] size The number of bytes to read. 68 * @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code 69 * on failure. 70 */ 71 dc_status_t 72 dc_rbstream_read (dc_rbstream_t *rbstream, dc_event_progress_t *progress, unsigned char data[], unsigned int size); 73 74 /** 75 * Destroy the ringbuffer stream. 76 * 77 * @param[in] rbstream A valid ringbuffer stream. 78 * @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code 79 * on failure. 80 */ 81 dc_status_t 82 dc_rbstream_free (dc_rbstream_t *rbstream); 83 84 #ifdef __cplusplus 85 } 86 #endif /* __cplusplus */ 87 #endif /* DC_RBSTREAM_H */