1 /* 2 * Copyright (C) 2019 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /* 39 * btstack_run_loop_base.h 40 * 41 * Portable implementation of timer and data source managment as base for platform specific implementations 42 */ 43 44 #ifndef BTSTACK_RUN_LOOP_BASE_H 45 #define BTSTACK_RUN_LOOP_BASE_H 46 47 #include "btstack_run_loop.h" 48 49 #include "btstack_linked_list.h" 50 51 #include <stdint.h> 52 53 #if defined __cplusplus 54 extern "C" { 55 #endif 56 57 // private data (access only by run loop implementations) 58 extern btstack_linked_list_t btstack_run_loop_base_timers; 59 extern btstack_linked_list_t btstack_run_loop_base_data_sources; 60 61 /** 62 * @brief Init 63 */ 64 void btstack_run_loop_base_init(void); 65 66 /** 67 * @brief Add timer source. 68 */ 69 void btstack_run_loop_base_add_timer(btstack_timer_source_t * timer); 70 71 /** 72 * @brief Remove timer source. 73 */ 74 int btstack_run_loop_base_remove_timer(btstack_timer_source_t * timer); 75 76 /** 77 * @brief Process timers: remove expired timers from list and call their process function 78 * @param now 79 */ 80 void btstack_run_loop_base_process_timers(uint32_t now); 81 82 /** 83 * @brief Get time until first timer fires 84 * @returns -1 if no timers, time until next timeout otherwise 85 */ 86 int32_t btstack_run_loop_base_get_time_until_timeout(uint32_t now); 87 88 /** 89 * @brief Add data source to run loop 90 * @param data_source to add 91 */ 92 void btstack_run_loop_base_add_data_source(btstack_data_source_t * data_source); 93 94 /** 95 * @brief Remove data source from run loop 96 * @param data_source to remove 97 */ 98 int btstack_run_loop_base_remove_data_source(btstack_data_source_t * data_source); 99 100 /** 101 * @brief Enable callbacks for a data source 102 * @param data_source to remove 103 * @param callback types to enable 104 */ 105 void btstack_run_loop_base_enable_data_source_callbacks(btstack_data_source_t * data_source, uint16_t callbacks); 106 107 /** 108 * @brief Enable callbacks for a data source 109 * @param data_source to remove 110 * @param callback types to disable 111 */ 112 void btstack_run_loop_base_disable_data_source_callbacks(btstack_data_source_t * data_source, uint16_t callbacks); 113 114 #if defined __cplusplus 115 } 116 #endif 117 118 #endif // BTSTACK_RUN_LOOP_BASE_H 119