Blame src/Timer.h

Packit 8f70b4
/*
Packit 8f70b4
 * lftp - file transfer program
Packit 8f70b4
 *
Packit 8f70b4
 * Copyright (c) 1996-2013 by Alexander V. Lukyanov (lav@yars.free.net)
Packit 8f70b4
 *
Packit 8f70b4
 * This program is free software; you can redistribute it and/or modify
Packit 8f70b4
 * it under the terms of the GNU General Public License as published by
Packit 8f70b4
 * the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
 * (at your option) any later version.
Packit 8f70b4
 *
Packit 8f70b4
 * This program is distributed in the hope that it will be useful,
Packit 8f70b4
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
 * GNU General Public License for more details.
Packit 8f70b4
 *
Packit 8f70b4
 * You should have received a copy of the GNU General Public License
Packit 8f70b4
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 8f70b4
 */
Packit 8f70b4
Packit 8f70b4
#ifndef TIMER_H
Packit 8f70b4
#define TIMER_H
Packit 8f70b4
Packit 8f70b4
#include "SMTask.h"
Packit 8f70b4
#include "ResMgr.h"
Packit 8f70b4
#include "xlist.h"
Packit 8f70b4
#include "xheap.h"
Packit 8f70b4
Packit 8f70b4
class Timer
Packit 8f70b4
{
Packit 8f70b4
   Time start;
Packit 8f70b4
   Time stop;
Packit 8f70b4
   TimeInterval last_setting;
Packit 8f70b4
   double random_max;
Packit 8f70b4
   xstring_c resource;
Packit 8f70b4
   xstring_c closure;
Packit 8f70b4
Packit 8f70b4
   static int infty_count;
Packit 8f70b4
   static xlist_head<Timer> all_timers;
Packit 8f70b4
   xlist<Timer> all_timers_node;
Packit 8f70b4
   static xheap<Timer> running_timers;
Packit 8f70b4
   xheap<Timer>::node running_timers_node;
Packit 8f70b4
Packit 8f70b4
   void re_sort();
Packit 8f70b4
   void re_set();
Packit 8f70b4
   void add_random();
Packit 8f70b4
   void set_last_setting(const TimeInterval &);
Packit 8f70b4
   void init();
Packit 8f70b4
   void reconfig(const char *);
Packit 8f70b4
Packit 8f70b4
public:
Packit 8f70b4
   Timer();
Packit 8f70b4
   ~Timer();
Packit 8f70b4
   Timer(int s,int ms=0);
Packit 8f70b4
   Timer(const TimeInterval &);
Packit 8f70b4
   Timer(const char *,const char *);
Packit 8f70b4
   bool Stopped() const;
Packit 8f70b4
   void Stop() { stop=SMTask::now; re_sort(); }
Packit 8f70b4
   void Set(const TimeInterval&);
Packit 8f70b4
   void Set(time_t s,int ms=0) { Set(TimeInterval(s,ms)); }
Packit 8f70b4
   void SetMilliSeconds(int ms) { Set(TimeInterval(0,ms)); }
Packit 8f70b4
   void SetMicroSeconds(int us) { Set(TimeInterval(0,0,us)); }
Packit 8f70b4
   void SetResource(const char *,const char *);
Packit 8f70b4
   void AddRandom(double r);
Packit 8f70b4
   void Reset(const Time &t);
Packit 8f70b4
   void Reset() { Reset(SMTask::now); }
Packit 8f70b4
   void Reset(const Timer &t) { Reset(t.GetStartTime()); }
Packit 8f70b4
   void ResetDelayed(int s);
Packit 8f70b4
   void StopDelayed(int s);
Packit 8f70b4
   const TimeInterval& GetLastSetting() const { return last_setting; }
Packit 8f70b4
   TimeDiff TimePassed() const { return SMTask::now-start; }
Packit 8f70b4
   TimeInterval TimeLeft() const;
Packit 8f70b4
   bool IsInfty() const { return last_setting.IsInfty(); }
Packit 8f70b4
   const Time &GetStartTime() const { return start; }
Packit 8f70b4
   static timeval GetTimeoutTV();
Packit 8f70b4
   static void ReconfigAll(const char *);
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
bool operator<(const Timer& a,const Timer& b);
Packit 8f70b4
Packit 8f70b4
#endif