#ifndef _MODEMBROKER_H
#define _MODEMBROKER_H

#include "Modem.h"
#include "ModemMessage.h"
#include <list>

class Modem;

typedef list<ModemMessage*> MessageBufferList;
typedef list<Modem*> ModemList;

class ModemBroker {

public:

  ModemBroker();
  virtual ~ModemBroker();
  
  static ModemBroker* getModemBroker();

    ///////////////////////////////////////////////////////////////////
  // addModem - adds the modem to the ModemController.
  //  Controller will delete the modem upon destruction.
  virtual void addModem(Modem* pModem);

  ///////////////////////////////////////////////////////////////////
  // delete - removes the modem from the ModemController.
  virtual void removeModem(Modem* pModem);

	// in this case, send the message right away
  virtual void addMessage(ModemMessage *pMessage);

  ///////////////////////////////////////////////////////////////////
  // runCycle - a single iteration of the modem run cycle.
  virtual void runCycle();
  
  ///////////////////////////////////////////////////////////////////
  // handleIncomingData - deals with incoming data
  virtual void handleIncomingData();

///////////////////////////////////////////////////////////////////
  // handleOutgoingData - deals with outgoing data
  virtual void handleOutgoingData();

    ///////////////////////////////////////////////////////////////////
  // choose which modem is best for sending right now
  virtual void selectSendingModem();
  
  // Are we connected?
  virtual bool hasConnection();

  virtual long getBytesPerSecond();

 protected:

  Modem* _pSendingModem;    // the modem currently in use for sending
  ModemList _pmlModems;  // the modems available to the controller

  MessageBufferList _msPendingMessages;   // messages that we need to send
  
  // Friends!
  friend class Modem;
  friend class ModemSocket;

 private:
  debug_t debug;
	static ModemBroker* _pgModemBroker;
};  


#endif
