#ifndef CETHERNETNETWORKSERVER_H
#define CETHERNETNETWORKSERVER_H


#include <QObject>
#include "NetworkProtocol.h"
#include <QTcpServer>
#include <QTcpSocket>
#include <QList>
#include <NetworkDevice.h>


class CMasterCtrl;
class CNetworkDevicesMgr;
class CEthernetDeviceConnection
{
public:

    QTcpSocket *mConnectionSocket;
    CNetworkDevice *mConnectedDevice;

};

class CEthernetNetworkServer : public QObject, CNetworkProtocol
{
    Q_OBJECT
public:

    enum eDeviceCreationResult
    {
        RES_CREATION_FAILED,
        RES_CREATION_SUCCESS,
        RES_CREATION_UNKNOWN_DEVICE
    };

    CEthernetNetworkServer();
    ~CEthernetNetworkServer();

    QTcpServer *mEthernetNetworkServer;
    CMasterCtrl *mProgramHandle;
    CNetworkDevicesMgr *mDevicesMgrHandle;

    //NetworkProtocol implementation
    virtual int NewFrameReceived(int DeviceID, int DeviceAddress, int MessageID, int DataSize, QByteArray Data);



//    QList<CNetworkDevice*> mNetworkDevices;
//    QList<CEthernetDeviceConnection*> mEthernetDeviceConnections;




//    bool IsDeviceRegistered(int DeviceID);
//    int RegisterNewDevice(CNetworkDevice* Device);
    int StartServer(int port);
    int CloseServer();

private:
//    int FindConnection(CEthernetDeviceConnection* Connection);
//    CEthernetDeviceConnection *FindConnection(QTcpSocket* socket);
    int CloseConnection(CEthernetDeviceConnection *Connection);

public slots:
    void EthernetNetworkServerConnected();
    void DeviceSocketDataAvail();
    void DeviceSocketDisconnected();
};

#endif // CETHERNETNETWORKSERVER_H
