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-2005 Andras Varga
00014 
00015   This file is distributed WITHOUT ANY WARRANTY. See the file
00016   `license' for details on this and other legal matters.
00017 *--------------------------------------------------------------*/
00018 
00019 #ifndef __CSIMPLEMODULE_H
00020 #define __CSIMPLEMODULE_H
00021 
00022 #include "cmodule.h"
00023 
00024 
00058 class SIM_API cSimpleModule : public cModule
00059 {
00060     friend class cModule;
00061     friend class cSimulation;
00062     friend class TSimpleModInspector;
00063 
00064   private:
00065     bool usesactivity;      // uses activity() or handleMessage()
00066     int state;              // ended/ready/waiting for msg
00067     opp_string phasestr;    // a 'phase' string
00068     cMessage *timeoutmsg;   // msg used in wait() and receive() with timeout
00069     cCoroutine *coroutine;
00070 
00071     static bool stack_cleanup_requested; // 'true' value asks activity() to throw a cStackCleanupException
00072     static cSimpleModule *after_cleanup_transfer_to; // transfer back to this module (or to main)
00073 
00074   private:
00075     // internal use
00076     static void activate(void *p);
00077 
00078   protected:
00079     // internal use
00080     virtual void arrived(cMessage *msg,int n,simtime_t t);
00081 
00082     // internal: sets the module id.
00083     virtual void setId(int n);
00084 
00085   protected:
00096 
00102     virtual void activity();
00103 
00108     virtual void handleMessage(cMessage *msg);
00110 
00111   public:
00114 
00118     cSimpleModule(const cSimpleModule& mod);
00119 
00126     cSimpleModule(unsigned stacksize = 0);
00127 
00134     cSimpleModule(const char *name, cModule *parent, unsigned stacksize);
00135 
00139     virtual ~cSimpleModule();
00140 
00144     cSimpleModule& operator=(const cSimpleModule& mod);
00146 
00149 
00154     virtual cPolymorphic *dup() const  {return new cSimpleModule(*this);}
00155 
00160     virtual std::string info() const;
00161 
00166     virtual void forEachChild(cVisitor *v);
00168 
00171 
00175     virtual void scheduleStart(simtime_t t);
00176 
00181     virtual void deleteModule();
00183 
00186 
00190     bool usesActivity() const  {return usesactivity;}
00192 
00195 
00200     simtime_t simTime() const;   // cannot make inline because of declaration order!
00202 
00205 
00211     void setPhase(const char *phase)  {phasestr=phase;}
00212 
00217     const char *phase() const  {return phasestr.c_str();}
00218 
00235     bool snapshot(cObject *obj=&simulation, const char *label=NULL); // write snapshot file
00236 
00243     void breakpoint(const char *label);     // user breakpoint
00244 
00255     void pause(const char *phase=NULL);
00257 
00260 
00264     int send(cMessage *msg, int gateid);   // send a message thru gate id
00265 
00270     int send(cMessage *msg, const char *gatename, int sn=-1); // s:gate name, sn:index
00271 
00275     int send(cMessage *msg, cGate *outputgate);
00276 
00281     int sendDelayed(cMessage *msg, double delay, int gateid);
00282 
00288     int sendDelayed(cMessage *msg, double delay, const char *gatename, int sn=-1);
00289 
00294     int sendDelayed(cMessage *msg, double delay, cGate *outputgate);
00295 
00301     int sendDirect(cMessage *msg, double delay, cModule *mod, int inputgateid);
00302 
00325     int sendDirect(cMessage *msg, double delay, cModule *mod, const char *inputgatename, int sn=-1);
00326 
00332     int sendDirect(cMessage *msg, double delay, cGate *inputgate);
00334 
00337 
00364     int scheduleAt(simtime_t t, cMessage *msg);
00365 
00372     cMessage *cancelEvent(cMessage *msg);
00373 
00380     void cancelAndDelete(cMessage *msg);
00382 
00389 
00394     cMessage *receive();
00395 
00403     cMessage *receive(simtime_t timeout);
00405 
00408 
00422     void wait(simtime_t time);
00423 
00431     void waitAndEnqueue(simtime_t time, cQueue *queue);
00433 
00436 
00448     void end();
00449 
00454     void endSimulation();
00455 
00460     void error(const char *fmt,...) const;
00462 
00465 
00473     void recordScalar(const char *name, double value);
00475 
00478 
00487     virtual bool stackOverflow() const;
00488 
00493     virtual unsigned stackSize() const;
00494 
00503     virtual unsigned stackUsage() const;
00505 
00511     int moduleState() const {return state;}
00513 };
00514 
00515 #endif
00516 

Generated on Sat Oct 21 17:47:56 2006 for OMNeT++/OMNEST Simulation Library by  doxygen 1.4.6