SensorList.cc 5.04 KB
Newer Older
1 2 3
// SensorList.cc

#include "lib.h"
4
#include "log.h"
5
#include "SensorList.h"
6 7
#include "Sensor.h"
#include "Command.h"
8

9
#include "StateSensor.h"
10 11 12 13 14
#include "PacketSensor.h"
#include "DelaySensor.h"
#include "MinDelaySensor.h"
#include "MaxDelaySensor.h"
#include "ThroughputSensor.h"
15
#include "EwmaThroughputSensor.h"
16

17 18 19 20
using namespace std;

SensorList::SensorList()
{
21
  reset();
22 23 24 25
}

SensorList::SensorList(SensorList const & right)
{
26 27 28 29 30 31 32
  if (right.head.get() != NULL)
  {
    logWrite(ERROR, "SensorList copy constructed after setup. "
             "This shouldn't have been able to happen. "
             "Sensors have been lost.");
  }
  reset();
33 34 35 36
}

SensorList & SensorList::operator=(SensorList const & right)
{
37 38 39
  if (this != &right)
  {
    if (right.head.get() != NULL)
40
    {
41 42 43
      logWrite(ERROR, "SensorList assigned after setup. "
               "This shouldn't have been able to happen. "
               "Sensors have been lost.");
44
    }
45
    reset();
46 47
  }
  return *this;
48 49 50 51
}

void SensorList::addSensor(SensorCommand const & newSensor)
{
52 53 54
  // Add dependency type demux here.
  switch(newSensor.type)
  {
55
  case NULL_SENSOR:
56 57
    pushNullSensor();
    break;
58 59 60
  case STATE_SENSOR:
    pushStateSensor();
    break;
61 62 63 64 65 66 67 68 69 70 71 72 73 74
  case PACKET_SENSOR:
    pushPacketSensor();
    break;
  case DELAY_SENSOR:
    pushDelaySensor();
    break;
  case MIN_DELAY_SENSOR:
    pushMinDelaySensor();
    break;
  case MAX_DELAY_SENSOR:
    pushMaxDelaySensor();
    break;
  case THROUGHPUT_SENSOR:
    pushThroughputSensor();
75
    break;
76 77 78
  case EWMA_THROUGHPUT_SENSOR:
    pushEwmaThroughputSensor();
    break;
79 80 81 82 83 84
  default:
    logWrite(ERROR,
             "Incorrect sensor type (%d). Ignoring add sensor command.",
             newSensor.type);
    break;
  }
85 86 87 88
}

Sensor * SensorList::getHead(void)
{
89
  return head.get();
90 91
}

92
void SensorList::reset(void)
93 94 95 96 97
{
  head.reset(NULL);
  tail = NULL;
  // Dependency = NULL here
  depNullSensor = NULL;
98
  depStateSensor = NULL;
99 100 101
  depPacketSensor = NULL;
  depDelaySensor = NULL;
  depThroughputSensor = NULL;
102 103
}

104
void SensorList::pushSensor(std::auto_ptr<Sensor> newSensor)
105
{
106 107 108
  if (tail != NULL)
  {
    tail->addNode(newSensor);
109
    tail = tail->getTail();
110 111 112 113 114 115
  }
  else
  {
    head = newSensor;
    tail = head.get();
  }
116 117 118 119
}

// Add individual pushSensor functions here.

120
void SensorList::pushNullSensor(void)
121 122 123 124 125 126
{
  // Dependency list

  // Example dependency check
  if (depNullSensor == NULL)
  {
127
    logWrite(SENSOR, "Adding NullSensor");
128 129 130 131 132 133 134 135
    NullSensor * newSensor = new NullSensor();
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depNullSensor = newSensor;
  }
}
136

137 138 139
void SensorList::pushStateSensor(void)
{
  // Dependency list
140
  pushNullSensor();
141 142 143 144 145 146 147 148 149 150 151 152 153 154

  // Dependency check
  if (depStateSensor == NULL)
  {
    logWrite(SENSOR, "Adding StateSensor");
    StateSensor * newSensor = new StateSensor();
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Dependency set
    depStateSensor = newSensor;
  }
}

155 156 157
void SensorList::pushPacketSensor(void)
{
  // Dependency list
158
  pushStateSensor();
159 160 161 162

  // Example dependency check
  if (depPacketSensor == NULL)
  {
163 164
    logWrite(SENSOR, "Adding PacketSensor");
    PacketSensor * newSensor = new PacketSensor(depStateSensor);
165 166 167 168 169 170 171 172 173 174 175
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depPacketSensor = newSensor;
  }
}

void SensorList::pushDelaySensor(void)
{
  // Dependency list
176
  pushStateSensor();
177 178 179 180 181
  pushPacketSensor();

  // Example dependency check
  if (depDelaySensor == NULL)
  {
182 183
    logWrite(SENSOR, "Adding DelaySensor");
    DelaySensor * newSensor = new DelaySensor(depPacketSensor, depStateSensor);
184 185 186 187 188 189 190 191 192 193 194 195 196
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depDelaySensor = newSensor;
  }
}

void SensorList::pushMinDelaySensor(void)
{
  // Dependency list
  pushDelaySensor();

197
  logWrite(SENSOR, "Adding MinDelaySensor");
198 199 200 201 202 203 204 205
  std::auto_ptr<Sensor> current(new MinDelaySensor(depDelaySensor));
  pushSensor(current);
}

void SensorList::pushMaxDelaySensor(void)
{
  // Dependency list
  pushDelaySensor();
206
  pushStateSensor();
207

208
  logWrite(SENSOR, "Adding MaxDelaySensor");
209 210
  std::auto_ptr<Sensor> current(new MaxDelaySensor(depDelaySensor,
                                                   depStateSensor));
211 212 213 214 215 216
  pushSensor(current);
}

void SensorList::pushThroughputSensor(void)
{
  // Dependency list
217
  pushStateSensor();
218 219 220 221 222
  pushPacketSensor();

  // Example dependency check
  if (depThroughputSensor == NULL)
  {
223 224 225
    logWrite(SENSOR, "Adding ThroughputSensor");
    ThroughputSensor * newSensor = new ThroughputSensor(depPacketSensor,
                                                        depStateSensor);
226 227 228 229 230 231 232
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depThroughputSensor = newSensor;
  }
}
233 234 235 236 237 238 239 240 241 242

void SensorList::pushEwmaThroughputSensor(void)
{
  // Dependency list
  pushThroughputSensor();

  logWrite(SENSOR, "Adding EwmaThroughputSensor");
  std::auto_ptr<Sensor> current(new EwmaThroughputSensor(depThroughputSensor));
  pushSensor(current);
}