00001 /* 00002 * Copyright 2004-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include <queue> 00018 #include <oasys/debug/DebugUtils.h> 00019 #include <oasys/debug/Log.h> 00020 #include <oasys/util/Singleton.h> 00021 00022 #include "SimEvent.h" 00023 #include "SimEventHandler.h" 00024 00025 namespace dtnsim { 00026 00030 class Simulator : public oasys::Singleton<Simulator, false>, 00031 public SimEventHandler, 00032 public oasys::Logger 00033 { 00034 public: 00038 static double time() { return time_; } 00039 00043 Simulator(); 00044 00048 virtual ~Simulator() {} 00049 00053 static void post(SimEvent *e); 00054 00058 void exit(); 00059 00063 void run(); 00064 00069 int run_node_events(); 00070 00075 void pause(); 00076 00080 void run_console(bool complete); 00081 00085 void set_exit_event(SimAtEvent* event); 00086 00087 static double runtill_; 00088 00089 private: 00093 void process(SimEvent* e); 00094 00095 void log_inqueue_stats(); 00096 00097 static double time_; 00098 00099 std::priority_queue<SimEvent*, 00100 std::vector<SimEvent*>, 00101 SimEventCompare> eventq_; 00102 00103 SimAtEvent* exit_event_; 00104 00105 void run_at_event(SimAtEvent* evt); 00106 00107 /* 00108 * Handlers for SIGINT to pause the simulation while it's running. 00109 */ 00110 static void handle_interrupt(int sig); 00111 void check_interrupt(); 00112 static bool interrupted_; 00113 }; 00114 00115 } // namespace dtnsim 00116