//
//  Copyright © 2004, RESON Inc. All Rights Reserved.
//
//  No part of this file may be reproduced or transmitted in any form or by
//  any means, electronic or mechanical, including photocopy, recording, or
//  information storage or retrieval system, without permission in writing
//  from RESON Inc.
//
//  Filename:   
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    
//
//  Notes:      
//

#if !defined(AFX_GENERICESOCKET_H__38DC75A1_8394_4E90_BB05_5169FF619D55__INCLUDED_)
#define AFX_GENERICESOCKET_H__38DC75A1_8394_4E90_BB05_5169FF619D55__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "..\..\..\Utils\NetUtils\BaseThread.h"
#include "..\..\..\Utils\NetUtils\DataCallback.h"
#include "..\..\..\Utils\NetUtils\UDPSocket.h"

#include "Parent.h"
#include "TCPSocket.h"

class CGenericSocket
{
public:

    ///////////////
    // Definitions.

    enum ESOCKETTYPE
    {
        socketTypeUnspecified           = -1,                                               // Unknown or unspecified.
        socketTypeDatagram              = 0,                                                // UDP/IP-based datagram socket.
        socketTypeStream,                                                                   // TCP/IP-based stream socket.

        socketTypeMaxSupported                                                              // Keep as last item for accurate count.
    };

    ///////////////
    // Services.

                        CGenericSocket      (   void );
    virtual            ~CGenericSocket      (   void );

    bool                Configure           (   const ESOCKETTYPE                      &reSocketType,
                                                const unsigned short                   &runPort,
                                                const bool                             &rbBroadcast,
                                                PFN_DATACALLBACK                        pfnCallback,
                                                void *                                  pvCallbackParam,
                                                const unsigned long                    &rulSendAddress = 0UL );
        
    bool                Send                (   BYTE * const                            pbyStream,
                                                const unsigned long                    &rulNumBytes,
                                                const int                              &riSocketIndex   = -1 );

    ESOCKETTYPE         Type                (   void )  const;

    bool                IsHealthy           (   void );

protected:

    ESOCKETTYPE                             m_eSocketType;

    PFN_DATACALLBACK                        m_pfnDataHandlerCallback;
    void *                                  m_pvDataHandlerParam;

    CUDPSocket                             *m_pUDPSocket;
    CTCPSocket                             *m_pTCPSocket;


    bool                IsResponsive        (   void );

private:

    ///////////////
    // Services.

                        CGenericSocket     (   const CGenericSocket  &rRhs );                         // Not implemented thus private.
    CGenericSocket &   operator =          (   const CGenericSocket  &rRhs );                         // Not implemented thus private.

};

#endif // !defined(AFX_GENERICESOCKET_H__38DC75A1_8394_4E90_BB05_5169FF619D55__INCLUDED_)
