RealWorldTestApp.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include <IPAddressResolver.h>
00025 #include <CommonMessages_m.h>
00026
00027
00028 #include "RealWorldTestApp.h"
00029 #include "RealWorldTestMessage_m.h"
00030
00031
00032 Define_Module(RealWorldTestApp);
00033
00034
00035 void RealWorldTestApp::initializeApp(int stage)
00036 {
00037 if (stage != MIN_STAGE_APP)
00038 return;
00039
00040 displayMsg = new cMessage("DISPLAY");
00041 }
00042
00043 void RealWorldTestApp::finishApp()
00044 {
00045 cancelAndDelete(displayMsg);
00046 }
00047
00048 void RealWorldTestApp::deliver(OverlayKey& key, cMessage* msg)
00049 {
00050 RealWorldTestMessage* testMsg = check_and_cast<RealWorldTestMessage*>(msg);
00051 OverlayCtrlInfo* overlayCtrlInfo =
00052 check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
00053
00054 if(std::string(testMsg->getName()) == "CALL") {
00055
00056
00057
00058
00059 std::string tempString = "Message received: \"" + std::string(testMsg->getMsg()) + "\"";
00060
00061 getParentModule()->getParentModule()->bubble(tempString.c_str());
00062
00063
00064 getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "green");
00065
00066 if(displayMsg->isScheduled())
00067 cancelEvent(displayMsg);
00068 scheduleAt(simTime() + 2, displayMsg);
00069
00070
00071 RealWorldTestMessage* answerMsg = new RealWorldTestMessage("ANSWER");
00072
00073
00074
00075 tempString = "Reply to: \"" + std::string(testMsg->getMsg()) + "\" from "
00076 + overlay->getThisNode().getAddress().str();
00077
00078 answerMsg->setMsg(tempString.c_str());
00079 callRoute(overlayCtrlInfo->getSrcNode().getKey(), answerMsg, overlayCtrlInfo->getSrcNode());
00080
00081 delete testMsg;
00082 } else if(std::string(testMsg->getName()) == "ANSWER") {
00083 if(gate("to_upperTier")->getNextGate()->isConnectedOutside())
00084 send(msg, "to_upperTier");
00085 else
00086 delete msg;
00087 }
00088
00089 delete overlayCtrlInfo;
00090 }
00091
00092 void RealWorldTestApp::handleUpperMessage(cMessage* msg)
00093 {
00094 RealWorldTestMessage* callMsg = check_and_cast<RealWorldTestMessage*>(msg);
00095 callMsg->setName("CALL");
00096 callRoute(OverlayKey::sha1(const_cast<char*>(callMsg->getMsg())), callMsg);
00097 }
00098
00099 void RealWorldTestApp::handleTimerEvent(cMessage* msg)
00100 {
00101 getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "");
00102 }