www.pudn.com > adHocSimtest.rar > mobileHost_n.cc, change:2004-06-21,size:16044b


//----------------------------------------- 
// 
// Generated by NEDC version 2.3 
// date:	Mon Jun 21 10:27:27 2004 
// 
// Input file:	simple.ned 
// Output file:	simple_n.cc 
//----------------------------------------- 
 
 
#include <math.h> 
#include "omnetpp.h" 
 
#define check_error() \ 
    {(void)0;} 
#define check_memory() \ 
    {if (memoryIsLow()) {throw new cException(eNOMEM); }} 
#define check_module_count(num, mod, parentmod) \ 
    {if ((int)num<=0) {throw new cException("Negative or zero module vector size %s[%d] in compound module %s", \ 
                          mod,(int)num,parentmod);}} 
#define check_gate_count(num, mod, gate, parentmod) \ 
    {if ((int)num<0) {throw new cException("Negative gate vector size %s.%s[%d] in compound module %s", \ 
                          mod,gate,(int)num,parentmod);}} 
#define check_loop_bounds(lower, upper, parentmod) \ 
    {if ((int)lower<0) \ 
        {throw new cException("Bad loop bounds (%d..%d) in compound module %s", \ 
                 (int)lower,(int)upper,parentmod);}} 
#define check_module_index(index,modvar,modname,parentmod) \ 
    {if (index<0 || index>=modvar[0]->size()) {throw new cException("Bad submodule index %s[%d] in compound module %s", \ 
          modname,(int)index,parentmod);}} 
#define check_channel_params(delay, err, channel) \ 
    {if ((double)delay<0.0) \ 
        {throw new cException("Negative delay value %lf in channel %s",(double)delay,channel);} \ 
     if ((double)err<0.0 || (double)err>1.0) \ 
        {throw new cException("Incorrect error value %lf in channel %s",(double)err,channel);}} 
#define check_modtype(modtype, modname) \ 
    {if ((modtype)==NULL) {throw new cException("Simple module type definition %s not found", \ 
                                     modname);}} 
#define check_function(funcptr, funcname) \ 
    {if ((funcptr)==NULL) {throw new cException("Function %s not found", \ 
                                     funcname);}} 
#define check_function_retnull(funcptr, funcname) \ 
    {if ((funcptr)==NULL) {throw new cException("Function %s not found", \ 
                                     funcname);return NULL;}} 
#define check_gate(gateindex, modname, gatename) \ 
    {if ((int)gateindex==-1) {throw new cException("Gate %s.%s not found",modname,gatename);}} 
#define check_anc_param(ptr,parname,compoundmod) \ 
    {if ((ptr)==NULL) {throw new cException("Unknown ancestor parameter named %s in compound module %s", \ 
                                parname,compoundmod);}} 
#define check_param(ptr,parname) \ 
    {if ((ptr)==NULL) {throw new cException("Unknown parameter named %s", \ 
                                parname);}} 
#ifndef __cplusplus 
#  error Compile as C++! 
#endif 
#ifdef __BORLANDC__ 
#  if !defined(__FLAT__) && !defined(__LARGE__) 
#    error Compile as 16-bit LARGE model or 32-bit DPMI! 
#  endif 
#endif 
 
// Disable warnings about unused variables: 
#ifdef _MSC_VER 
#  pragma warning(disable:4101) 
#endif 
#ifdef __BORLANDC__ 
#  pragma warn -waus 
#  pragma warn -wuse 
#endif 
// for GCC, seemingly there's no way to emulate the -Wunused command-line 
// flag from a source file... 
 
// Version check 
#define NEDC_VERSION 0x0203 
#if (NEDC_VERSION!=OMNETPP_VERSION) 
#    error Version mismatch! Probably this file was generated by an earlier version of nedc: 'make clean' should help. 
#endif 
 
//-------------------------------------------- 
// Following code generated from: mobileHost.ned 
//-------------------------------------------- 
 
ModuleInterface( MobileHost ) 
	Machine( default ) 
	Parameter( numHost, ParType_Numeric ParType_Const ) 
	Parameter( x, ParType_Numeric ) 
	Parameter( y, ParType_Numeric ) 
	Parameter( Xbound, ParType_Numeric ) 
	Parameter( Ybound, ParType_Numeric ) 
	Parameter( routeAlgoritm, ParType_String ) 
	Parameter( mobilityModel, ParType_String ) 
