#include <Simulator.h>
This defines the main event loop
Definition at line 30 of file Simulator.h.
Public Member Functions | |
Simulator () | |
Constructor. | |
virtual | ~Simulator () |
Destructor. | |
void | exit () |
Stops simulation and exits the loop. | |
void | run () |
Main run loop. | |
int | run_node_events () |
Handle all bundle events at nodes returning the amount of time (in ms) until the next timer is due. | |
void | pause () |
Pause execution of the simulator, running a console loop until it exits. | |
void | run_console (bool complete) |
Run the command loop. | |
void | set_exit_event (SimAtEvent *event) |
Register a command to run at exit. | |
Static Public Member Functions | |
static double | time () |
Return the current simulator time. | |
static void | post (SimEvent *e) |
Add an event to the main event queue. | |
Static Public Attributes | |
static double | runtill_ = -1 |
time to end the simulation | |
Private Member Functions | |
void | process (SimEvent *e) |
Virtual from SimEventHandler. | |
void | log_inqueue_stats () |
void | run_at_event (SimAtEvent *evt) |
void | check_interrupt () |
Static Private Member Functions | |
static void | handle_interrupt (int sig) |
Private Attributes | |
std::priority_queue< SimEvent *, std::vector< SimEvent * > , SimEventCompare > | eventq_ |
SimAtEvent * | exit_event_ |
Static Private Attributes | |
static double | time_ = 0 |
current time (static to avoid object) | |
static bool | interrupted_ = false |
dtnsim::Simulator::Simulator | ( | ) |
virtual dtnsim::Simulator::~Simulator | ( | ) | [inline, virtual] |
static double dtnsim::Simulator::time | ( | ) | [inline, static] |
Return the current simulator time.
Definition at line 38 of file Simulator.h.
References time_.
Referenced by dtnsim::gettimeofday(), dtnsim::SimLog::log_entry(), and dtnsim::SimLink::start_next_bundle().
void dtnsim::Simulator::post | ( | SimEvent * | e | ) | [static] |
Add an event to the main event queue.
Definition at line 52 of file Simulator.cc.
Referenced by dtnsim::SimCommand::exec().
void dtnsim::Simulator::exit | ( | ) |
void dtnsim::Simulator::run | ( | ) |
Main run loop.
Definition at line 131 of file Simulator.cc.
References ASSERT, check_interrupt(), eventq_, exit_event_, handle_interrupt(), dtnsim::SimEvent::handler(), dtnsim::SimEvent::is_valid(), dtn::log, log_inqueue_stats(), dtnsim::Topology::node_table(), dtnsim::SimEventHandler::process(), run_at_event(), run_node_events(), runtill_, dtnsim::SimEvent::time(), time_, and dtnsim::SimEvent::type_str().
int dtnsim::Simulator::run_node_events | ( | ) |
Handle all bundle events at nodes returning the amount of time (in ms) until the next timer is due.
Definition at line 66 of file Simulator.cc.
References check_interrupt(), dtnsim::Node::name(), dtnsim::Topology::node_table(), dtnsim::Node::process_one_bundle_event(), and dtnsim::Node::set_active().
Referenced by run().
void dtnsim::Simulator::pause | ( | ) |
Pause execution of the simulator, running a console loop until it exits.
Definition at line 210 of file Simulator.cc.
References run_console(), and time_.
Referenced by run_at_event().
void dtnsim::Simulator::run_console | ( | bool | complete | ) |
Run the command loop.
Definition at line 221 of file Simulator.cc.
References dtnsim::Node::active_node(), interrupted_, and dtnsim::Node::set_active().
Referenced by check_interrupt(), and pause().
void dtnsim::Simulator::set_exit_event | ( | SimAtEvent * | event | ) |
Register a command to run at exit.
Definition at line 300 of file Simulator.cc.
References exit_event_.
void dtnsim::Simulator::process | ( | SimEvent * | e | ) | [private, virtual] |
Virtual from SimEventHandler.
Implements dtnsim::SimEventHandler.
Definition at line 286 of file Simulator.cc.
References run_at_event(), dtnsim::SIM_AT_EVENT, and dtnsim::SimEvent::type().
void dtnsim::Simulator::log_inqueue_stats | ( | ) | [private] |
Definition at line 108 of file Simulator.cc.
References dtn::BundleList::begin(), dtn::BundleList::end(), dtn::BundleList::lock(), dtnsim::Topology::node_table(), and dtn::BundleDaemon::pending_bundles().
Referenced by run().
void dtnsim::Simulator::run_at_event | ( | SimAtEvent * | evt | ) | [private] |
Definition at line 308 of file Simulator.cc.
References dtnsim::SimAtEvent::objc_, dtnsim::SimAtEvent::objv_, and pause().
void dtnsim::Simulator::handle_interrupt | ( | int | sig | ) | [static, private] |
void dtnsim::Simulator::check_interrupt | ( | ) | [private] |
Definition at line 254 of file Simulator.cc.
References interrupted_, run_console(), and time_.
Referenced by run(), and run_node_events().
double dtnsim::Simulator::runtill_ = -1 [static] |
time to end the simulation
Definition at line 87 of file Simulator.h.
Referenced by run(), and dtnsim::SimCommand::SimCommand().
double dtnsim::Simulator::time_ = 0 [static, private] |
current time (static to avoid object)
Definition at line 97 of file Simulator.h.
Referenced by check_interrupt(), pause(), run(), and time().
std::priority_queue<SimEvent*, std::vector<SimEvent*>, SimEventCompare> dtnsim::Simulator::eventq_ [private] |
SimAtEvent* dtnsim::Simulator::exit_event_ [private] |
bool dtnsim::Simulator::interrupted_ = false [static, private] |
Definition at line 112 of file Simulator.h.
Referenced by check_interrupt(), handle_interrupt(), and run_console().