c++ twoprocesses.cc -o twoprocesses -I$prefix/include -L$prefix/lib -lssim
00001 // 00002 // twoprocesses.cc 00003 // 00004 #include <string> 00005 #include <iostream> 00006 00007 #include <siena/ssim.h> 00008 00009 using namespace std; 00010 using namespace ssim; 00011 00012 // 00013 // this is a simple iterative process 00014 // 00015 class Client: public Process { 00016 int iterations; 00017 int interval; 00018 string name; 00019 public: 00020 Client(const string &n, int i, int delta): 00021 iterations(i), interval(delta), name(n) {}; 00022 00023 virtual void init(void); 00024 virtual void process_event(const Event *); 00025 }; 00026 00027 void Client::init() { 00028 // 00029 // we start immediately by giving ourselves an immediate "timeout" 00030 // 00031 Sim::self_signal_event(NULL, 0); 00032 } 00033 00034 void Client::process_event(const Event * e) { 00035 if (e != 0) { 00036 cerr << "Client: sorry, I have not been programmed to handle events" 00037 << "only \"timeouts\", please." << endl; 00038 return; 00039 } 00040 cout << "I am " << name << ", the time is " << Sim::clock(); 00041 if (iterations > 0) { 00042 cout << ", " << iterations << " to go!"; 00043 --iterations; 00044 Sim::self_signal_event(NULL, interval); 00045 } else { 00046 cout << ", no more iteration. Bye!"; 00047 } 00048 cout << endl; 00049 } 00050 00051 int main(int argc, char *argv[]) { 00052 00053 Client c1("Yanyan", 10,100); 00054 Client c2("Antonio", 30,50); 00055 00056 Sim::create_process(&c1); 00057 Sim::create_process(&c2); 00058 00059 Sim::run_simulation(); 00060 00061 return 0; 00062 } 00063 00064