#include <TopologyVis.h>
Public Member Functions | |
TopologyVis () | |
Protected Member Functions | |
void | initVis (cModule *terminal) |
void | showOverlayNeighborArrow (const NodeHandle &neighbor, bool flush=true, const char *displayString=NULL) |
Draws an arrow from this node to neighbor. | |
void | deleteOverlayNeighborArrow (const NodeHandle &neighbor) |
Removes an arrow from this node to neighbor. | |
Protected Attributes | |
cModule * | thisTerminal |
BootstrapOracle * | bootstrapOracle |
pointer to corresponding node | |
cGate * | thisOutGateArray |
cGate * | thisInGateArray |
Private Member Functions | |
void | compactGateArray (cModule *terminal, enum VisDrawDirection dir) |
compacts arrow gate-array |
TopologyVis::TopologyVis | ( | ) |
void TopologyVis::initVis | ( | cModule * | terminal | ) | [protected] |
Referenced by BaseOverlay::initialize().
00040 { 00041 thisTerminal = terminal; 00042 bootstrapOracle = BootstrapOracleAccess().get(); 00043 00044 // set up arrow-gates 00045 thisOutGateArray = thisTerminal->gate("overlayNeighborArrowOut"); 00046 thisInGateArray = thisTerminal->gate("overlayNeighborArrowIn"); 00047 thisTerminal->setGateSize("overlayNeighborArrowOut", 1); 00048 thisTerminal->setGateSize("overlayNeighborArrowIn", 1); 00049 00050 }
void TopologyVis::showOverlayNeighborArrow | ( | const NodeHandle & | neighbor, | |
bool | flush = true , |
|||
const char * | displayString = NULL | |||
) | [protected] |
Draws an arrow from this node to neighbor.
neighbor | neighbor to point to | |
flush | delete all previous drawn arrows starting at this node? | |
displayString | display string to define the arrow drawing style |
Referenced by Gia::addNeighbor(), Gia::changeState(), Kademlia::handleFailedNode(), Kademlia::routingAdd(), Kademlia::routingTimeout(), Koorde::updateTooltip(), Chord::updateTooltip(), and BasePastry::updateTooltip().
00054 { 00055 if (!ev.isGUI() || !thisTerminal) 00056 return; 00057 00058 char red[] = "o=red,1"; 00059 if (displayString == NULL) 00060 displayString = red; 00061 00062 cModule* neighborTerminal; 00063 cGate* neighborInGateArray; 00064 00065 // flush 00066 if (flush) { 00067 for (int l = 0; l < thisOutGateArray->size(); l++) { 00068 cGate* tempGate = 00069 thisTerminal->gate("overlayNeighborArrowOut", l)->toGate(); 00070 00071 thisTerminal->gate("overlayNeighborArrowOut", l)->disconnect(); 00072 if (tempGate != NULL) 00073 compactGateArray(tempGate->ownerModule(), IN); 00074 } 00075 thisTerminal->setGateSize("overlayNeighborArrowOut" ,0); 00076 } 00077 00078 if (bootstrapOracle->getPeerInfo(neighbor) == NULL) 00079 return; 00080 00081 neighborTerminal 00082 = simulation.module(bootstrapOracle 00083 ->getPeerInfo(neighbor)->getModuleID()); 00084 if (neighborTerminal != NULL) { 00085 neighborInGateArray = neighborTerminal->gate("overlayNeighborArrowIn"); 00086 } else 00087 return; 00088 00089 if (thisTerminal == neighborTerminal) 00090 return; 00091 00092 //do not draw double 00093 for (int i = 0; i < thisOutGateArray->size(); i++) 00094 if (thisTerminal->gate("overlayNeighborArrowOut", i) 00095 ->toGate() != NULL && 00096 neighborTerminal == thisTerminal 00097 ->gate("overlayNeighborArrowOut", i) 00098 ->toGate()->ownerModule()) 00099 return; 00100 00101 // IN 00102 int i = 0; 00103 if (neighborInGateArray->size() == 0) { 00104 neighborTerminal->setGateSize("overlayNeighborArrowIn", 1); 00105 } else { 00106 for (i = 0; i < neighborInGateArray->size() - 1; i++) { 00107 if (!(neighborTerminal->gate("overlayNeighborArrowIn", i) 00108 ->isConnectedOutside())) 00109 break; 00110 } 00111 if (neighborTerminal->gate("overlayNeighborArrowIn", i) 00112 ->isConnectedOutside()) { 00113 neighborTerminal->setGateSize("overlayNeighborArrowIn", i + 2); 00114 i++; 00115 } 00116 } 00117 00118 // OUT 00119 int j = 0; 00120 if (thisOutGateArray->size() == 0) 00121 thisTerminal->setGateSize("overlayNeighborArrowOut", 1); 00122 else { 00123 for (j = 0; j < (thisOutGateArray->size() - 1); j++) { 00124 if (!(thisTerminal->gate("overlayNeighborArrowOut", j) 00125 ->isConnectedOutside())) 00126 break; 00127 } 00128 if (thisTerminal->gate("overlayNeighborArrowOut", j) 00129 ->isConnectedOutside()) { 00130 thisTerminal->setGateSize("overlayNeighborArrowOut", j + 2); 00131 j++; 00132 } 00133 } 00134 00135 thisTerminal->gate("overlayNeighborArrowOut", j)-> 00136 connectTo(neighborTerminal->gate("overlayNeighborArrowIn", i)); 00137 00138 thisTerminal->gate("overlayNeighborArrowOut", j)-> 00139 setDisplayString(displayString); 00140 }
void TopologyVis::deleteOverlayNeighborArrow | ( | const NodeHandle & | neighbor | ) | [protected] |
Removes an arrow from this node to neighbor.
neighbor | neighbor to remove arrow to |
Referenced by Kademlia::handleFailedNode(), Gia::removeNeighbor(), Kademlia::routingAdd(), and Kademlia::routingTimeout().
00143 { 00144 if (!ev.isGUI() || !thisTerminal) 00145 return; 00146 00147 PeerInfo* peerInfo = bootstrapOracle->getPeerInfo(neighbor); 00148 if (peerInfo == NULL) { 00149 return; 00150 } 00151 00152 cModule* neighborTerminal = simulation.module(peerInfo->getModuleID()); 00153 if (neighborTerminal == NULL) { 00154 return; 00155 } 00156 00157 //find gate 00158 bool compactOut = false; 00159 bool compactIn = false; 00160 for (int i = 0; i < thisOutGateArray->size(); i++) { 00161 // NULL-Gate? 00162 if (thisTerminal->gate("overlayNeighborArrowOut", i) 00163 ->toGate() == NULL) { 00164 compactOut = true; 00165 continue; 00166 } 00167 00168 if (thisTerminal->gate("overlayNeighborArrowOut", i) 00169 ->toGate()->ownerModule()->id() == neighborTerminal->id()) { 00170 thisTerminal->gate("overlayNeighborArrowOut", i)->disconnect(); 00171 compactOut = true; 00172 compactIn = true; 00173 } 00174 } 00175 00176 //compact OUT-array 00177 if (compactOut) 00178 compactGateArray(thisTerminal, OUT); 00179 //compact IN-array 00180 if (compactIn) 00181 compactGateArray(neighborTerminal, IN); 00182 }
void TopologyVis::compactGateArray | ( | cModule * | terminal, | |
enum VisDrawDirection | dir | |||
) | [private] |
compacts arrow gate-array
terminal | node | |
dir | in- or out-array? |
Referenced by deleteOverlayNeighborArrow(), and showOverlayNeighborArrow().
00186 { 00187 cGate* gateArray = (dir == OUT ? terminal->gate("overlayNeighborArrowOut") 00188 : terminal->gate("overlayNeighborArrowIn")); 00189 const char* gateName = (dir == OUT ? "overlayNeighborArrowOut" 00190 : "overlayNeighborArrowIn"); 00191 00192 for (int j = 0; j < gateArray->size() - 1; j++) { 00193 if (terminal->gate(gateName, j)->isConnectedOutside()) 00194 continue; 00195 00196 cGate* tempGate = NULL; 00197 int k = 1; 00198 while ((tempGate == NULL) && ((j + k) != gateArray->size())) { 00199 tempGate = (dir == OUT ? 00200 terminal->gate(gateName, j + k)->toGate() : 00201 terminal->gate(gateName, j + k)->fromGate()); 00202 k++; 00203 } 00204 00205 if (tempGate == NULL) 00206 break; 00207 00208 if (dir == OUT) { 00209 terminal->gate(gateName, j + k - 1)->disconnect(); 00210 terminal->gate(gateName, j)->connectTo(tempGate); 00211 } else { 00212 tempGate->disconnect(); 00213 tempGate->connectTo(terminal->gate(gateName, j)); 00214 } 00215 } 00216 00217 int nullGates = 0; 00218 for (int j = 0; j < gateArray->size(); j++) 00219 if (!terminal->gate(gateName, j)->isConnectedOutside()) 00220 nullGates++; 00221 00222 terminal->setGateSize(gateName, gateArray->size() - nullGates); 00223 }
cModule* TopologyVis::thisTerminal [protected] |
Referenced by deleteOverlayNeighborArrow(), initVis(), showOverlayNeighborArrow(), and TopologyVis().
BootstrapOracle* TopologyVis::bootstrapOracle [protected] |
pointer to corresponding node
Reimplemented in BaseOverlay.
Referenced by deleteOverlayNeighborArrow(), initVis(), showOverlayNeighborArrow(), and TopologyVis().
cGate* TopologyVis::thisOutGateArray [protected] |
Referenced by deleteOverlayNeighborArrow(), initVis(), and showOverlayNeighborArrow().
cGate* TopologyVis::thisInGateArray [protected] |
Referenced by initVis().