Scheduler Class Reference

#include <Scheduler.h>

List of all members.

Public Member Functions

 Scheduler ()
 ~Scheduler ()
void schedule (double deltaT, ScheduledEvent *event)
void start ()
void stop ()
bool running ()
void clear ()
GPStime elapsed_time () const
void setLog (std::ostream &out)
void endLogging ()
void printOn (std::ostream &out) const

Static Public Member Functions

static Schedulerinstance ()

Private Attributes

GPStime m_time
bool m_running
std::ostreamm_log

Static Private Attributes

static Schedulers_instance = 0


Detailed Description

Definition at line 33 of file Scheduler.h.


Constructor & Destructor Documentation

Scheduler::Scheduler (  ) 

Definition at line 11 of file Scheduler.cxx.

References s_instance.

Referenced by instance().

00012 : m_time(GPStime(0))
00013 , m_running(false)
00014 , m_log(0)
00015 {
00016     assert( s_instance==0);  // require only one
00017     s_instance = this;
00018 }

Scheduler::~Scheduler (  ) 

Definition at line 20 of file Scheduler.cxx.

References clear().

00021 {
00022     clear();
00023 }


Member Function Documentation

void Scheduler::clear (  ) 

Definition at line 24 of file Scheduler.cxx.

References m_time.

Referenced by ~Scheduler().

00025 {
00026     while( ! empty() ) {
00027         iterator f = begin();
00028         delete (*f).second;
00029         erase(f);
00030     }
00031     m_time = 0;
00032 }

GPStime Scheduler::elapsed_time (  )  const [inline]

Definition at line 61 of file Scheduler.h.

References m_time.

Referenced by printOn(), and setLog().

00061 {return m_time;}

void Scheduler::endLogging (  ) 

Definition at line 86 of file Scheduler.cxx.

References m_log.

00087 {
00088     m_log = 0;
00089 }

Scheduler * Scheduler::instance (  )  [static]

Definition at line 9 of file Scheduler.cxx.

References s_instance, and Scheduler().

Referenced by ScheduledEvent::schedule().

00009 {return (s_instance) ? s_instance : new Scheduler();}

void Scheduler::printOn ( std::ostream out  )  const

Definition at line 66 of file Scheduler.cxx.

References elapsed_time(), and deljobs::end.

00067 {
00068     out << "\nScheduler stack: current time = " << elapsed_time() << std::endl;
00069     out << "\ttime\tclass name\n";
00070     for( const_iterator it= begin(); it !=end(); ++it){
00071         std::pair<double, ScheduledEvent*> entry = *it;
00072         out << "\t" << entry.first << '\t' << entry.second->name() << std::endl ;
00073     }
00074     out << std::endl;
00075 
00076 }

bool Scheduler::running (  )  [inline]

Definition at line 55 of file Scheduler.h.

References m_running.

00055 {return m_running;}

void Scheduler::schedule ( double  deltaT,
ScheduledEvent event 
)

Definition at line 35 of file Scheduler.cxx.

References m_time.

Referenced by ScheduledEvent::schedule().

00036 {
00037     insert(std::make_pair(m_time+deltaT, event));
00038 }

void Scheduler::setLog ( std::ostream out  ) 

Definition at line 78 of file Scheduler.cxx.

References elapsed_time(), and m_log.

00079 {
00080     m_log = &out;
00081     out << "\nSchedule event: current time = " << elapsed_time() << std::endl;
00082     out << "\ttime\tEvent\n";
00083 
00084 }

void Scheduler::start (  ) 

Definition at line 40 of file Scheduler.cxx.

References m_log, m_running, and m_time.

00041 {
00042     m_running = true;
00043 
00044     while( !empty() && m_running ) {
00045 
00046         // get the entry at the head of the queue
00047         std::pair<double, ScheduledEvent*> entry = *begin();
00048 
00049         // set current time, remove the entry
00050         m_time = entry.first;
00051         erase(begin());
00052 
00053         // run, then delete it
00054         if( m_log ) {
00055             (*m_log) << "\t" << entry.first << '\t' << entry.second->name() << std::endl ;
00056         }
00057         entry.second->execute();
00058         delete entry.second;
00059     }
00060 }

void Scheduler::stop (  ) 

Definition at line 62 of file Scheduler.cxx.

References m_running.

00063 {
00064     m_running = false;
00065 }


Member Data Documentation

std::ostream* Scheduler::m_log [private]

Definition at line 78 of file Scheduler.h.

Referenced by endLogging(), setLog(), and start().

bool Scheduler::m_running [private]

Definition at line 77 of file Scheduler.h.

Referenced by running(), start(), and stop().

GPStime Scheduler::m_time [private]

Definition at line 76 of file Scheduler.h.

Referenced by clear(), elapsed_time(), schedule(), and start().

Scheduler * Scheduler::s_instance = 0 [static, private]

Definition at line 75 of file Scheduler.h.

Referenced by instance(), and Scheduler().


Generated on Tue Nov 29 23:35:53 2016 for BOSS_7.0.2 by  doxygen 1.4.7