/*! 
* 
* Copyright(c) 2009 Apogee Instruments, Inc. 
* \class UdpSocketBase 
* \brief Base class for a upd socket that finds apogee devices on a subnet 
* 
*/ 


#ifndef UDPSOCKETBASE_INCLUDE_H__ 
#define UDPSOCKETBASE_INCLUDE_H__ 

#include <string>
#include <vector>

class UdpSocketBase 
{ 
    public: 
        virtual ~UdpSocketBase(); 

        std::vector<std::string> Search4ApogeeDevices(const std::string & subnet,
            unsigned short portNum);

        int GetElapsedSecs() { return m_elapsedSec;}
        int GetTimeout() {return m_timeout;}

    protected:
        UdpSocketBase();
        virtual void CloseSocket() = 0;
        int m_SocketDescriptor;

    private:
        void CreateSocket(unsigned short portNum);
        void SetSocketOptions();
        void CreateUpdPacket();
        
        void BroadcastMsg(const std::string & subnet,
            unsigned short portNum);

        std::string FetchMsgFromSocket();
        std::vector<std::string> GetReturnedMsgs();

        
        std::string m_udpPacket;
        int m_timeout;
        int m_elapsedSec;

        //disabling the copy ctor and assignment operator
        //generated by the compiler - don't want them
        //Effective C++ Item 6
        UdpSocketBase(const UdpSocketBase&);
        UdpSocketBase& operator=(UdpSocketBase&);
}; 

#endif 
