RealWorldTestApp.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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         // bubble
00055         //std::string tempString = "Call for key (" + key.toString() +
00056         //") with message: \"" + testMsg->getMessage() + "\"";
00057 
00058         std::string tempString = "Message received: \"" + std::string(testMsg->getMsg()) + "\"";
00059 
00060         getParentModule()->getParentModule()->bubble(tempString.c_str());
00061 
00062         // change color
00063         getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "green");
00064 
00065         if(displayMsg->isScheduled())
00066             cancelEvent(displayMsg);
00067         scheduleAt(simTime() + 2, displayMsg);
00068 
00069         // send back
00070         RealWorldTestMessage* answerMsg = new RealWorldTestMessage("ANSWER");
00071         //tempString = "Reply to: \"" + std::string(testMsg->getMessage()) + "\" from "
00072         //    + overlayCtrlInfo->getThisNode().getKey().toString();
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 }

Generated on Wed Mar 25 16:32:49 2009 for OverSim by  doxygen 1.5.5