SensorList.cc 3.69 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 10 11 12 13 14
#include "PacketSensor.h"
#include "DelaySensor.h"
#include "MinDelaySensor.h"
#include "MaxDelaySensor.h"
#include "ThroughputSensor.h"

15 16 17 18
using namespace std;

SensorList::SensorList()
{
19
  reset();
20 21 22 23
}

SensorList::SensorList(SensorList const & right)
{
24 25 26 27 28 29 30
  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();
31 32 33 34
}

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

void SensorList::addSensor(SensorCommand const & newSensor)
{
50 51 52
  // Add dependency type demux here.
  switch(newSensor.type)
  {
53
  case NULL_SENSOR:
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    pushNullSensor();
    break;
  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();
70
    break;
71 72 73 74 75 76
  default:
    logWrite(ERROR,
             "Incorrect sensor type (%d). Ignoring add sensor command.",
             newSensor.type);
    break;
  }
77 78 79 80
}

Sensor * SensorList::getHead(void)
{
81
  return head.get();
82 83
}

84
void SensorList::reset(void)
85 86 87 88 89
{
  head.reset(NULL);
  tail = NULL;
  // Dependency = NULL here
  depNullSensor = NULL;
90 91 92
  depPacketSensor = NULL;
  depDelaySensor = NULL;
  depThroughputSensor = NULL;
93 94
}

95
void SensorList::pushSensor(std::auto_ptr<Sensor> newSensor)
96
{
97 98 99 100 101 102 103 104 105
  if (tail != NULL)
  {
    tail->addNode(newSensor);
  }
  else
  {
    head = newSensor;
    tail = head.get();
  }
106 107 108 109
}

// Add individual pushSensor functions here.

110
void SensorList::pushNullSensor(void)
111 112 113 114 115 116 117 118 119 120 121 122 123 124
{
  // Dependency list

  // Example dependency check
  if (depNullSensor == NULL)
  {
    NullSensor * newSensor = new NullSensor();
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depNullSensor = newSensor;
  }
}
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

void SensorList::pushPacketSensor(void)
{
  // Dependency list

  // Example dependency check
  if (depPacketSensor == NULL)
  {
    PacketSensor * newSensor = new PacketSensor();
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depPacketSensor = newSensor;
  }
}

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

  // Example dependency check
  if (depDelaySensor == NULL)
  {
    DelaySensor * newSensor = new DelaySensor(depPacketSensor);
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depDelaySensor = newSensor;
  }
}

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

  std::auto_ptr<Sensor> current(new MinDelaySensor(depDelaySensor));
  pushSensor(current);
}

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

  std::auto_ptr<Sensor> current(new MaxDelaySensor(depDelaySensor));
  pushSensor(current);
}

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

  // Example dependency check
  if (depThroughputSensor == NULL)
  {
    ThroughputSensor * newSensor = new ThroughputSensor(depPacketSensor);
    std::auto_ptr<Sensor> current(newSensor);
    pushSensor(current);

    // Example dependency set
    depThroughputSensor = newSensor;
  }
}