/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef INCLUDED_PacketMux_h
#define INCLUDED_PacketMux_h

#include <vector>

using std::vector;

class RobotDataPacket;
class PacketStream;
class PacketStreamCollection;

/*------------------------------------------------------------------
CLASS
  PacketMux

DESCRIPTION
  Muxes independent packet streams into a single stream.
------------------------------------------------------------------*/
class PacketMux {
public:
  PacketMux() {};
  virtual ~PacketMux() {};

  virtual void addPSC(PacketStreamCollection *psc) = 0;

  virtual bool getNextPacket(RobotDataPacket *packet, int data_length) = 0;
};

/*------------------------------------------------------------------
CLASS
  PacketMuxRoundRobin

DESCRIPTION
  Muxes independent packet streams into a single stream.  Uses a
round robin scheduling algorithm.
------------------------------------------------------------------*/
class PacketMuxRoundRobin : public PacketMux {
public:
  PacketMuxRoundRobin();
  virtual ~PacketMuxRoundRobin() {};

  virtual void addPSC(PacketStreamCollection *psc);

  virtual bool getNextPacket(RobotDataPacket *packet, int data_length);

protected:
private: // methods
private: // data
  vector<PacketStream *> streams;
  vector<int> nextPackets;
  uint nextStream;
};

/*------------------------------------------------------------------
CLASS
  PacketMuxFIFO

DESCRIPTION
  Muxes independent packet streams into a single stream.  Uses a
FIFO scheduling algorithm.
------------------------------------------------------------------*/
class PacketMuxFIFO : public PacketMux {
public:
  PacketMuxFIFO();
  virtual ~PacketMuxFIFO() {};

  virtual void addPSC(PacketStreamCollection *psc);

  virtual bool getNextPacket(RobotDataPacket *packet, int data_length);

protected:
private: // methods
private: // data
  vector<PacketStream *> streams;
  vector<int> nextPackets;
};

#endif
