custom.h (2690B)
1 /* 2 * libdivecomputer 3 * 4 * Copyright (C) 2017 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_CUSTOM_H 23 #define DC_CUSTOM_H 24 25 #include "common.h" 26 #include "context.h" 27 #include "iostream.h" 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif /* __cplusplus */ 32 33 typedef struct dc_custom_cbs_t { 34 dc_status_t (*set_timeout) (void *userdata, int timeout); 35 dc_status_t (*set_break) (void *userdata, unsigned int value); 36 dc_status_t (*set_dtr) (void *userdata, unsigned int value); 37 dc_status_t (*set_rts) (void *userdata, unsigned int value); 38 dc_status_t (*get_lines) (void *userdata, unsigned int *value); 39 dc_status_t (*get_available) (void *userdata, size_t *value); 40 dc_status_t (*configure) (void *userdata, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol); 41 dc_status_t (*poll) (void *userdata, int timeout); 42 dc_status_t (*read) (void *userdata, void *data, size_t size, size_t *actual); 43 dc_status_t (*write) (void *userdata, const void *data, size_t size, size_t *actual); 44 dc_status_t (*ioctl) (void *userdata, unsigned int request, void *data, size_t size); 45 dc_status_t (*flush) (void *userdata); 46 dc_status_t (*purge) (void *userdata, dc_direction_t direction); 47 dc_status_t (*sleep) (void *userdata, unsigned int milliseconds); 48 dc_status_t (*close) (void *userdata); 49 } dc_custom_cbs_t; 50 51 /** 52 * Create a custom I/O stream. 53 * 54 * @param[out] iostream A location to store the custom I/O stream. 55 * @param[in] context A valid context object. 56 * @param[in] callbacks The callback functions to call. 57 * @param[in] userdata User data to pass to the callback functions. 58 * @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code 59 * on failure. 60 */ 61 dc_status_t 62 dc_custom_open (dc_iostream_t **iostream, dc_context_t *context, dc_transport_t transport, const dc_custom_cbs_t *callbacks, void *userdata); 63 64 #ifdef __cplusplus 65 } 66 #endif /* __cplusplus */ 67 #endif /* DC_CUSTOM_H */