00001 // -*-C++-*- 00002 // 00003 // This file is part of SSim, a simple discrete-event simulator. 00004 // See http://www.cs.colorado.edu/serl/ssim/ 00005 // 00006 // Author: Antonio Carzaniga <carzanig@cs.colorado.edu> 00007 // See the file AUTHORS for full details. 00008 // 00009 // Copyright (C) 1998-2004 University of Colorado 00010 // 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of the GNU General Public License 00013 // as published by the Free Software Foundation; either version 2 00014 // of the License, or (at your option) any later version. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License 00022 // along with this program; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 00024 // USA, or send email to serl@cs.colorado.edu. 00025 // 00026 // 00027 // $Id: ssim.h,v 1.24 2005-12-13 09:50:03 carzanig Exp $ 00028 // 00029 #ifndef _ssim_h 00030 #define _ssim_h 00031 00052 namespace ssim { 00053 00056 extern const char * Version; 00057 00060 typedef int ProcessId; 00061 00064 const ProcessId NULL_PROCESSID = -1; 00065 00080 typedef double Time; 00081 00084 const Time INIT_TIME = 0; 00085 00112 class Event { 00113 public: 00114 Event(): refcount(0) {}; 00115 virtual ~Event() {}; 00116 00117 private: 00118 mutable unsigned refcount; 00119 friend class SimImpl; // this is an opaque implementation class 00120 friend class Sim; // these need to be friends to manage refcount 00121 }; 00122 00128 class Process { 00129 public: 00130 virtual ~Process() {}; 00131 00140 virtual void init(void) {}; 00141 00196 virtual void process_event(const Event * msg) {}; 00197 00205 virtual void stop(void) {}; 00206 }; 00207 00214 class ProcessWithPId : public Process { 00215 public: 00227 ProcessId activate() throw(); 00228 00235 ProcessId pid() const throw(); 00236 00237 ProcessWithPId() throw(); 00238 00239 private: 00240 ProcessId process_id; 00241 }; 00242 00253 class SimErrorHandler { 00254 public: 00255 virtual ~SimErrorHandler() {} 00256 00265 virtual void clear() throw() {} 00266 00284 virtual void handle_busy(ProcessId p, const Event * e) throw() {} 00285 00303 virtual void handle_terminated(ProcessId p, const Event * e) throw() {} 00304 }; 00305 00328 class Sim { 00329 public: 00342 static ProcessId create_process(Process *) throw(); 00343 00345 static int stop_process(ProcessId) throw(); 00347 static void stop_process() throw(); 00348 00359 static void clear() throw(); 00360 00375 static void self_signal_event(const Event * e) throw(); 00376 00393 static void self_signal_event(const Event * e, Time delay) throw(); 00394 00414 static void signal_event(ProcessId p, const Event * e) throw(); 00415 00437 static void signal_event(ProcessId p, const Event * e, Time d) throw(); 00438 00516 static void advance_delay(Time) throw(); 00517 00539 static ProcessId this_process() throw(); 00540 00558 static Time clock() throw(); 00559 00561 static void run_simulation(); 00563 static void stop_simulation() throw(); 00564 00577 static void set_stop_time(Time t = INIT_TIME) throw(); 00578 00586 static void set_error_handler(SimErrorHandler *) throw(); 00587 }; 00588 00589 } // end namespace ssim 00590 00591 #endif /* _ssim_h */ 00592