?? mobilehost_n.cc
字號:
//-----------------------------------------
//
// Generated by nedtool, version 3.0
// date: Sun Sep 11 21:44:08 2005
//
//-----------------------------------------
#include <math.h>
#include "omnetpp.h"
// NEDC version check
#define NEDC_VERSION 0x0300
#if (NEDC_VERSION!=OMNETPP_VERSION)
# error Version mismatch! Probably this file was generated by an earlier version of nedc: 'make clean' should help.
#endif
// Disable warnings about unused variables. For MSVC and BC only:
// GCC has no way to turn on its -Wunused option in a source file :(
#ifdef _MSC_VER
# pragma warning(disable:4101)
#endif
#ifdef __BORLANDC__
# pragma warn -waus
# pragma warn -wuse
#endif
static cModuleType *_getModuleType(const char *modname)
{
cModuleType *modtype = findModuleType(modname);
if (!modtype)
throw new cException("Module type definition %s not found (Define_Module() missing from C++ code?)", modname);
return modtype;
}
static void _checkModuleVectorSize(int vectorsize, const char *mod)
{
if (vectorsize<0)
throw new cException("Negative module vector size %s[%d]", mod, vectorsize);
}
static void _readModuleParameters(cModule *mod)
{
int n = mod->params();
for (int k=0; k<n; k++)
if (mod->par(k).isInput())
mod->par(k).read();
}
static int _checkModuleIndex(int index, int vectorsize, const char *modname)
{
if (index<0 || index>=vectorsize)
throw new cException("Submodule index %s[%d] out of range, sizeof(%s) is %d", modname, index, modname, vectorsize);
return index;
}
static cGate *_checkGate(cModule *mod, const char *gatename)
{
cGate *g = mod->gate(gatename);
if (!g)
throw new cException("%s has no gate named %s",mod->fullPath().c_str(), gatename);
return g;
}
static cGate *_checkGate(cModule *mod, const char *gatename, int gateindex)
{
cGate *g = mod->gate(gatename, gateindex);
if (!g)
throw new cException("%s has no gate %s[%d]",mod->fullPath().c_str(), gatename, gateindex);
return g;
}
static cGate *_getFirstUnusedParentModGate(cModule *mod, const char *gatename)
{
int baseId = mod->findGate(gatename);
if (baseId<0)
throw new cException("%s has no %s[] gate",mod->fullPath().c_str(), gatename);
int n = mod->gate(baseId)->size();
for (int i=0; i<n; i++)
if (!mod->gate(baseId+i)->isConnectedInside())
return mod->gate(baseId+i);
throw new cException("%s[] gates are all connected, no gate left for `++' operator",mod->fullPath().c_str(), gatename);
}
static cGate *_getFirstUnusedSubmodGate(cModule *mod, const char *gatename)
{
int baseId = mod->findGate(gatename);
if (baseId<0)
throw new cException("%s has no %s[] gate",mod->fullPath().c_str(), gatename);
int n = mod->gate(baseId)->size();
for (int i=0; i<n; i++)
if (!mod->gate(baseId+i)->isConnectedOutside())
return mod->gate(baseId+i);
int newBaseId = mod->setGateSize(gatename,n+1);
return mod->gate(newBaseId+n);
}
static cFunctionType *_getFunction(const char *funcname, int argcount)
{
cFunctionType *functype = findFunction(funcname,argcount);
if (!functype)
throw new cException("Function %s with %d args not found", funcname, argcount);
return functype;
}
static cChannel *_createChannel(const char *channeltypename)
{
cChannelType *channeltype = findChannelType(channeltypename);
if (!channeltype)
throw new cException("Channel type %s not found", channeltypename);
cChannel *channel = channeltype->create("channel");
return channel;
}
static cChannel *_createNonTypedBasicChannel(double delay, double error, double datarate)
{
cBasicChannel *channel = new cBasicChannel("channel");
if (delay!=0) channel->setDelay(delay);
if (error!=0) channel->setError(error);
if (datarate!=0) channel->setDatarate(datarate);
return channel;
}
static cXMLElement *_getXMLDocument(const char *fname, const char *pathexpr=NULL)
{
cXMLElement *node = ev.getXMLDocument(fname, pathexpr);
if (!node)
throw new cException(!pathexpr ? "xmldoc(\"%s\"): element not found" : "xmldoc(\"%s\", \"%s\"): element not found",fname,pathexpr);
return node;
}
ModuleInterface(MobileHost)
// parameters:
Parameter(numHost, ParType_Numeric ParType_Const)
Parameter(x, ParType_Numeric)
Parameter(y, ParType_Numeric)
Parameter(Xbound, ParType_Numeric)
Parameter(Ybound, ParType_Numeric)
Parameter(macAlgorithm, ParType_String)
Parameter(routeAlgorithm, ParType_String)
Parameter(mobilityModel, ParType_String)
EndInterface
Register_ModuleInterface(MobileHost);
class MobileHost : public cCompoundModule
{
public:
MobileHost(const char *name, cModule *parent) :
cCompoundModule(name, parent) {}
protected:
virtual void doBuildInside();
};
Define_Module(MobileHost);
void MobileHost::doBuildInside()
{
cModule *mod = this;
// temporary variables:
cPar tmpval;
const char *modtypename;
mod->setBackgroundDisplayString("p=10,10;b=287,250");
// submodules:
cModuleType *modtype = NULL;
int submodindex;
//
// submodule 'physic':
//
modtype = _getModuleType("Physic");
cModule *physic_p = modtype->create("physic", mod);
int physic_size = 1;
// parameter assignments:
physic_p->par("txPower") = (tmpval=0L, tmpval.setInput(true), tmpval);
physic_p->par("rxThreshold") = (tmpval=0L, tmpval.setInput(true), tmpval);
physic_p->par("channelDelay") = (tmpval=0L, tmpval.setInput(true), tmpval);
physic_p->par("channelDatarate") = (tmpval=0L, tmpval.setInput(true), tmpval);
physic_p->par("channelError") = (tmpval=0L, tmpval.setInput(true), tmpval);
_readModuleParameters(physic_p);
physic_p->setDisplayString("p=148,62;b=104,10");
//
// submodule 'mac':
//
modtypename = mod->par("macAlgorithm");
modtype = _getModuleType(modtypename);
cModule *mac_p = modtype->create("mac", mod);
int mac_size = 1;
// parameter assignments:
mac_p->par("inBufferSize") = (tmpval=0L, tmpval.setInput(true), tmpval);
mac_p->par("promisqueMode") = (tmpval=0L, tmpval.setInput(true), tmpval);
_readModuleParameters(mac_p);
mac_p->setDisplayString("p=148,116;b=104,10");
//
// submodule 'route':
//
modtypename = mod->par("routeAlgorithm");
modtype = _getModuleType(modtypename);
cModule *route_p = modtype->create("route", mod);
int route_size = 1;
// parameter assignments:
_readModuleParameters(route_p);
route_p->setDisplayString("p=148,171;b=104,10");
//
// submodule 'app':
//
modtype = _getModuleType("Application");
cModule *app_p = modtype->create("app", mod);
int app_size = 1;
// parameter assignments:
app_p->par("rate") = (tmpval=0L, tmpval.setInput(true), tmpval);
app_p->par("pktSize") = (tmpval=0L, tmpval.setInput(true), tmpval);
app_p->par("burstInterval") = (tmpval=0L, tmpval.setInput(true), tmpval);
app_p->par("hostNum") = mod->par("numHost");
app_p->par("active") = (tmpval=0L, tmpval.setInput(true), tmpval);
_readModuleParameters(app_p);
app_p->setDisplayString("p=148,216;b=104,10");
//
// submodule 'mobility':
//
modtypename = mod->par("mobilityModel");
modtype = _getModuleType(modtypename);
cModule *mobility_p = modtype->create("mobility", mod);
int mobility_size = 1;
// parameter assignments:
mobility_p->par("maxSpeed") = (tmpval=0, tmpval.setPrompt("max speed"), tmpval.setInput(true), tmpval);
mobility_p->par("minSpeed") = (tmpval=0, tmpval.setPrompt("min speed"), tmpval.setInput(true), tmpval);
mobility_p->par("movKind") = (tmpval=0, tmpval.setPrompt("0 toroidal, 1 rebound"), tmpval.setInput(true), tmpval);
mobility_p->par("XRange") = mod->par("Xbound");
mobility_p->par("YRange") = mod->par("Ybound");
mobility_p->par("moveInterval") = (tmpval=0.5, tmpval.setPrompt("movement period"), tmpval.setInput(true), tmpval);
mobility_p->par("distance") = (tmpval=100, tmpval.setPrompt("distance to cover"), tmpval.setInput(true), tmpval);
mobility_p->par("target") = (tmpval=-1, tmpval.setPrompt("target node id"), tmpval.setInput(true), tmpval);
mobility_p->par("pauseTime") = (tmpval=0, tmpval.setPrompt("pause between two moves"), tmpval.setInput(true), tmpval);
mobility_p->par("speedVariator") = (tmpval=1, tmpval.setPrompt("speed choice variance"), tmpval.setInput(true), tmpval);
_readModuleParameters(mobility_p);
mobility_p->setDisplayString("p=252,128;b=24,26");
//
// connections:
//
cGate *srcgate, *destgate;
cChannel *channel;
cPar *par;
// connection
srcgate = _checkGate(app_p, "out");
destgate = _checkGate(route_p, "fromApp");
srcgate->connectTo(destgate);
srcgate->setDisplayString("m=m,24,16,24,16");
// connection
srcgate = _checkGate(route_p, "toMac");
destgate = _checkGate(mac_p, "fromRoute");
srcgate->connectTo(destgate);
srcgate->setDisplayString("m=m,24,0,24,4");
// connection
srcgate = _checkGate(mac_p, "toRoute");
destgate = _checkGate(route_p, "fromMac");
srcgate->connectTo(destgate);
srcgate->setDisplayString("m=m,80,0,80,0");
// connection
srcgate = _checkGate(mac_p, "toPh");
destgate = _checkGate(physic_p, "fromMac");
srcgate->connectTo(destgate);
srcgate->setDisplayString("m=m,24,12,24,12");
// connection
srcgate = _checkGate(physic_p, "toMac");
destgate = _checkGate(mac_p, "fromPh");
srcgate->connectTo(destgate);
srcgate->setDisplayString("m=m,80,0,80,8");
// connection
srcgate = _checkGate(mobility_p, "out");
destgate = _checkGate(physic_p, "fromMobility");
srcgate->connectTo(destgate);
srcgate->setDisplayString("m=m,64,8,88,44");
// connection
srcgate = _checkGate(route_p, "toApp");
destgate = _checkGate(app_p, "in");
srcgate->connectTo(destgate);
srcgate->setDisplayString("m=m,80,24,80,54");
// check all gates are connected:
mod->checkInternalConnections();
//
// this level is done -- recursively build submodules too
//
physic_p->buildInside();
mac_p->buildInside();
route_p->buildInside();
app_p->buildInside();
mobility_p->buildInside();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -