SSim
C++ API documentation (v. 1.7.6)
Main Page
Namespaces
Classes
Files
Examples
File List
src
ssim
trunk
siena
ssim.h
Go to the documentation of this file.
1
// -*-C++-*-
2
//
3
// This file is part of SSim, a simple discrete-event simulator.
4
// See http://www.inf.usi.ch/carzaniga/ssim/
5
//
6
// Copyright (C) 1998-2004 University of Colorado
7
// Copyright (C) 2012 Antonio Carzaniga
8
//
9
// Authors: Antonio Carzaniga <
[email protected]
>
10
// See AUTHORS for full details.
11
//
12
// SSim is free software: you can redistribute it and/or modify it under
13
// the terms of the GNU General Public License as published by the Free
14
// Software Foundation, either version 3 of the License, or (at your
15
// option) any later version.
16
//
17
// SSim is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
// GNU General Public License for more details.
21
//
22
// You should have received a copy of the GNU General Public License
23
// along with SSim. If not, see <http://www.gnu.org/licenses/>.
24
//
25
#ifndef _ssim_h
26
#define _ssim_h
27
48
namespace
ssim {
49
52
extern
const
char
*
Version
;
53
56
typedef
int
ProcessId
;
57
60
const
ProcessId
NULL_PROCESSID
= -1;
61
76
typedef
double
Time
;
77
80
const
Time
INIT_TIME
= 0;
81
108
class
Event
{
109
public
:
110
Event
(): refcount(0) {};
111
virtual
~
Event
() {};
112
113
private
:
114
mutable
unsigned
refcount;
115
friend
class
SimImpl;
// this is an opaque implementation class
116
friend
class
Sim
;
// these need to be friends to manage refcount
117
};
118
124
class
Process
{
125
public
:
126
virtual
~
Process
() {};
127
136
virtual
void
init
(
void
) {};
137
192
virtual
void
process_event
(
const
Event
* msg) {};
193
201
virtual
void
stop
(
void
) {};
202
};
203
210
class
ProcessWithPId
:
public
Process
{
211
public
:
223
ProcessId
activate
()
throw
();
224
231
ProcessId
pid
()
const
throw
();
232
233
ProcessWithPId
()
throw
();
234
235
private
:
236
ProcessId
process_id;
237
};
238
249
class
SimErrorHandler
{
250
public
:
251
virtual
~
SimErrorHandler
() {}
252
261
virtual
void
clear
() throw() {}
262
280
virtual
void
handle_busy
(
ProcessId
p,
const
Event
* e)
throw
() {}
281
299
virtual
void
handle_terminated
(
ProcessId
p,
const
Event
* e)
throw
() {}
300
};
301
324
class
Sim
{
325
public
:
338
static
ProcessId
create_process
(
Process
*)
throw
();
339
341
static
int
stop_process
(
ProcessId
)
throw
();
343
static
void
stop_process
()
throw
();
344
355
static
void
clear
()
throw
();
356
371
static
void
self_signal_event
(
const
Event
* e)
throw
();
372
389
static
void
self_signal_event
(
const
Event
* e,
Time
delay)
throw
();
390
410
static
void
signal_event
(
ProcessId
p,
const
Event
* e)
throw
();
411
433
static
void
signal_event
(
ProcessId
p,
const
Event
* e,
Time
d)
throw
();
434
512
static
void
advance_delay
(
Time
)
throw
();
513
535
static
ProcessId
this_process
()
throw
();
536
554
static
Time
clock
()
throw
();
555
557
static
void
run_simulation
();
559
static
void
stop_simulation
()
throw
();
560
573
static
void
set_stop_time
(
Time
t =
INIT_TIME
)
throw
();
574
582
static
void
set_error_handler
(
SimErrorHandler
*)
throw
();
583
};
584
585
}
// end namespace ssim
586
587
#endif
/* _ssim_h */
588