1 /* 2 * Generic event loop functionality. 3 * 4 * (c) 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program 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 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #ifdef __cplusplus 25 26 #include <pthread.h> 27 #include <pthread-l4.h> 28 29 /* Event loop abstraction. */ 30 31 class Event_loop 32 { 33 protected: 34 /* Private data for the handler. */ 35 36 void *_priv; 37 38 /* Thread properties. */ 39 40 int _priority; 41 pthread_t _pthread; 42 43 public: 44 /* Initialise the event loop with an event handler function and private data, 45 plus thread priority. */ 46 47 explicit Event_loop(void *priv, int priority=0x20) 48 : _priv(priv), _priority(priority) 49 { 50 } 51 52 /* Static main loop function for event-handling thread. */ 53 54 static void *event_loop(void *data); 55 56 /* Event handler method. */ 57 58 virtual void handle() = 0; 59 60 /* Initiation function. */ 61 62 virtual void start(); 63 }; 64 65 #endif