#include <ANSimMobility.h>
Protected Member Functions | |
virtual void | initialize (int) |
Initializes mobility model parameters. | |
virtual void | setTargetPosition () |
Overridden from LineSegmentsMobilityBase. | |
virtual void | extractDataFrom (cXMLElement *node) |
Utility: extract data from given <position_update> element. | |
virtual void | fixIfHostGetsOutside () |
Overridden from LineSegmentsMobilityBase. | |
Protected Attributes | |
int | nodeId |
we'll have to compare this to the <node_id> elements | |
cXMLElement * | nextPosChange |
points to the next <position_change> element |
void ANSimMobility::initialize | ( | int | stage | ) | [protected, virtual] |
Initializes mobility model parameters.
Reimplemented from LineSegmentsMobilityBase.
00037 { 00038 LineSegmentsMobilityBase::initialize(stage); 00039 00040 EV << "initializing ANSimMobility stage " << stage << endl; 00041 00042 if (stage == 1) 00043 { 00044 nodeId = par("nodeId"); 00045 if (nodeId == -1) 00046 nodeId = getParentModule()->getIndex(); 00047 00048 // get script: param should point to <simulation> element 00049 cXMLElement *rootElem = par("ansimTrace"); 00050 if (strcmp(rootElem->getTagName(),"simulation")!=0) 00051 error("ansimTrace: <simulation> is expected as root element not <%s> at %s", 00052 rootElem->getTagName(), rootElem->getSourceLocation()); 00053 nextPosChange = rootElem->getElementByPath("mobility/position_change"); 00054 if (!nextPosChange) 00055 error("element doesn't have <mobility> child or <position_change> grandchild at %s", 00056 rootElem->getSourceLocation()); 00057 00058 // set initial position; 00059 setTargetPosition(); 00060 pos = targetPos; 00061 updatePosition(); 00062 } 00063 }
void ANSimMobility::setTargetPosition | ( | ) | [protected, virtual] |
Overridden from LineSegmentsMobilityBase.
Implements LineSegmentsMobilityBase.
Referenced by initialize().
00067 { 00068 // find next <position_update> element with matching <node_id> tag (current one also OK) 00069 while (nextPosChange) 00070 { 00071 const char *nodeIdStr = firstChildWithTag(nextPosChange, "node_id")->getNodeValue(); 00072 if (nodeIdStr && atoi(nodeIdStr)==nodeId) 00073 break; 00074 nextPosChange = nextPosChange->getNextSibling(); 00075 } 00076 00077 if (!nextPosChange) 00078 { 00079 stationary = true; 00080 return; 00081 } 00082 00083 // extract data from it 00084 extractDataFrom(nextPosChange); 00085 00086 // skip this one 00087 nextPosChange = nextPosChange->getNextSibling(); 00088 }
void ANSimMobility::extractDataFrom | ( | cXMLElement * | node | ) | [protected, virtual] |
Utility: extract data from given <position_update> element.
Referenced by setTargetPosition().
00091 { 00092 // extract data from <position_update> element 00093 // FIXME start_time has to be taken into account too! as pause from prev element's end_time 00094 const char *startTimeStr = firstChildWithTag(node, "start_time")->getNodeValue(); 00095 const char *endTimeStr = firstChildWithTag(node, "end_time")->getNodeValue(); 00096 cXMLElement *destElem = firstChildWithTag(node, "destination"); 00097 const char *xStr = firstChildWithTag(destElem, "xpos")->getNodeValue(); 00098 const char *yStr = firstChildWithTag(destElem, "ypos")->getNodeValue(); 00099 00100 if (!endTimeStr || !xStr || !yStr) 00101 error("no content in <end_time>, <destination>/<xpos> or <ypos> element at %s", node->getSourceLocation()); 00102 00103 targetTime = atof(endTimeStr); 00104 targetPos.x = atof(xStr); 00105 targetPos.y = atof(yStr); 00106 }
void ANSimMobility::fixIfHostGetsOutside | ( | ) | [protected, virtual] |
Overridden from LineSegmentsMobilityBase.
Implements LineSegmentsMobilityBase.
00109 { 00110 raiseErrorIfOutside(); 00111 }
int ANSimMobility::nodeId [protected] |
we'll have to compare this to the <node_id> elements
Referenced by initialize(), and setTargetPosition().
cXMLElement* ANSimMobility::nextPosChange [protected] |