#include <ChannelInstaller.h>
This module is a temporary solution until the NED infrastructure gets extended to accomodate channel classes.
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual cChannel * | createReplacementChannelFor (cChannel *channel) |
cChannel * ChannelInstaller::createReplacementChannelFor | ( | cChannel * | channel | ) | [protected, virtual] |
00047 { 00048 cBasicChannel *oldchan = dynamic_cast<cBasicChannel *>(channel); 00049 if (!oldchan) 00050 return channel; 00051 00052 // create new channel object of the given class, and take over the original object's attributes 00053 const char *channelClassName = par("channelClass"); 00054 cBasicChannel *newchan = check_and_cast<cBasicChannel *>(createOne(channelClassName)); 00055 newchan->setName(oldchan->name()); 00056 newchan->setError(oldchan->error()); 00057 newchan->setDelay(oldchan->delay()); 00058 newchan->setDatarate(oldchan->datarate()); 00059 00060 // parse the "attr=value;attr=value;.." string, and set the given attributes on the channel 00061 const char *attrs = par("channelAttrs"); 00062 cStringTokenizer tok(attrs,";"); 00063 while (tok.hasMoreTokens()) 00064 { 00065 cStringTokenizer tok2(tok.nextToken(), "="); 00066 const char *attrname = tok2.nextToken(); 00067 const char *value = tok2.nextToken(); 00068 cPar& p = newchan->addPar(attrname); 00069 if (!p.setFromText(value)) 00070 p.setStringValue(value); 00071 } 00072 00073 return newchan; 00074 }
void ChannelInstaller::initialize | ( | ) | [protected, virtual] |
00025 { 00026 int count = 0; 00027 for (int i=0; i<=simulation.lastModuleId(); i++) 00028 { 00029 cModule *mod = simulation.module(i); 00030 if (!mod) continue; 00031 int numGates = mod->gates(); 00032 for (int j=0; j<numGates; j++) 00033 { 00034 cGate *g = mod->gate(j); 00035 if (!g) continue; 00036 cChannel *channel = g->channel(); 00037 if (!channel) continue; 00038 g->setChannel(createReplacementChannelFor(channel)); 00039 count++; 00040 } 00041 } 00042 00043 EV << "ChannelInstaller replaced " << count << " channel objects.\n"; 00044 }