EndInterface 
 
Register_ModuleInterface( MobileHost ) 
 
class MobileHost : public cCompoundModule 
{ 
  public: 
    MobileHost(const char *name, cModule *parentmod) : 
      cCompoundModule(name, parentmod) {} 
  protected: 
    virtual void doBuildInside(); 
}; 
 
Define_Module( MobileHost ); 
 
void MobileHost::doBuildInside() 
{ 
	cModule *mod = this; 
	// temporary variables: 
	cPar value, *par; 
	cPar::ExprElem *expr_tab; int k; 
	cFunctionType *functype; 
	const char *type_name; 
	char b1[64], b2[64]; 
	cArray machines; 
	bool islocal, do_this_block; 
	int n; 
 
	// const parameters: 
	// Submodules: 
	cModuleType *modtype = NULL; 
	long sub_nr = 0; 
	long sub_i = 0; 
 
	// mobility 
	par = &mod->par("mobilityModel"); 
	check_param(par,"mobilityModel"); 
	type_name = (const char *)par; 
	type_name = mod->par("mobilityModel"); 
	modtype = findModuleType( type_name ); 
	check_modtype( modtype, type_name ); 
	cModule *mobility_mod; 
 
	// an empty actual machine list for the next module 
	par = new cPar(); 
	*par = mod->machinePar("default"); 
	machines.add( par ); 
	check_error(); check_memory(); 
 
	// module creation: 
	islocal = simulation.netInterface()==NULL || 
	          simulation.netInterface()->isLocalMachineIn( machines ); 
	mobility_mod = modtype->create( "mobility", mod, islocal); 
	check_error(); check_memory(); 
 
	// set machine list: 
	mobility_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); 
	check_error(); check_memory(); 
 
	// 'parameters:' section 
	value.cancelRedirection(); 
	value = 0; 
	value.setPrompt( "max speed" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("maxSpeed")); 
	check_param(par, "maxSpeed"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0; 
	value.setPrompt( "min speed" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("minSpeed")); 
	check_param(par, "minSpeed"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0; 
	value.setPrompt( "0 toroidal, 1 rebound" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("movKind")); 
	check_param(par, "movKind"); 
	*par = value; 
 
	par = &(mobility_mod->par("XRange")); 
	check_param(par, "XRange"); 
	*par = mod->par( "Xbound" ); 
 
	par = &(mobility_mod->par("YRange")); 
	check_param(par, "YRange"); 
	*par = mod->par( "Ybound" ); 
 
	value.cancelRedirection(); 
	value = 0.5; 
	value.setPrompt( "movement period" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("moveInterval")); 
	check_param(par, "moveInterval"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 100; 
	value.setPrompt( "distance to cover" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("distance")); 
	check_param(par, "distance"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = -1; 
	value.setPrompt( "target node id" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("target")); 
	check_param(par, "target"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0; 
	value.setPrompt( "pause between two moves" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("pauseTime")); 
	check_param(par, "pauseTime"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 1; 
	value.setPrompt( "speed choice variance" ); 
	value.setInput( true ); 
	par = &(mobility_mod->par("speedVariator")); 
	check_param(par, "speedVariator"); 
	*par = value; 
 
	n = mobility_mod->params(); 
	for(k=0;k<n;k++) 
	   if(mobility_mod->par(k).isInput()) 
	      {mobility_mod->par(k).read();check_error();} 
 
	mobility_mod->setDisplayString(dispSUBMOD, "p=252,128;b=24,26" ); 
 
	// build function call: 
	mobility_mod->buildInside(); 
	machines.clear(); 
 
	// physic 
	modtype = findModuleType( "Physic" ); 
	check_modtype( modtype, "Physic" ); 
	cModule *physic_mod; 
 
	// an empty actual machine list for the next module 
	par = new cPar(); 
	*par = mod->machinePar("default"); 
	machines.add( par ); 
	check_error(); check_memory(); 
 
	// module creation: 
	islocal = simulation.netInterface()==NULL || 
	          simulation.netInterface()->isLocalMachineIn( machines ); 
	physic_mod = modtype->create( "physic", mod, islocal); 
	check_error(); check_memory(); 
 
	// set machine list: 
	physic_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); 
	check_error(); check_memory(); 
 
	// 'parameters:' section 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(physic_mod->par("txPower")); 
	check_param(par, "txPower"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(physic_mod->par("rxThreshold")); 
	check_param(par, "rxThreshold"); 
	*par = value; 
 
	n = physic_mod->params(); 
	for(k=0;k<n;k++) 
	   if(physic_mod->par(k).isInput()) 
	      {physic_mod->par(k).read();check_error();} 
 
	physic_mod->setDisplayString(dispSUBMOD, "p=148,62;b=104,10" ); 
 
	// build function call: 
	physic_mod->buildInside(); 
	machines.clear(); 
 
	// mac 
	modtype = findModuleType( "Mac" ); 
	check_modtype( modtype, "Mac" ); 
	cModule *mac_mod; 
 
	// an empty actual machine list for the next module 
	par = new cPar(); 
	*par = mod->machinePar("default"); 
	machines.add( par ); 
	check_error(); check_memory(); 
 
	// module creation: 
	islocal = simulation.netInterface()==NULL || 
	          simulation.netInterface()->isLocalMachineIn( machines ); 
	mac_mod = modtype->create( "mac", mod, islocal); 
	check_error(); check_memory(); 
 
	// set machine list: 
	mac_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); 
	check_error(); check_memory(); 
 
	// 'parameters:' section 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(mac_mod->par("inBufferSize")); 
	check_param(par, "inBufferSize"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(mac_mod->par("promisqueMode")); 
	check_param(par, "promisqueMode"); 
	*par = value; 
 
	n = mac_mod->params(); 
	for(k=0;k<n;k++) 
	   if(mac_mod->par(k).isInput()) 
	      {mac_mod->par(k).read();check_error();} 
 
	mac_mod->setDisplayString(dispSUBMOD, "p=148,116;b=104,10" ); 
 
	// build function call: 
	mac_mod->buildInside(); 
	machines.clear(); 
 
	// route 
	par = &mod->par("routeAlgoritm"); 
	check_param(par,"routeAlgoritm"); 
	type_name = (const char *)par; 
	type_name = mod->par("routeAlgoritm"); 
	modtype = findModuleType( type_name ); 
	check_modtype( modtype, type_name ); 
	cModule *route_mod; 
 
	// an empty actual machine list for the next module 
	par = new cPar(); 
	*par = mod->machinePar("default"); 
	machines.add( par ); 
	check_error(); check_memory(); 
 
	// module creation: 
	islocal = simulation.netInterface()==NULL || 
	          simulation.netInterface()->isLocalMachineIn( machines ); 
	route_mod = modtype->create( "route", mod, islocal); 
	check_error(); check_memory(); 
 
	// set machine list: 
	route_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); 
	check_error(); check_memory(); 
 
	// 'parameters:' section 
	n = route_mod->params(); 
	for(k=0;k<n;k++) 
	   if(route_mod->par(k).isInput()) 
	      {route_mod->par(k).read();check_error();} 
 
	route_mod->setDisplayString(dispSUBMOD, "p=148,171;b=104,10" ); 
 
	// build function call: 
	route_mod->buildInside(); 
	machines.clear(); 
 
	// app 
	modtype = findModuleType( "Application" ); 
	check_modtype( modtype, "Application" ); 
	cModule *app_mod; 
 
	// an empty actual machine list for the next module 
	par = new cPar(); 
	*par = mod->machinePar("default"); 
	machines.add( par ); 
	check_error(); check_memory(); 
 
	// module creation: 
	islocal = simulation.netInterface()==NULL || 
	          simulation.netInterface()->isLocalMachineIn( machines ); 
	app_mod = modtype->create( "app", mod, islocal); 
	check_error(); check_memory(); 
 
	// set machine list: 
	app_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); 
	check_error(); check_memory(); 
 
	// 'parameters:' section 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(app_mod->par("rate")); 
	check_param(par, "rate"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(app_mod->par("pktSize")); 
	check_param(par, "pktSize"); 
	*par = value; 
 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(app_mod->par("burstInterval")); 
	check_param(par, "burstInterval"); 
	*par = value; 
 
	par = &(app_mod->par("hostNum")); 
	check_param(par, "hostNum"); 
	*par = mod->par( "numHost" ); 
 
	value.cancelRedirection(); 
	value = 0L; 
	value.setPrompt( NULL ); 
	value.setInput( true ); 
	par = &(app_mod->par("active")); 
	check_param(par, "active"); 
	*par = value; 
 
	n = app_mod->params(); 
	for(k=0;k<n;k++) 
	   if(app_mod->par(k).isInput()) 
	      {app_mod->par(k).read();check_error();} 
 
	app_mod->setDisplayString(dispSUBMOD, "p=148,216;b=104,10" ); 
 
	// build function call: 
	app_mod->buildInside(); 
	machines.clear(); 
 
	// Connections: 
	cLinkType *link_p; 
	cPar *delay_p, *error_p, *datarate_p; 
	int gateL, gateR; 
	long mod_nr_L, mod_nr_R, gate_nr_L, gate_nr_R; 
 
	do_this_block = true; // no "if" condition 
	if (do_this_block) // "if" in NED 
	{ 
	gateL = app_mod->findGate( "out" ); 
	check_gate( gateL, "app", "out" ); 
 
	gateR = route_mod->findGate( "fromApp" ); 
	check_gate( gateR, "route", "fromApp" ); 
 
	connect (app_mod, gateL, 
	         NULL, 
	         route_mod, gateR); 
 
	app_mod->gate(gateL)->setDisplayString( "m=m,24,16,24,16" ); 
	check_error(); check_memory(); 
	} // end-if 
 
 
	do_this_block = true; // no "if" condition 
	if (do_this_block) // "if" in NED 
	{ 
	gateL = route_mod->findGate( "toMac" ); 
	check_gate( gateL, "route", "toMac" ); 
 
	gateR = mac_mod->findGate( "fromRoute" ); 
	check_gate( gateR, "mac", "fromRoute" ); 
 
	connect (route_mod, gateL, 
	         NULL, 
	         mac_mod, gateR); 
 
	route_mod->gate(gateL)->setDisplayString( "m=m,24,0,24,4" ); 
	check_error(); check_memory(); 
	} // end-if 
 
 
	do_this_block = true; // no "if" condition 
	if (do_this_block) // "if" in NED 
	{ 
	gateL = mac_mod->findGate( "toRoute" ); 
	check_gate( gateL, "mac", "toRoute" ); 
 
	gateR = route_mod->findGate( "fromMac" ); 
	check_gate( gateR, "route", "fromMac" ); 
 
	connect (mac_mod, gateL, 
	         NULL, 
	         route_mod, gateR); 
 
	mac_mod->gate(gateL)->setDisplayString( "m=m,80,0,80,0" ); 
	check_error(); check_memory(); 
	} // end-if 
 
 
	do_this_block = true; // no "if" condition 
	if (do_this_block) // "if" in NED 
	{ 
	gateL = mac_mod->findGate( "toPh" ); 
	check_gate( gateL, "mac", "toPh" ); 
 
	gateR = physic_mod->findGate( "fromMac" ); 
	check_gate( gateR, "physic", "fromMac" ); 
 
	connect (mac_mod, gateL, 
	         NULL, 
	         physic_mod, gateR); 
 
	mac_mod->gate(gateL)->setDisplayString( "m=m,24,12,24,12" ); 
	check_error(); check_memory(); 
	} // end-if 
 
 
	do_this_block = true; // no "if" condition 
	if (do_this_block) // "if" in NED 
	{ 
	gateL = physic_mod->findGate( "toMac" ); 
	check_gate( gateL, "physic", "toMac" ); 
 
	gateR = mac_mod->findGate( "fromPh" ); 
	check_gate( gateR, "mac", "fromPh" ); 
 
	connect (physic_mod, gateL, 
	         NULL, 
	         mac_mod, gateR); 
 
	physic_mod->gate(gateL)->setDisplayString( "m=m,80,0,80,8" ); 
	check_error(); check_memory(); 
	} // end-if 
 
 
	do_this_block = true; // no "if" condition 
	if (do_this_block) // "if" in NED 
	{ 
	gateL = mobility_mod->findGate( "out" ); 
	check_gate( gateL, "mobility", "out" ); 
 
	gateR = physic_mod->findGate( "fromMobility" ); 
	check_gate( gateR, "physic", "fromMobility" ); 
 
	connect (mobility_mod, gateL, 
	         NULL, 
	         physic_mod, gateR); 
 
	mobility_mod->gate(gateL)->setDisplayString( "m=m,64,8,88,44" ); 
	check_error(); check_memory(); 
	} // end-if 
 
	mod->setDisplayString(dispENCLOSINGMOD, "p=10,10;b=287,250" ); 
 
	mod->checkInternalConnections(); 
	check_error(); check_memory(); 
}