This is an example of how to program a simple simulation with two very simple iterative processes. To compile this example on a GNU/Linux system or on other Unix-like systems, assuming SSim has been installed in $prefix, execute:
c++ twoprocesses.cc -o twoprocesses -I$prefix/include -L$prefix/lib -lssim
#include <string>
#include <iostream>
using namespace std;
using namespace ssim;
int iterations;
int interval;
string name;
public:
Client(const string &n, int i, int delta):
iterations(i), interval(delta), name(n) {};
virtual void init(void);
virtual void process_event(
const Event *);
};
void Client::init() {
Sim::self_signal_event(NULL, 0);
}
void Client::process_event(
const Event * e) {
if (e != 0) {
cerr << "Client: sorry, I have not been programmed to handle events"
<< "only \"timeouts\", please." << endl;
return;
}
cout << "I am " << name << ", the time is " << Sim::clock();
if (iterations > 0) {
cout << ", " << iterations << " to go!";
--iterations;
Sim::self_signal_event(NULL, interval);
} else {
cout << ", no more iteration. Bye!";
}
cout << endl;
}
int main(int argc, char *argv[]) {
Client c1("Yanyan", 10,100);
Client c2("Antonio", 30,50);
Sim::create_process(&c1);
Sim::create_process(&c2);
Sim::run_simulation();
return 0;
}