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 00021 #include "DTNServer.h" 00022 #include "SimEvent.h" 00023 #include "SimEventHandler.h" 00024 #include "storage/DTNStorageConfig.h" 00025 00026 namespace dtnsim { 00027 00031 class Simulator : public DTNServer, public SimEventHandler { 00032 public: 00036 static Simulator* instance() { 00037 if (instance_ == NULL) { 00038 PANIC("Simulator::init not called yet"); 00039 } 00040 return instance_; 00041 } 00042 00046 static void init(Simulator* instance) { 00047 if (instance_ != NULL) { 00048 PANIC("Simulator::init called multiple times"); 00049 } 00050 instance_ = instance; 00051 } 00052 00053 static double time() { return time_; } 00054 00058 Simulator(DTNStorageConfig* storage_config); 00059 00063 virtual ~Simulator() {} 00064 00068 static void post(SimEvent *e); 00069 00073 void exit(); 00074 00078 void run(); 00079 00080 static double runtill_; 00081 00082 protected: 00083 static Simulator* instance_; 00084 void process(SimEvent* e); 00085 00086 private: 00087 00088 static double time_; 00089 00090 bool is_running_; 00091 00092 00093 00094 std::priority_queue<SimEvent*, 00095 std::vector<SimEvent*>, 00096 SimEventCompare> eventq_; 00097 00098 oasys::DurableStore* store_; 00099 }; 00100 00101 } // namespace dtnsim 00102