
#include "packet.h"
#include "address.h"
//#include "stream.h"
#include "generator.h"
#include "popt.h"

#ifndef PORT_H
#define PORT_H

#define MAX_STREAM_NUM_PER_PORT 16  // but we only allow 1

#define DEFAULT_SEND_PORT 3000
#define DEFAULT_RECV_PORT 4000



/** 
 * Port is an abstract class for the interface to send (send only) a packet, whether UDP, TCP Socket, or IP raw socket.
 * The common funcitons for a port are defiend here:
 * - Send Packet.
 *
 *
 *  In general, port is a duplex entity, but we limit port for sender-only.
    Port is also associated with a pair of address. One Port send to one Address only,
    no matter the address is unicast or broadcast.
*/

class Port
{
public:
  Port();
  virtual ~Port(){}
   /**
    * Function to initialize the port
    */
  virtual void init()=0;
   /**
    * Function to send a packet.
    * The default socket file descriptor will always be used for send()
    * No matter how many streams will be served by this port, only a sockfd used by the port.
    * For TCP, multiple streams are not allowed.
    */
  virtual void sendPacket(Packet *pkt)=0;
   /**
    * Function to close a port
    */
  virtual void closePort()=0;
   /**
    * Function to get the next packet delivery time for a sender port
    */
   //virtual double nextDeliverTime()=0;
 
   /**
    * Function to get Command line Options
    *
    */
   virtual const struct poptOption* getOptions()=0;
  
   //void pickPacket();
   //bool readyCheck();
   //void addStream(Generator *gen);
   //bool deleteStream(Stream *strm);
   //bool deleteStream(short id);
   //Stream *searchStreambyID(short id);
   //short getStreamNum();

   Address *getDstAddr();

protected:
  
   /**This pointer points to the packet.
    * This packet is  to be send next time in OTG or is just received in OTR
    * 
    */
   //Packet * pkt_;    

   //   Stream* slhead_;   ///< This points to the head of Outgoing Stream List
   //   Stream* sltail_;   ///< This points to the tail of Outgoing Stream List
   //   Stream* slcurr_;    ///<  This points to the outgoing stream which feeds last(curr) packet   

   /** An enum.
    * Indication of port state */
   //enum port_state { 
   //              uninitialized, /*!< Enum value UnInit. */  
   //              running, /*!< Enum value Normal running. */  
   //              paused  /*!< Enum value Paused by user's command. */  
   //}
     //! Enum variable.
     /*! Indicating the state of port */
   //  state_;  
   
   Address myaddr_;  ///< The default address of mine 
   Address itsaddr_; ///< The default address of the other end of communication link (Source,Destination, depends on role)
};

#endif


