#include <string>
#include <iostream>
#include <siena/ssim.h>
using namespace std;
using namespace ssim;
class Client: public Process {
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;
}