1 /* 2 * Copyright (C) 2012 Frafos GmbH 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. This program is released under 10 * the GPL with the additional exemption that compiling, linking, 11 * and/or using OpenSSL is allowed. 12 * 13 * For a license to use the SEMS software under conditions 14 * other than those described here, or to purchase support for this 15 * software, please contact iptel.org by e-mail at the following addresses: 16 * info@iptel.org 17 * 18 * SEMS is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 */ 27 /** @file AmPeriodicThread.h */ 28 #ifndef _AmPeriodicThread_h_ 29 #define _AmPeriodicThread_h_ 30 31 #include "AmThread.h" 32 33 class AmPeriodicThread: public AmThread 34 { 35 protected: AmPeriodicThread()36 AmPeriodicThread() {} ~AmPeriodicThread()37 virtual ~AmPeriodicThread() {} 38 39 /* 40 * Start the infinite loop. The loop will 41 * do its best to execute looping_step() at regular 42 * intervals defined by 'tick'. The time spent in looping_step() 43 * is subtracted from the 'tick' to calculate the next execution 44 * time. 45 * 46 * @param tick execution time interval. 47 * @param max_ticks_behind maximum forward clock drift in ticks. 48 * @param usr_data pointer that will be passed to looping_step(). 49 */ 50 void infinite_loop(struct timeval* tick, 51 unsigned int max_ticks_behind, 52 void* usr_data); 53 54 /* 55 * This method is executed periodically by 56 * infinite loop. 57 * @return true to continue the loop, false to stop it. 58 */ 59 virtual bool looping_step(void* usr_data)=0; 60 }; 61 62 #endif 63