csimplemodule.h

00001 //==========================================================================
00002 //   CSIMPLEMODULE.H  -  header for
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cSimpleModule  : base for simple module objects
00009 //
00010 //==========================================================================
00011 
00012 /*--------------------------------------------------------------*
00013   Copyright (C) 1992-2008 Andras Varga
00014   Copyright (C) 2006-2008 OpenSim Ltd.
00015 
00016   This file is distributed WITHOUT ANY WARRANTY. See the file
00017   `license' for details on this and other legal matters.
00018 *--------------------------------------------------------------*/
00019 
00020 #ifndef __CSIMPLEMODULE_H
00021 #define __CSIMPLEMODULE_H
00022 
00023 #include "cmodule.h"
00024 
00025 NAMESPACE_BEGIN
00026 
00027 class cQueue;
00028 class cCoroutine;
00029 
00064 class SIM_API cSimpleModule : public cModule //implies noncopyable
00065 {
00066     friend class cModule;
00067     friend class cSimulation;
00068 
00069   private:
00070     enum {
00071         FL_USESACTIVITY = 512,   // uses activity() or handleMessage()
00072         FL_ISTERMINATED = 1024,  // for both activity and handleMessage modules
00073         FL_STACKALREADYUNWOUND = 2048, // only for activity modules
00074     };
00075     cMessage *timeoutmsg;   // msg used in wait() and receive() with timeout
00076     cCoroutine *coroutine;
00077 
00078     static bool stack_cleanup_requested; // 'true' value asks activity() to throw a cStackCleanupException
00079     static cSimpleModule *after_cleanup_transfer_to; // transfer back to this module (or to main)
00080 
00081   private:
00082     // internal use
00083     static void activate(void *p);
00084 
00085   protected:
00086     // internal use
00087     virtual void arrived(cMessage *msg, cGate *ongate, simtime_t t);
00088 
00089     // internal: sets the module id.
00090     virtual void setId(int n);
00091 
00092   protected:
00103 
00109     virtual void activity();
00110 
00115     virtual void handleMessage(cMessage *msg);
00117 
00118   public:
00127     cSimpleModule(unsigned stacksize = 0);
00128 
00135     cSimpleModule(const char *dummy1, cModule *dummy2, unsigned stacksize);
00136 
00140     virtual ~cSimpleModule();
00142 
00149     virtual std::string info() const;
00150 
00155     virtual void forEachChild(cVisitor *v);
00157 
00160 
00164     virtual void scheduleStart(simtime_t t);
00165 
00180     virtual void deleteModule();
00182 
00185 
00189     bool usesActivity() const  {return flags&FL_USESACTIVITY;}
00190 
00195     bool isTerminated() const {return flags&FL_ISTERMINATED;}
00197 
00216     bool snapshot(cObject *obj=NULL, const char *label=NULL);
00218 
00221 
00225     int send(cMessage *msg, int gateid)  {return sendDelayed(msg, SIMTIME_ZERO, gateid);}
00226 
00231     int send(cMessage *msg, const char *gatename, int gateindex=-1)  {return sendDelayed(msg, SIMTIME_ZERO, gatename, gateindex);}
00232 
00236     int send(cMessage *msg, cGate *outputgate)  {return sendDelayed(msg, SIMTIME_ZERO, outputgate);}
00237 
00242     int sendDelayed(cMessage *msg, simtime_t delay, int gateid);
00243 
00249     int sendDelayed(cMessage *msg, simtime_t delay, const char *gatename, int gateindex=-1);
00250 
00255     int sendDelayed(cMessage *msg, simtime_t delay, cGate *outputgate);
00256 
00262     int sendDirect(cMessage *msg, cModule *mod, const char *inputGateName, int gateIndex=-1);
00263 
00269     int sendDirect(cMessage *msg, cModule *mod, int inputGateId);
00270 
00276     int sendDirect(cMessage *msg, cGate *inputGate);
00277 
00283     int sendDirect(cMessage *msg, simtime_t propagationDelay, simtime_t duration, cModule *mod, const char *inputGateName, int gateIndex=-1);
00284 
00289     int sendDirect(cMessage *msg, simtime_t propagationDelay, simtime_t duration, cModule *mod, int inputGateId);
00290 
00330     int sendDirect(cMessage *msg, simtime_t propagationDelay, simtime_t duration, cGate *inputGate);
00332 
00335 
00362     int scheduleAt(simtime_t t, cMessage *msg);
00363 
00370     cMessage *cancelEvent(cMessage *msg);
00371 
00378     void cancelAndDelete(cMessage *msg);
00380 
00386 
00391     cMessage *receive();
00392 
00400     cMessage *receive(simtime_t timeout);
00402 
00405 
00419     void wait(simtime_t time);
00420 
00428     void waitAndEnqueue(simtime_t time, cQueue *queue);
00430 
00437     void endSimulation();
00438 
00444     void halt();
00445 
00449     void error(const char *format,...) const;
00451 
00454 
00463     virtual bool hasStackOverflow() const;
00464 
00469     virtual unsigned getStackSize() const;
00470 
00479     virtual unsigned getStackUsage() const;
00481 };
00482 
00483 NAMESPACE_END
00484 
00485 
00486 #endif
00487 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3