SSim C++ API documentation (v. 1.3.2)

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Examples  

twoprocesses.cc

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>

#include <ssim/ssim.h>

using namespace ssim;

//
// this is a simple iterative process
//
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_timeout();
};

void Client::init() { 
    Sim::set_timeout(0); // we start immediately
}

void Client::process_timeout() { 
    cout << "I am " << name << ", the time is " << Sim::clock();
    if (iterations > 0) {
        cout << ", " << iterations << " to go!";
        --iterations;
        Sim::set_timeout(interval);
    } else {
        cout << ", no more iteration.  Bye!";
    }
    cout << endl;
}

int main(int argc, char *argv[]) {

    Client c1("Yan Yan", 10,100);
    Client c2("Antonio", 30,50);

    Sim::create_process(&c1);
    Sim::create_process(&c2);

    Sim::run_simulation();

    return 0;
}



Copyright © 2002 University of Colorado.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". This documentation is authored and maintained by Antonio Carzaniga