SSim C++ API documentation (v. 1.7.6)
Public Member Functions | List of all members
ssim::Process Class Reference

Virtual class (interface) representing processes running within the simulator. More...

#include <ssim.h>

Inheritance diagram for ssim::Process:
ssim::ProcessWithPId ssim::TProcess

Public Member Functions

virtual void init (void)
 action executed when the process is initialized.
virtual void process_event (const Event *msg)
 action executed in response to an event signaled to this process.
virtual void stop (void)
 executed when the process is explicitly stopped.

Detailed Description

Virtual class (interface) representing processes running within the simulator.

A simulated process must implement this basic interface.

Examples:
bs.cc, and twoprocesses.cc.

Member Function Documentation

virtual void ssim::Process::init ( void  )
inlinevirtual

action executed when the process is initialized.

This method is not a constructor. It is rather an initialization step that is executed during the simulation when the process is created within the simulation through Sim::create_process. This initialization is guaranteed to be executed before any event is signaled to the process.

virtual void ssim::Process::process_event ( const Event msg)
inlinevirtual

action executed in response to an event signaled to this process.

The Event object signaled through this method should not be used outside this method, other than by signaling it to other processes through Sim::signal_event(). In fact, the Event pointer passed to this method should be considered invalid outside this method, as the simulator proceeds to de-allocate every event object that is not signaled to any other process.

The implementation of this method may specify the duration of the actions associated with this response using the advance_delay method. By default, the duration of an action is 0.

The implementation of this method may use the C++ dynamic_cast feature to select an action on the basis of the actual type of the Event object. Here's an example that illustrates this feature:

class Payment : public Event {
public:
int dollars;
//...
};
class Delivery : public Event {
public:
int count;
string model;
//...
};
class GuitarShop : public Process {
//...
virtual void process_event(const Event * e) {
const Payment * p;
const Delivery * d;
if ((p = dynamic_cast<const Payment *>(e)) != 0) {
cout << "I got a payment for $" << p->dollars << endl;
} else if ((d = dynamic_cast<const Delivery *>(e)) != 0) {
cout << "I got a delivery of " << d->count
<< " " << d->model << " guitars" << endl;
} else {
cerr << "GuitarShop: error: unknown event." << endl;
}
}
};
See Also
Sim::advance_delay(Time).
virtual void ssim::Process::stop ( void  )
inlinevirtual

executed when the process is explicitly stopped.

A process is stopped by a call to Sim::stop_process(ProcessId). This method is executed immediately after the process has processed all the events scheduled before the call to Sim::stop_process.


The documentation for this class was generated from the following file: