SSim C++ API documentation (v. 1.7.4)

tprocess.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) 2003-2005 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: tprocess.h,v 1.9 2005/11/01 09:40:28 carzanig Exp $
00028 //
00029 #ifndef _tprocess_h
00030 #define _tprocess_h
00031 
00032 #ifndef TPROCESS_IMPL
00033 #include "tprocessconf.h"
00034 #endif
00035 
00036 #if TPROCESS_IMPL != 0
00037 
00038 #if TPROCESS_IMPL==1
00039 #include <ucontext.h>
00040 #else
00041 #include <setjmp.h>
00042 #endif
00043 
00044 #include <siena/ssim.h>
00045 
00051 namespace ssim {
00052 
00068 class TProcess : public Process {
00069 public:
00074     TProcess();
00075 
00077     TProcess(unsigned long stacksize);
00078 
00079     virtual ~TProcess();
00080 
00090     virtual void main() = 0;
00091 
00097     static unsigned long DefaultStackSize;
00098 
00104     class Timeout : public Event { };
00105 
00148     static const Event * wait_for_event(Time timeout = INIT_TIME);
00149 
00150 private:
00151     virtual void init(void);
00152     virtual void process_event(const Event * msg);
00153     virtual void stop(void);
00154 
00155 #if TPROCESS_IMPL==1
00156     ucontext_t running_ctx;
00157 #else
00158     jmp_buf running_ctx; 
00159 #endif
00160     char * mystack;
00161     unsigned long mystack_size;
00162 
00163     const Event * ev;
00164 
00165 #if TPROCESS_IMPL==1
00166     static void starter();
00167 #else
00168     static void starter(int);
00169 #endif
00170     void pause();
00171     void resume();
00172 };
00173 
00174 }; // end namespace ssim
00175 
00176 #endif /* TPROCESS_IMPL!=VOID */
00177 
00178 #endif /* _ssim_h */
00179