next up previous contents index
Next: Datahandlers Up: Base classes Previous: The class data

The class datahandler

The abstract class datahandler  forms the basis for all objects that influence the flow of information in some way. The time a datahandler needs to perform its action is specified by its distribution  and distribution-parameters.

interface datahandler
{
protected:
  datahandler();                                // constructor

public:
  virtual int accept(data* d);                  // do we accept the data
  virtual void pass(data* d);                   // offer d to next datahandler
  virtual void next(datahandler* dh);           // set next handler
  virtual datahandler* next();                  // get next handler
  virtual void previous(datahandler* dh);       // set previous handler
  virtual double duration();                    // get a duration 
  virtual void duration(double a, generator* g = NULL, 
                        distribution db = EXACT, double b = 0);
                                                // set duration
};

A datahandler should be created by means of the constructor, and be given a successor datahandler using the next member. The member next will call the member previous of the successor, so the successor has a way of knowing its precessor. This is mainly important with the class waitqueue. An object of class waitqueue  need to know whether it has one precessor -- so it is a regular queue -- or whether it has two precessors -- and it will function as a waitqueue. See also section 6.2.3.

A distribution according to which duration times are generated can be specified with the duration  member. Some examples of how to specify the duration:

// random number generator with seed 1
bpgenerator* g = new bpgenerator(1);

// duration allways 5.0, no generator needed
handler -> duration(5.0);      

// duration is normal distributed, mean 5.0, standard deviation 2.0
handler -> duration(5.0, g, NORMAL, 2.0);

// duration with poisson distribution, mean 5.0
handler -> duration(5.0, g, POISSON);

The distribution  type looks as follows:

enum distribution {EXACT, UNIFORM, EXPONENTIAL, LAPLACE, NORMAL, CHISQUARE, 
                   STUDENT, LOGNORMAL, ERLANG, GAMMA, BETA, FDISTRIBUTION, 
                   POISSON, GEOMETRIC, WEIBULL, BINOMIAL, NEGATIVEBINOMIAL, 
                   TRIANGULAR};

The datahandler receives data when the member function accept gets called by another datahandler. The function accept should return OK if the datahandler is able to handle the data, FALSE otherwise. Classes that are derived from datahandler should override this member if they do not allways accept the data, for instance when they have to acquire some resources. If the datahandler is able to accept the data it schedules an event to become active after a timeperiod, determined by duration. When that event gets activated it will pass the data to the next datahandler, using the datahandler-members next, to find out which, and pass to offer the data to the next handler.



A Eliëns
Mon Jun 1 11:51:50 MET DST 1998