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 
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         // bubble
00056         //std::string tempString = "Call for key (" + key.toString() +
00057         //") with message: \"" + testMsg->getMessage() + "\"";
00058 
00059         std::string tempString = "Message received: \"" + std::string(testMsg->getMsg()) + "\"";
00060 
00061         getParentModule()->getParentModule()->bubble(tempString.c_str());
00062 
00063         // change color
00064         getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "green");
00065 
00066         if(displayMsg->isScheduled())
00067             cancelEvent(displayMsg);
00068         scheduleAt(simTime() + 2, displayMsg);
00069 
00070         // send back
00071         RealWorldTestMessage* answerMsg = new RealWorldTestMessage("ANSWER");
00072         //tempString = "Reply to: \"" + std::string(testMsg->getMessage()) + "\" from "
00073         //    + overlayCtrlInfo->getThisNode().getKey().toString();
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 }
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3