1 /* vim:tabstop=4:expandtab:shiftwidth=4 2 * 3 * Idesk -- Timer.h 4 * 5 * Copyright (c) 2005, FixXxeR (avelar@gmail.com) 6 * based from Timer.cc (vdesk project) by MrChuoi <mrchuoi at yahoo dot com> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are met: 11 * 12 * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * Neither the name of the <ORGANIZATION> nor the names of its 20 * contributors may be used to endorse or promote products derived from 21 * this software without specific prior written permission. 22 * 23 * (See the included file COPYING / BSD ) 24 */ 25 26 #ifndef TIMER_CLASS 27 #define TIMER_CLASS 28 29 #include <time.h> 30 #include "XDesktopContainer.h" 31 #include <fcntl.h> 32 33 class TimerControl { 34 private: 35 long start; 36 long delay; 37 public: SetDelay(long d)38 void SetDelay( long d ) { delay = d; start = time(0); } GetDelay(long n)39 long GetDelay( long n ) { return start + delay - n; } Finish()40 void Finish() { start = delay;} Reset()41 long Reset() { start = time(0); return delay; } 42 IsOneShot()43 virtual bool IsOneShot() { return true; } 44 virtual void OnTime() = 0; 45 }; 46 47 class Timer{ 48 private: 49 static vector<TimerControl*> items; 50 AbstractContainer * container; 51 int c; 52 public: 53 Timer(AbstractContainer * con); 54 void Update(); 55 public: 56 static void Add( TimerControl *t, long d ); 57 static void Remove( TimerControl *t ); 58 }; 59 60 #endif 61