ARC SDK
Counter.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 // Counter.h
4 
5 #ifndef __Counter__
6 #define __Counter__
7 
8 #include <glibmm/timeval.h>
9 
10 namespace Arc {
11 
13  extern const Glib::TimeVal ETERNAL;
14 
16  extern const Glib::TimeVal HISTORIC;
17 
18 
19 
20  // Some forward declarations.
21  class Counter;
22  class CounterTicket;
23  class ExpirationReminder;
24 
25 
26 
28 
105  class Counter {
106 
107  protected:
108 
110 
116  typedef unsigned long long int IDType;
117 
119 
125  Counter();
126 
127  public:
128 
130 
134  virtual ~Counter();
135 
137 
142  virtual int getLimit() = 0;
143 
145 
149  virtual int setLimit(int newLimit) = 0;
150 
152 
157  virtual int changeLimit(int amount) = 0;
158 
160 
164  virtual int getExcess() = 0;
165 
167 
171  virtual int setExcess(int newExcess) = 0;
172 
174 
179  virtual int changeExcess(int amount) = 0;
180 
182 
191  virtual int getValue() = 0;
192 
194 
208  virtual CounterTicket reserve(int amount = 1,
209  Glib::TimeVal duration = ETERNAL,
210  bool prioritized = false,
211  Glib::TimeVal timeOut = ETERNAL) = 0;
212 
213  protected:
214 
216 
221  virtual void cancel(IDType reservationID) = 0;
222 
224 
237  virtual void extend(IDType& reservationID,
238  Glib::TimeVal& expiryTime,
239  Glib::TimeVal duration = ETERNAL) = 0;
240 
242 
246  Glib::TimeVal getCurrentTime();
247 
249 
254  Glib::TimeVal getExpiryTime(Glib::TimeVal duration);
255 
257 
275  Glib::TimeVal expiryTime,
276  Counter *counter);
277 
279 
294  ExpirationReminder getExpirationReminder(Glib::TimeVal expTime,
295  Counter::IDType resID);
296  private:
297 
299 
303  Counter(const Counter& unique);
304 
306 
311  void operator=(const Counter& unique);
312 
314  friend class CounterTicket;
315 
317  friend class ExpirationReminder;
318 
319  };
320 
321 
322 
324 
348 
349  public:
350 
352 
357  CounterTicket();
358 
360 
365  bool isValid();
366 
368 
375  void extend(Glib::TimeVal duration);
376 
378 
382  void cancel();
383 
384  private:
385 
387 
398  CounterTicket(Counter::IDType reservationID,
399  Glib::TimeVal expiryTime,
400  Counter *counter);
401 
403  Counter::IDType reservationID;
404 
406  Glib::TimeVal expiryTime;
407 
409  Counter *counter;
410 
412  friend class Counter;
413 
414  };
415 
416 
417 
419 
425 
426  public:
427 
429 
435  bool operator<(const ExpirationReminder& other) const;
436 
438 
442  Glib::TimeVal getExpiryTime() const;
443 
445 
451 
452  private:
453 
455 
463  ExpirationReminder(Glib::TimeVal expiryTime,
464  Counter::IDType reservationID);
465 
467  Glib::TimeVal expiryTime;
468 
470  Counter::IDType reservationID;
471 
473  friend class Counter;
474 
475  };
476 
477 }
478 
479 #endif
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
A class defining a common interface for counters.
Definition: Counter.h:105
bool isValid()
Returns the validity of a CounterTicket.
virtual ~Counter()
The destructor.
Glib::TimeVal getExpiryTime(Glib::TimeVal duration)
Computes an expiry time.
virtual int changeLimit(int amount)=0
Changes the limit of the counter.
virtual int changeExcess(int amount)=0
Changes the excess limit of the counter.
virtual int getValue()=0
Returns the current value of the counter.
ExpirationReminder getExpirationReminder(Glib::TimeVal expTime, Counter::IDType resID)
A "relay method" for the constructor of ExpirationReminder.
bool operator<(const ExpirationReminder &other) const
Less than operator, compares "soonness".
void cancel()
Cancels a reservation.
const Glib::TimeVal ETERNAL
A time very far in the future.
const Glib::TimeVal HISTORIC
A time very far in the past.
virtual int getExcess()=0
Returns the excess limit of the counter.
virtual void cancel(IDType reservationID)=0
Cancellation of a reservation.
Glib::TimeVal getExpiryTime() const
Returns the expiry time.
A class intended for internal use within counters.
Definition: Counter.h:424
A class for "tickets" that correspond to counter reservations.
Definition: Counter.h:347
Glib::TimeVal getCurrentTime()
Get the current time.
virtual int setExcess(int newExcess)=0
Sets the excess limit of the counter.
Counter::IDType getReservationID() const
Returns the identification number of the reservation.
virtual int setLimit(int newLimit)=0
Sets the limit of the counter.
unsigned long long int IDType
A typedef of identification numbers for reservation.
Definition: Counter.h:116
void extend(Glib::TimeVal duration)
Extends a reservation.
Counter()
Default constructor.
virtual CounterTicket reserve(int amount=1, Glib::TimeVal duration=ETERNAL, bool prioritized=false, Glib::TimeVal timeOut=ETERNAL)=0
Makes a reservation from the counter.
CounterTicket()
The default constructor.
virtual void extend(IDType &reservationID, Glib::TimeVal &expiryTime, Glib::TimeVal duration=ETERNAL)=0
Extension of a reservation.
CounterTicket getCounterTicket(Counter::IDType reservationID, Glib::TimeVal expiryTime, Counter *counter)
A "relay method" for a constructor of the CounterTicket class.
virtual int getLimit()=0
Returns the current limit of the counter.