SSim C++ API documentation (v. 1.7.0)
Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Examples

ssim.h

Go to the documentation of this file.
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.22 2005/01/06 10:34:54 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 unsigned long   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 
00251 class SimErrorHandler {
00252 public:
00261     virtual void clear() throw() {}
00262 
00272     virtual void handle_busy(ProcessId p, const Event * e) throw() {}
00273 
00283     virtual void handle_terminated(ProcessId p, const Event * e) throw() {}
00284 };
00285 
00308 class Sim {
00309 public:
00319     static ProcessId    create_process(Process *) throw();
00320 
00322     static int          stop_process(ProcessId) throw();
00324     static void         stop_process() throw();
00325 
00336     static void         clear() throw();
00337 
00347     static void         self_signal_event(const Event *) throw();
00348 
00357     static void         self_signal_event(const Event *, Time delay) throw();
00358 
00368     static void         signal_event(ProcessId, const Event *) throw();
00377     static void         signal_event(ProcessId, const Event *, Time) throw();
00378 
00453     static void         advance_delay(Time) throw();
00454     
00476     static ProcessId    this_process() throw();
00477 
00495     static Time         clock() throw();
00496     
00498     static void         run_simulation();
00500     static void         stop_simulation() throw();
00501 
00514     static void         set_stop_time(Time t = INIT_TIME) throw();
00515 
00523     static void         set_error_handler(SimErrorHandler *) throw();
00524 };
00525 
00526 }; // end namespace ssim
00527 
00528 #endif /* _ssim_h */
00529