OverSim
RealWorldTestApp.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #include <IPAddressResolver.h>
25 #include <CommonMessages_m.h>
26 
27 
28 #include "RealWorldTestApp.h"
29 #include "RealWorldTestMessage_m.h"
30 
31 
33 
34 
36 {
37  if (stage != MIN_STAGE_APP)
38  return;
39 
40  displayMsg = new cMessage("DISPLAY");
41 }
42 
44 {
45  cancelAndDelete(displayMsg);
46 }
47 
48 void RealWorldTestApp::deliver(OverlayKey& key, cMessage* msg)
49 {
50  RealWorldTestMessage* testMsg = check_and_cast<RealWorldTestMessage*>(msg);
51  OverlayCtrlInfo* overlayCtrlInfo =
52  check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
53 
54  if(std::string(testMsg->getName()) == "CALL") {
55  // bubble
56  //std::string tempString = "Call for key (" + key.toString() +
57  //") with message: \"" + testMsg->getMessage() + "\"";
58 
59  std::string tempString = "Message received: \"" + std::string(testMsg->getMsg()) + "\"";
60 
61  getParentModule()->getParentModule()->bubble(tempString.c_str());
62 
63  // change color
64  getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "green");
65 
66  if(displayMsg->isScheduled())
67  cancelEvent(displayMsg);
68  scheduleAt(simTime() + 2, displayMsg);
69 
70  // send back
71  RealWorldTestMessage* answerMsg = new RealWorldTestMessage("ANSWER");
72  //tempString = "Reply to: \"" + std::string(testMsg->getMessage()) + "\" from "
73  // + overlayCtrlInfo->getThisNode().getKey().toString();
74 
75  tempString = "Reply to: \"" + std::string(testMsg->getMsg()) + "\" from "
76  + overlay->getThisNode().getIp().str();
77 
78  answerMsg->setMsg(tempString.c_str());
79  callRoute(overlayCtrlInfo->getSrcNode().getKey(), answerMsg, overlayCtrlInfo->getSrcNode());
80 
81  delete testMsg;
82  } else if(std::string(testMsg->getName()) == "ANSWER") {
83  if(gate("to_upperTier")->getNextGate()->isConnectedOutside())
84  send(msg, "to_upperTier");
85  else
86  delete msg;
87  }
88 
89  delete overlayCtrlInfo;
90 }
91 
93 {
94  RealWorldTestMessage* callMsg = check_and_cast<RealWorldTestMessage*>(msg);
95  callMsg->setName("CALL");
96  callRoute(OverlayKey::sha1(std::string(callMsg->getMsg())), callMsg);
97 }
98 
100 {
101  getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "");
102 }