Inherited by Arrival, Assistant, Boat, Customer, CustomerGen, Matrioschka::Proc, Continuous, Shopkeeper, SimA::Master, SimA::Slave, SimB::Loop, Tide, and TimerA.
Process supports Trace.
//---------------------------------------------------------------------------- // Copyright (C) 2002, 2003 Humboldt-Universitaet zu Berlin // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //---------------------------------------------------------------------------- #include <odemx/base/Process.h> #include <iostream> using namespace std; using namespace odemx; // // The first Process is a simple SimTime timer. // It does write a '.' every full (1.0) tic in SimTime. // class TimerA : public Process { public: // // We label all instances of this class 'TimerA'. // ODEMx changes the label on its own to prevent // confusion. It will add a number to the label // if more than one Timer is created in the // simulation. This procedure guarantees that // every label is unique in a simulation. // // When we create a Timer object we will have to // provide a pointer to the Simulation we want it // to participate with. // TimerA(Simulation* sim) : Process(sim, "TimerA") {} // // The behaviour of a user process must be defined // by an implementation of the pure virtual function // 'int main()'. The return value of this function // is stored and can be accessed with 'getReturnValue()'. // As long as 'main()' hasn't finished, the return // value is not valid. You can use 'hasReturned()' // to check this condition. // virtual int main() { while (true) { // // We use 'holdFor()' to let the SimTime pass. // 'holdFor()' requires a time period. We could // also use 'activateIn()'. // The difference between these two is seen if // there is more than one process scheduled at // the same time. 'holdFor' would than schedule // the current process as the last while 'activateIn' // would schedule the current process as the first one. // holdFor(1.0); cout << '.'; } return 0; } }; int main(int argc, char* argv[]) { // // For this example we can use the DefaultSimulation. // In more complex applications it is recommended to // provide a custom-made simulation class. // TimerA* myTimer=new TimerA(getDefaultSimulation()); // // The new process is just created by now. // It won't be executed because it is not activated. // A process can be activated by any of these methods: // // 'hold()' // 'holdFor()' // 'holdUntil()' // 'activate()' // 'activateIn()' // 'acitvateAt()' // // 'hold()' and 'activate()' are equal to 'holdFor(0.0)' // and 'activateIn(0.0)'. 'holdUntil(t)' and 'activateAt(t)' // are equal to 'holdFor(t-now)' and 'activateIn(t-now)'. // myTimer->activate(); // // There are three ways to compute a simulation. // Firstly, you can 'run()' the simulation until it is // finished. A simulation is finished if there is no active // process left or it is stopped with 'exitSimulation()'. // Secondly, you can compute a simulation 'step()' by step. // Thirdly, you can run a simulation until a given SimTime is // reached or passed with 'runUntil()'. // // Because TimerA is running for ever we shouldn't use // 'run()'. Instead we try both 'step()' and 'runUntil()'. // cout << "Basic Simulation Example" << endl; cout << "========================" << endl; for (int i=1; i<5; ++i) { getDefaultSimulation()->step(); cout << endl << i << ". step time=" << getDefaultSimulation()->getTime() << endl; } cout << endl; cout << "continue until SimTime 13.0 is reached or passed:"; getDefaultSimulation()->runUntil(13.0); cout << endl << "time=" << getDefaultSimulation()->getTime() << endl; cout << "========================" << endl; return 0; }
Public Types | |
enum | ProcessState { CREATED, CURRENT, RUNNABLE, IDLE, TERMINATED } |
Process states. More... | |
Public Member Functions | |
Process (Simulation *s, Label l, ProcessObserver *o=0) | |
Construction. | |
~Process () | |
Destruction. | |
ProcessState | getProcessState () const |
Get process state. | |
bool | hasReturned () const |
main() function status | |
int | getReturnValue () const |
Get return value of main() function. | |
virtual Trace * | getTrace () const |
Get pointer to Trace. | |
ProcessQueue * | getQueue () const |
Get queue. | |
SimTime | getEnqueueTime () const |
Get enqueue-time. | |
SimTime | getDequeueTime () const |
Get dequeue-time. | |
Process Scheduling | |
These functions are used to schedule a process in simulation time. | |
void | activate () |
Immediate activation. | |
void | activateIn (SimTime t) |
Activation in (relative) time t . | |
void | activateAt (SimTime t) |
Activation at (absolute) time t . | |
void | activateBefore (Process *p) |
Activation before process p . | |
void | activateAfter (Process *p) |
Activation after process p . | |
void | hold () |
Immediate activation (FIFO). | |
void | holdFor (SimTime t) |
Activation (FIFO) in (relative) time t . | |
void | holdUntil (SimTime t) |
Activation (FIFO) at (absolute) time t . | |
void | sleep () |
Deactivation. | |
virtual void | interrupt () |
Interrupt. | |
void | cancel () |
Termination. | |
Priority | |
If the priority is changed the position of the process in the execution schedule and in queues is updated. This can cause a switch to another process. | |
Priority | getPriority () const |
Get priority. | |
Priority | setPriority (Priority newPriority) |
Set new priority. | |
Execution Time | |
SimTime | getExecutionTime () const |
Get execution time. | |
Current System State | |
Process * | getCurrentProcess () |
Get currently active process. | |
SimTime | getCurrentTime () |
Get current simtime. | |
Simulation * | getSimulation () |
Get simulation of this process. | |
Interrupt handling | |
An Interrupt is caused by the scheduling function interrupt(). The interrupter (Process) is stored. The interrupt-state is automatically reset by the next scheduling function called. If the Process is interrupted but the interrupter is 0 than the Process was interrupted by the simulation (environment). | |
bool | isInterrupted () const |
Get interrupt state. | |
Process * | getInterrupter () const |
Get process which called interrupt(). | |
void | resetInterrupt () |
Reset interrupt state. | |
Static Public Attributes | |
Trace MarkTypes | |
These MarkTypes and Tags are used to trace Process events. A TraceConsumer can use these constants to identify trace events send by Process. | |
const MarkTypeId | baseMarkId = 1000 |
const MarkType | markCreate |
const MarkType | markDestroy |
const MarkType | markActivate |
const MarkType | markActivateIn |
const MarkType | markActivateAt |
const MarkType | markActivateBefore |
const MarkType | markActivateAfter |
const MarkType | markHold |
const MarkType | markHoldFor |
const MarkType | markHoldUntil |
const MarkType | markInterrupt |
const MarkType | markSleep |
const MarkType | markCancel |
const MarkType | markExecute |
const MarkType | markChangeProcessState |
const MarkType | markChangePriority |
const MarkType | markChangeExTime |
const TagId | baseTagId = 1000 |
const Tag | tagCurrent |
const Tag | tagAbsSimTime |
const Tag | tagRelSimTime |
const Tag | tagPartner |
Protected Member Functions | |
virtual int | main ()=0 |
User defined process behaviour. | |
SimTime | setExecutionTime (const SimTime &time) |
Set execution time. | |
void | execute () |
Execution of this process. | |
Friends | |
class | ExecutionList |
class | Simulation |
class | ProcessQueue |
bool | operator< (const Process &first, const Process &second) |
Compare operator for Process objects. |
|
Process states. A process passes different process states during its life time (between new and delete). After construction a process is CREATED. In this state a process isn't scheduled for execution and hasn't been executed yet. In RUNNABLE a process is scheduled for execution. If a process is executed its state is CURRENT. In every simulation there is no more than one process executed at a time. A process in IDLE state is not scheduled for execution. It is inactive. If a process has finished or is terminated its state is TERMINATED. Such a process is not scheduled for execution and cannot be scheduled anymore.
|
|
Construction.
|
|
Get process state.
|
|
Immediate activation. This function schedules the process at the current time before all other processes with the same priority (LIFO). If the current process (A) does not have a higher priority than the process the function is called at (B) the following will happen:
|
|
Activation in (relative) time
now + t before all other processes with the same priority (LIFO). If t is 0 this function is equal to activate().
|
|
Activation at (absolute) time
t before all other processes with the same priority (LIFO). If t is now this function is equal to activate().
|
|
Activation before process
p . If necessary the priority of the process is changed. If p is this process this function does nothing. If process p is not scheduled ODEMx reports an error. |
|
Activation after process
p . If necessary the priority of this process is changed. If p is this process this function does nothing. If process p is not scheduled ODEMx reports an error. |
|
Immediate activation (FIFO). This function schedules the process at the current time after all other processes with the same priority. |
|
Activation (FIFO) in (relative) time
This function schedules the process at the time
|
|
Activation (FIFO) at (absolute) time
This function schedules the process at simtime
|
|
Deactivation. This function removes the process from execution schedule and changes its state into IDLE. The next RUNNABLE process in the schedule is than activated. |
|
Interrupt. This function interrupts the process, which results in an immediate activation [activate()]. A Process can determine whether it was interrupted by isInterrupted(). A Process must handle interrupts on its own. It should do so after activate... and hold... operation.
Reimplemented in Continuous. |
|
Termination. This function terminates the process. The process is than removed from execution schedule and its state is changed to TERMINATED. |
|
Get priority.
|
|
Set new priority.
|
|
Get execution time.
|
|
Get currently active process.
|
|
Get current simtime.
|
|
Get simulation of this process.
|
|
Get interrupt state.
|
|
Get process which called interrupt().
|
|
Reset interrupt state.
|
|
main() function status
|
|
Get return value of main() function.
|
|
Get pointer to Trace.
Implements TraceProducer. |
|
Get queue.
|
|
Get enqueue-time.
|
|
Get dequeue-time.
|
|
User defined process behaviour. This function must be implemented by the user to define the Behaviour of a process. It is executed by ODEMx when the process becomes the current process. If the process calls a scheduling function (direct or indirect, at itself or another process) the main() function is delayed until the process is executed again. The sequence in which different processes are executed is determined by the execution schedule.
Implemented in Continuous. |
|
Set execution time.
|
|
Execution of this process. This function is used by the library. Don't call is directly! The execution is managed by the process scheduling. |
|
Compare operator for Process objects.
first is less than the second or if both are equal if the priority of the first is higher than the second. |