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