TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
RCBuffer.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "RCBuffer.h"
17 #include <CTFrame_m.h>
18 #include <TTEScheduler.h>
19 #include "TTEApplicationBase.h"
20 
21 namespace TTEthernetModel {
22 
23 Define_Module( RCBuffer);
24 
26 {
27  bagExpired = true;
28  timerMessage = new SchedulerTimerEvent("RCBuffer Scheduler Event", TIMER_EVENT);
29 }
30 
32 {
33  cancelEvent(timerMessage);
34  delete timerMessage;
35 }
36 
38 {
40  return CTBuffer::numInitStages();
41  else
42  return 1;
43 }
44 
45 void RCBuffer::initialize(int stage)
46 {
47  CTBuffer::initialize(stage);
48  if(stage==0){
49  timerMessage->setDestinationGate(gate("schedulerIn"));
50 
51  //Update displaystring
52  setIsEmpty(true);
53  }
54 }
55 
56 void RCBuffer::handleMessage(cMessage *msg)
57 {
59 
60  if(destinationGates.size() > 0)
61  {
62  if (msg->arrivedOn("in"))
63  {
64  if (bagExpired)
65  {
66  cMessage *outgoingMessage = getFrame();
67  if(outgoingMessage){
68  bagExpired = false;
69  numReset = 0;
70  //Send Message
71  for (std::list<cGate*>::iterator dgate = destinationGates.begin(); dgate != destinationGates.end(); ++dgate)
72  {
73  sendDirect(outgoingMessage->dup(),0,0, *dgate);
74  }
75  if(gate("out")->isConnected()){
76  send(outgoingMessage->dup(),"out");
77  }
79  delete outgoingMessage;
80  }
81  }
82  }
83  else if (msg->arrivedOn("schedulerIn") && msg->getKind() == TIMER_EVENT)
84  {
85  cMessage *outgoingMessage = getFrame();
86  if (outgoingMessage)
87  {
88  bagExpired = false;
89  numReset = 0;
90  //Send Message
91  for (std::list<cGate*>::iterator gate = destinationGates.begin(); gate != destinationGates.end(); ++gate)
92  {
93  sendDirect(outgoingMessage->dup(), *gate);
94  }
96  delete outgoingMessage;
97  }
98  else
99  {
100  bagExpired = true;
101  getDisplayString().setTagArg("i2", 0, "");
102  }
103  }
104  }
105 }
106 
107 void RCBuffer::handleParameterChange(const char* parname){
109 
110  timerMessage->setTimer(par("bag").doubleValue());
111 }
112 
114 {
115  Enter_Method("resetBag()");
116  //This is the moment when the message was transmitted execute transmit callbacks if there are some
117  for(std::map<TTEApplicationBase*,Callback*>::const_iterator iter = transmitCallbacks.begin();
118  iter != transmitCallbacks.end(); ++iter){
119  iter->first->executeCallback(iter->second);
120  }
121 
122  //Set icon:
123  getDisplayString().setTagArg("i2", 0, "status/hourglass");
124 
125  numReset++;
126  if (numReset == destinationGates.size())
127  {
128  //Reregister scheduler
129  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
130  tteScheduler->registerEvent(timerMessage);
131  }
132 }
133 
134 } //namespace