OMNeT++ Simulation Library  5.6.1
csimplemodule.h
1 //==========================================================================
2 // CSIMPLEMODULE.H - header for
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CSIMPLEMODULE_H
17 #define __OMNETPP_CSIMPLEMODULE_H
18 
19 #include "cmodule.h"
20 
21 namespace omnetpp {
22 
23 class cQueue;
24 class cCoroutine;
25 
62 class SIM_API cSimpleModule : public cModule //implies noncopyable
63 {
64  friend class cModule;
65  friend class cSimulation;
66 
67  private:
68  enum {
69  FL_USESACTIVITY = 1 << 13, // uses activity() or handleMessage()
70  FL_ISTERMINATED = 1 << 14, // for both activity and handleMessage modules
71  FL_STACKALREADYUNWOUND = 1 << 15, // only for activity modules
72  };
73 
74  cMessage *timeoutMessage; // msg used in wait() and receive() with timeout
75  cCoroutine *coroutine;
76 
77  static bool stackCleanupRequested; // 'true' value asks activity() to throw a cStackCleanupException
78  static cSimpleModule *afterCleanupTransferTo; // transfer back to this module (or to main)
79 
80  private:
81  // internal use
82  static void activate(void *p);
83 
84  protected:
85  // internal use
86  virtual void arrived(cMessage *msg, cGate *ongate, simtime_t t) override;
87 
88  protected:
99 
105  virtual void activity();
106 
111  virtual void handleMessage(cMessage *msg);
113 
114  public:
123  cSimpleModule(unsigned stacksize = 0);
124 
129  virtual ~cSimpleModule();
131 
138  virtual std::string str() const override;
139 
144  virtual void forEachChild(cVisitor *v) override;
146 
149 
153  virtual void scheduleStart(simtime_t t) override;
155 
158 
162  bool usesActivity() const {return flags&FL_USESACTIVITY;}
163 
168  bool isTerminated() const {return flags&FL_ISTERMINATED;}
170 
189  virtual void snapshot(cObject *obj=nullptr, const char *label=nullptr);
191 
194 
198  virtual void send(cMessage *msg, int gateid) {return sendDelayed(msg, SIMTIME_ZERO, gateid);}
199 
204  virtual void send(cMessage *msg, const char *gatename, int gateindex=-1) {return sendDelayed(msg, SIMTIME_ZERO, gatename, gateindex);}
205 
209  virtual void send(cMessage *msg, cGate *outputgate) {return sendDelayed(msg, SIMTIME_ZERO, outputgate);}
210 
215  virtual void sendDelayed(cMessage *msg, simtime_t delay, int gateid);
216 
222  virtual void sendDelayed(cMessage *msg, simtime_t delay, const char *gatename, int gateindex=-1);
223 
228  virtual void sendDelayed(cMessage *msg, simtime_t delay, cGate *outputgate);
229 
235  virtual void sendDirect(cMessage *msg, cModule *mod, const char *inputGateName, int gateIndex=-1);
236 
242  virtual void sendDirect(cMessage *msg, cModule *mod, int inputGateId);
243 
249  virtual void sendDirect(cMessage *msg, cGate *inputGate);
250 
256  virtual void sendDirect(cMessage *msg, simtime_t propagationDelay, simtime_t duration, cModule *mod, const char *inputGateName, int gateIndex=-1);
257 
262  virtual void sendDirect(cMessage *msg, simtime_t propagationDelay, simtime_t duration, cModule *mod, int inputGateId);
263 
303  virtual void sendDirect(cMessage *msg, simtime_t propagationDelay, simtime_t duration, cGate *inputGate);
305 
308 
335  virtual void scheduleAt(simtime_t t, cMessage *msg);
336 
343  virtual cMessage *cancelEvent(cMessage *msg);
344 
351  virtual void cancelAndDelete(cMessage *msg);
353 
359 
364  virtual cMessage *receive();
365 
373  virtual cMessage *receive(simtime_t timeout);
375 
378 
392  virtual void wait(simtime_t time);
393 
401  virtual void waitAndEnqueue(simtime_t time, cQueue *queue);
403 
410  virtual void endSimulation();
411 
417  virtual void halt();
418 
422  virtual void error(const char *format,...) const;
424 
427 
436  virtual bool hasStackOverflow() const;
437 
442  virtual unsigned getStackSize() const;
443 
452  virtual unsigned getStackUsage() const;
454 };
455 
456 } // namespace omnetpp
457 
458 
459 #endif
460 
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
Represents a module gate.
Definition: cgate.h:63
bool isTerminated() const
Definition: csimplemodule.h:168
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Base class for all simple module classes.
Definition: csimplemodule.h:62
Simulation manager class.
Definition: csimulation.h:62
virtual void send(cMessage *msg, int gateid)
Definition: csimplemodule.h:198
Low-level coroutine library. Coroutines are used by cSimpleModule.
Definition: ccoroutine.h:67
bool usesActivity() const
Definition: csimplemodule.h:162
#define SIMTIME_ZERO
Zero simulation time.
Definition: simtime_t.h:73
This class represents modules in the simulation.
Definition: cmodule.h:47
Queue class for objects derived from cObject.
Definition: cqueue.h:42
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
virtual void send(cMessage *msg, const char *gatename, int gateindex=-1)
Definition: csimplemodule.h:204
Definition: cabstracthistogram.h:21
virtual void send(cMessage *msg, cGate *outputgate)
Definition: csimplemodule.h:209