Commit 78482b01 authored by Jonathon Duerig's avatar Jonathon Duerig

First draft of interface between new front-end and new back-end for the delay agent.

parent c91dfc8d
// EventPipe.hh
// A pipe which implements the system by generating events for the old delay agent.
// TEVC example:
// /usr/testbed/bin/tevc -e project/experiment now agent-name MODIFY BANDWIDTH=3455
// or DELAY=34
// or PLR=0.1
#ifndef EVENT_PIPE_HH_DELAY_AGENT_1
#define EVENT_PIPE_HH_DELAY_AGENT_1
class EventPipe : public RootPipe
{
public:
// 'name' will be prefixed with "new-" plus the original agent's
// name. To call the old agent, simply remove the prefix.
EventPipe(std::string const & name);
virtual ~EventPipe();
virtual void reset(void);
virtual void resetParameter(Parameter const & newParameter);
private:
};
#endif
// Parameter.cc
#include "lib.hh"
#include "Parameter.hh"
using namespace std;
Parameter::Parameter(ParameterType newType, int newValue)
: type(newType)
, value(newValue)
{
}
ParameterType Parameter::getType(void) const
{
return type;
}
int Parameter::getValue(void) const
{
return value;
}
// Parameter.hh
// A single discrete parameter which can be modified on a pipe.
#ifndef PARAMETER_HH_DELAY_AGENT_1
#define PARAMETER_HH_DELAY_AGENT_1
class Parameter
{
public:
enum ParameterType
{
BANDWIDTH,
DELAY,
// This is the loss rate in thousandths. 1000 is 100% loss. 1 is 0.1% loss. Etc.
LOSS
};
public:
Parameter(ParameterType newType=DELAY, int newValue=0);
ParameterType getType(void) const;
int getValue(void) const;
private:
ParameterType type;
int value;
};
#endif
// Pipe.cc
#include "lib.hh"
#include "Pipe.hh"
using namespace std;
Pipe::Pipe(RootPipe * newSecret)
{
assert(newSecret != NULL);
secret = newSecret;
}
Pipe::~Pipe()
{
release(secret);
}
Pipe::Pipe(Pipe const & right)
{
right.secret->acquire();
secret = right.secret;
}
Pipe & Pipe::operator=(Pipe const & right)
{
right.secret->acquire();
secret.release();
secret = right.secret;
return *this;
}
void Pipe::reset(void)
{
secret->reset();
}
void Pipe::resetParameter(Parameter const & newParameter)
{
secret->resetParameter(newParameter);
}
// Pipe.hh
// This is the container class for RootPipes. A RootPipe should never
// be created on its own. Rather, it should be created on the heap and
// immediately passed to a Pipe class which manages it.
//
// Example: Pipe current(new RemotePipe(some, args, here));
//
// All of the public functions are dispatches to their equivalents in
// the contained RootPipe.
#ifndef PIPE_HH_DELAY_AGENT_1
#define PIPE_HH_DELAY_AGENT_1
class RootPipe;
class Pipe
{
public:
// Used to create a new Pipe based on a heap-allocated object. Never
// pass NULL to this function.
Pipe(RootPipe * newSecret);
~Pipe();
Pipe(Pipe const & right);
Pipe & operator=(Pipe const & right);
public:
void reset(void);
void resetParameter(Parameter const & newParameter);
private:
Pipe();
private:
RootPipe * secret;
};
#endif
// RootPipe.cc
#include "lib.hh"
#include "RootPipe.hh"
using namespace std;
RootPipe::RootPipe()
: refCount(1)
{
}
RootPipe::~RootPipe()
{
}
void RootPipe::acquire(void)
{
++refCount;
}
void RootPipe::release(void)
{
--refCount;
if (refCount <= 0)
{
delete this;
}
}
// RootPipe.hh
// This is the abstract base class for the pipe interface. This uses a
// reference-counted implementation, so 'RootPipe's should never refer
// to each other.
#ifndef ROOT_PIPE_HH_DELAY_AGENT_1
#define ROOT_PIPE_HH_DELAY_AGENT_1
class RootPipe
{
public:
RootPipe();
virtual ~RootPipe();
// A new reference has been created which refers to this object.
void acquire(void);
// A current reference has been destroyed. Possibly destroys this
// object if the count goes to 0.
void release(void);
public:
// Reset all parameters to their default values.
virtual void reset(void)=0;
// Set a particular parameter to a new value. This is used for
// parameters which have a single discrete value which is discretely
// set and reset.
virtual void resetParameter(Parameter const & newParameter)=0;
private:
mutable int refCount;
};
#endif
// lib.cc
#include "lib.hh"
using namespace std;
namespace g
{
string projectName;
string experimentName;
}
// lib.hh
#ifndef LIB_HH_DELAY_AGENT_1
#define LIB_HH_DELAY_AGENT_1
#include <cassert>
#include <string>
#include <map>
#include <list>
#include <vector>
#include <iostream>
#include <sstream>
namespace g
{
extern std::string projectName;
extern std::string experimentName;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment