
/*---------------------------------------------------------------------------*/
/* client_sockets.h                                                          */
/* copyright (c) innovaphone 2015                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

class UClientSockets
{
public:
    virtual void ClientSocketsTimeout() = 0;
};

class IClientSockets
{
public:
    static IClientSockets * Create(class IIoMux *iomux, UClientSockets * user);
    virtual ~IClientSockets() {};
    virtual void StartTimer(unsigned timeoutMs) = 0;
    virtual void CancelTimer() = 0;
    virtual void SocketsActive(bool active) = 0;
    virtual void RtpSocketsActive(bool active) = 0;
    virtual void MulticastReceiveActive(bool active) = 0;
};

class ClientUDPSocketProvider : public UDPSocketProvider {
    bool registered;
    istd::list<class ClientUDPSocket> sockets;
    class UDPSocket * NewSocket(IIoMux * const iomux, USocket * const user, class IInstanceLog * const log) override;
public:
    ClientUDPSocketProvider();
    virtual ~ClientUDPSocketProvider();
    void CloseListen();
    void RestartListen();
};

class ClientUDPSocket : public UDPSocket, public istd::listElement<ClientUDPSocket> {
    bool rtpSocketActive;
    bool multicastReceiveActive;
    void UserSocketBindResult(const char * localAddr, word localPort) override;
    void UserSocketShutdown(shutdownreason_t reason) override;
public:
    ClientUDPSocket(IIoMux * const iomux, USocket * const user, class IInstanceLog * const log, ClientUDPSocketProvider * provider);
    virtual ~ClientUDPSocket();
    void CloseListen();
    void RestartListen();
};

ClientUDPSocketProvider * ClientCreateUDPSocketProvider();

class ClientTCPSocketProvider : public TCPSocketProvider {
    bool registered;
    istd::list<class ClientTCPSocket> sockets;
    class TCPSocket * NewSocket(IIoMux * const iomux, USocket * const user, class IInstanceLog * const log) override;
#ifdef _IOS_
    friend class ClientTCPSocket;
    struct ifaddrs *ifap;
#endif
public:
    ClientTCPSocketProvider();
    virtual ~ClientTCPSocketProvider();
    void CloseListen();
    void RestartListen();
    void CloseSockets();
    void CheckInterface();
};

class ClientTCPSocket : public TCPSocket, public istd::listElement<ClientTCPSocket> {
    void FDNotify(bool notifyRX, bool notifyTX) override;
public:
    ClientTCPSocket(IIoMux * const iomux, USocket * const user, class IInstanceLog * const log, ClientTCPSocketProvider * provider);
    virtual ~ClientTCPSocket();
    void CloseListen();
    void RestartListen();
    void CloseSockets();
    void CheckInterface();
};

ClientTCPSocketProvider * ClientCreateTCPSocketProvider();

class ClientUDSocketProvider : public UDSocketProvider {
    class UDSocket * NewSocket(IIoMux * const iomux, USocket * const user, class IInstanceLog * const log) override;
public:
    ClientUDSocketProvider() {};
    virtual ~ClientUDSocketProvider() {};
};

class ClientUDSocket : public UDSocket, public istd::listElement<ClientUDSocket> {
    void FDNotify(bool notifyRX, bool notifyTX) override;
public:
    ClientUDSocket(IIoMux * const iomux, USocket * const user, class IInstanceLog * const log, ClientUDSocketProvider * provider);
    virtual ~ClientUDSocket() {};
};

ClientUDSocketProvider * ClientCreateLocalSocketProvider();

