#include <ScenarioManager.h>
See NED file for details.
Public Member Functions | |
| ScenarioManager () | |
Protected Member Functions | |
| const char * | getRequiredAttribute (cXMLElement *node, const char *attr) |
| cModule * | getRequiredModule (cXMLElement *node, const char *attr) |
| cGate * | getRequiredGate (cXMLElement *node, const char *modattr, const char *gateattr) |
| void | processCommand (cXMLElement *node) |
| void | processAtCommand (cXMLElement *node) |
| void | processSetParamCommand (cXMLElement *node) |
| void | processSetChannelAttrCommand (cXMLElement *node) |
| void | processCreateModuleCommand (cXMLElement *node) |
| void | processDeleteModuleCommand (cXMLElement *node) |
| void | processConnectCommand (cXMLElement *node) |
| void | processDisconnectCommand (cXMLElement *node) |
| void | processModuleSpecificCommand (cXMLElement *node) |
| virtual void | initialize () |
| virtual void | handleMessage (cMessage *msg) |
| void | updateDisplayString () |
Protected Attributes | |
| int | numChanges |
| int | numDone |
|
|
00066 {}
|
|
||||||||||||
|
00101 {
00102 const char *s = node->getAttribute(attr);
00103 if (!s)
00104 error("required attribute %s of <%s> missing at %s",
00105 attr, node->getTagName(), node->getSourceLocation());
00106 return s;
00107 }
|
|
||||||||||||||||
|
00119 {
00120 cModule *mod = getRequiredModule(node, modAttr);
00121 const char *gateStr = getRequiredAttribute(node, gateAttr);
00122 std::string gname;
00123 int gindex;
00124 cGate *g = parseIndexedName(gateStr, gname, gindex) ? mod->gate(gname.c_str(), gindex) : mod->gate(gname.c_str());
00125 if (!g)
00126 error("module '%s' has no gate '%s' at %s", mod->fullPath().c_str(), gateStr, node->getSourceLocation());
00127 return g;
00128 }
|
|
||||||||||||
|
00110 {
00111 const char *moduleAttr = getRequiredAttribute(node, attr);
00112 cModule *mod = simulation.moduleByPath(moduleAttr);
00113 if (!mod)
00114 error("module '%s' not found at %s", moduleAttr, node->getSourceLocation());
00115 return mod;
00116 }
|
|
|
00053 {
00054 cXMLElement *node = (cXMLElement *) msg->contextPointer();
00055 delete msg;
00056
00057 processCommand(node);
00058
00059 numDone++;
00060 updateDisplayString();
00061 }
|
|
|
00025 {
00026 cXMLElement *script = par("script");
00027
00028 numChanges = numDone = 0;
00029 WATCH(numChanges);
00030 WATCH(numDone);
00031
00032 for (cXMLElement *node=script->getFirstChild(); node; node = node->getNextSibling())
00033 {
00034 // check attr t is present
00035 const char *tAttr = node->getAttribute("t");
00036 if (!tAttr)
00037 error("attribute 't' missing at %s", node->getSourceLocation());
00038
00039 // schedule self-message
00040 simtime_t t = strToSimtime(tAttr);
00041 cMessage *msg = new cMessage("scenario-event");
00042 msg->setContextPointer(node);
00043 scheduleAt(t, msg);
00044
00045 // count it
00046 numChanges++;
00047 }
00048
00049 updateDisplayString();
00050 }
|
|
|
00131 {
00132 for (cXMLElement *child=node->getFirstChild(); child; child=child->getNextSibling())
00133 processCommand(child);
00134 }
|
|
|
00064 {
00065 const char *tag = node->getTagName();
00066 EV << "processing <" << tag << "> command...\n";
00067
00068 if (!strcmp(tag,"at"))
00069 processAtCommand(node);
00070 else if (!strcmp(tag,"set-param"))
00071 processSetParamCommand(node);
00072 else if (!strcmp(tag,"set-channel-attr"))
00073 processSetChannelAttrCommand(node);
00074 // else if (!strcmp(tag,"create-module"))
00075 // processCreateModuleCommand(node);
00076 // else if (!strcmp(tag,"connect"))
00077 // processConnectCommand(node);
00078 else
00079 processModuleSpecificCommand(node);
00080 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
00137 {
00138 // find which module we'll need to invoke
00139 cModule *mod = getRequiredModule(node, "module");
00140
00141 // see if it supports the IScriptable interface
00142 IScriptable *scriptable = dynamic_cast<IScriptable *>(mod);
00143 if (!scriptable)
00144 error("<%s> not understood: it is not a built-in command of %s, and module class %s "
00145 "is not scriptable (does not subclass from IScriptable) at %s",
00146 node->getTagName(), className(), mod->className(), node->getSourceLocation());
00147
00148 // ok, trust it to process this command
00149 scriptable->processCommand(*node);
00150 }
|
|
|
00168 {
00169 // process <set-channel-attr> command
00170 cGate *g = getRequiredGate(node, "src-module", "src-gate");
00171 const char *attrAttr = getRequiredAttribute(node, "attr");
00172 const char *valueAttr = getRequiredAttribute(node, "value");
00173
00174 EV << "Setting channel attribute: " << attrAttr << " = " << valueAttr
00175 << " of gate " << g->fullPath() << "\n";
00176 bubble((std::string("setting channel attr: ")+attrAttr+" = "+valueAttr).c_str());
00177
00178 // make sure gate is connected at all
00179 if (!g->toGate())
00180 error("gate '%s' is not connected at %s", g->fullPath().c_str(), node->getSourceLocation());
00181
00182 // find channel (or add one?)
00183 cChannel *chan = g->channel();
00184 if (!chan)
00185 error("connection starting at gate '%s' has no attributes at %s", g->fullPath().c_str(), node->getSourceLocation());
00186
00187 // set the parameter to the given value
00188 if (!chan->hasPar(attrAttr))
00189 chan->addPar(attrAttr);
00190 cPar& param = chan->par(attrAttr);
00191 param.setFromText(valueAttr, '?');
00192 }
|
|
|
00153 {
00154 // process <set-param> command
00155 cModule *mod = getRequiredModule(node, "module");
00156 const char *parAttr = getRequiredAttribute(node, "par");
00157 const char *valueAttr = getRequiredAttribute(node, "value");
00158
00159 EV << "Setting " << mod->fullPath() << "." << parAttr << " = " << valueAttr << "\n";
00160 bubble((std::string("setting: ")+mod->fullPath()+"."+parAttr+" = "+valueAttr).c_str());
00161
00162 // set the parameter to the given value
00163 cPar& param = mod->par(parAttr);
00164 param.setFromText(valueAttr, '?');
00165 }
|
|
|
00210 {
00211 char buf[80];
00212 sprintf(buf, "total %d changes, %d left", numChanges, numChanges-numDone);
00213 displayString().setTagArg("t", 0, buf);
00214 }
|
|
|
|
|
|
|
1.4.1