1 /* 2 * Copyright (C) 2011 Stefan Sayer 3 * 4 * This file is part of SEMS, a free SIP media server. 5 * 6 * SEMS is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * For a license to use the SEMS software under conditions 12 * other than those described here, or to purchase support for this 13 * software, please contact iptel.org by e-mail at the following addresses: 14 * info@iptel.org 15 * 16 * SEMS is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #ifndef _AmEventProcessingThread_h_ 27 #define _AmEventProcessingThread_h_ 28 29 #include "AmThread.h" 30 #include "AmEventQueue.h" 31 #include "AmEvent.h" 32 33 34 /** 35 AmEventProcessingThread processes events posted 36 in the event queue until either server shutdown 37 is signaled or processing is requested to stop 38 with the stop_processing function. 39 40 Override the onEvent(AmEvent* ev) method, create 41 an object, start() it and post events to it. 42 43 If you need queue policing (e.g. overflow protection), 44 override police_event() function. 45 */ 46 47 class AmEventProcessingThread 48 : public AmThread, 49 public AmEventQueue, 50 public AmEventHandler 51 { 52 53 bool processing_events; 54 55 void process(AmEvent* ev); 56 57 protected: 58 void run(); 59 void on_stop(); 60 onEvent(AmEvent * ev)61 virtual void onEvent(AmEvent* ev) { } 62 63 virtual bool police_event(AmEvent* ev); 64 65 public: 66 AmEventProcessingThread(); 67 ~AmEventProcessingThread(); 68 69 void postEvent(AmEvent* ev); 70 71 void stop_processing(); 72 73 }; 74 75 #endif 76