Back to index

nordugrid-arc-nox  1.1.0~rc6
Counter.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 // Counter.h
00004 
00005 #ifndef __Counter__
00006 #define __Counter__
00007 
00008 #include <glibmm/timeval.h>
00009 
00010 namespace Arc {
00011 
00013   extern const Glib::TimeVal ETERNAL;
00014 
00016   extern const Glib::TimeVal HISTORIC;
00017 
00018 
00019 
00020   // Some forward declarations.
00021   class Counter;
00022   class CounterTicket;
00023   class ExpirationReminder;
00024 
00025 
00026 
00028 
00103   class Counter {
00104 
00105   protected:
00106 
00108 
00114     typedef unsigned long long int IDType;
00115 
00117 
00123     Counter();
00124 
00125   public:
00126 
00128 
00132     virtual ~Counter();
00133 
00135 
00140     virtual int getLimit() = 0;
00141 
00143 
00147     virtual int setLimit(int newLimit) = 0;
00148 
00150 
00155     virtual int changeLimit(int amount) = 0;
00156 
00158 
00162     virtual int getExcess() = 0;
00163 
00165 
00169     virtual int setExcess(int newExcess) = 0;
00170 
00172 
00177     virtual int changeExcess(int amount) = 0;
00178 
00180 
00189     virtual int getValue() = 0;
00190 
00192 
00206     virtual CounterTicket reserve(int amount = 1,
00207                                   Glib::TimeVal duration = ETERNAL,
00208                                   bool prioritized = false,
00209                                   Glib::TimeVal timeOut = ETERNAL) = 0;
00210 
00211   protected:
00212 
00214 
00219     virtual void cancel(IDType reservationID) = 0;
00220 
00222 
00235     virtual void extend(IDType& reservationID,
00236                         Glib::TimeVal& expiryTime,
00237                         Glib::TimeVal duration = ETERNAL) = 0;
00238 
00240 
00244     Glib::TimeVal getCurrentTime();
00245 
00247 
00252     Glib::TimeVal getExpiryTime(Glib::TimeVal duration);
00253 
00255 
00272     CounterTicket getCounterTicket(Counter::IDType reservationID,
00273                                    Glib::TimeVal expiryTime,
00274                                    Counter *counter);
00275 
00277 
00292     ExpirationReminder getExpirationReminder(Glib::TimeVal expTime,
00293                                              Counter::IDType resID);
00294   private:
00295 
00297 
00301     Counter(const Counter& unique);
00302 
00304 
00309     void operator=(const Counter& unique);
00310 
00312     friend class CounterTicket;
00313 
00315     friend class ExpirationReminder;
00316 
00317   };
00318 
00319 
00320 
00322 
00343   class CounterTicket {
00344 
00345   public:
00346 
00348 
00353     CounterTicket();
00354 
00356 
00361     bool isValid();
00362 
00364 
00371     void extend(Glib::TimeVal duration);
00372 
00374 
00378     void cancel();
00379 
00380   private:
00381 
00383 
00394     CounterTicket(Counter::IDType reservationID,
00395                   Glib::TimeVal expiryTime,
00396                   Counter *counter);
00397 
00399     Counter::IDType reservationID;
00400 
00402     Glib::TimeVal expiryTime;
00403 
00405     Counter *counter;
00406 
00408     friend class Counter;
00409 
00410   };
00411 
00412 
00413 
00415 
00418   class ExpirationReminder {
00419 
00420   public:
00421 
00423 
00429     bool operator<(const ExpirationReminder& other) const;
00430 
00432 
00436     Glib::TimeVal getExpiryTime() const;
00437 
00439 
00444     Counter::IDType getReservationID() const;
00445 
00446   private:
00447 
00449 
00457     ExpirationReminder(Glib::TimeVal expiryTime,
00458                        Counter::IDType reservationID);
00459 
00461     Glib::TimeVal expiryTime;
00462 
00464     Counter::IDType reservationID;
00465 
00467     friend class Counter;
00468 
00469   };
00470 
00471 }
00472 
00473 #endif