00001
#ifndef ERIS_TIMEOUT_H
00002
#define ERIS_TIMEOUT_H
00003
00004
#include <Eris/Timestamp.h>
00005
00006
#include <sigc++/object.h>
00007
#include <sigc++/signal.h>
00008
00009
#include <map>
00010
#include <string>
00011
00012
namespace Eris {
00013
00015 class Timeout :
virtual public SigC::Object
00016 {
00017
public:
00018
00022
Timeout(
const std::string &label,
unsigned long milli);
00027
Timeout(
const std::string &label,
void* inst,
unsigned long milli);
00028 ~
Timeout();
00029
00031
Timeout&
operator=(
const Timeout &t);
00032
00036
void extend(
unsigned long msec);
00037
00040
void reset(
unsigned long msec);
00041
00043
void cancel();
00044
unsigned long poll(
const Time::Stamp &t);
00045
00047
bool isExpired()
const;
00048
00050 SigC::Signal0<void>
Expired;
00051
00053
00057
static const Timeout*
findByName(
const std::string &lbl,
void* inst = 0);
00058
00063
static unsigned long pollAll();
00064
00067 static void extendByName(
const std::string &lbl,
unsigned long msec)
00068 {extendByName(lbl, 0, msec);}
00069
static void extendByName(
const std::string &lbl,
void* inst,
unsigned long msec);
00070
00073
static void cancelByName(
const std::string &lbl,
void* inst = 0);
00074
00075
protected:
00077
00084 class Label {
00085
public:
00086
Label(
const std::string &s,
void* p = 0) : _s(s), _p(p) {}
00087
00088
Label(
const char* s,
void* p = 0) : _s(s), _p(p) {}
00089
00090
00091
00092
00093
bool operator==(
const Label& l)
const
00094
{
return _p == l.
_p && _s == l.
_s;}
00095
bool operator<(
const Label& l)
const
00096
{
return _p < l.
_p || (_p == l.
_p && _s < l.
_s);}
00097
00098
const std::string& getString()
const {
return _s;}
00099
00100
private:
00101 std::string _s;
00102
void* _p;
00103 };
00104
00105 const Label _label;
00106 Time::Stamp
_due;
00107 bool _fired;
00108
00109
typedef std::map<Label, Timeout*> TimeoutMap;
00110
static TimeoutMap _allTimeouts;
00111
00112
private:
00115
Timeout(
const Timeout &t);
00116 };
00117
00118 }
00119
00120
#endif