#ifndef COMMUNICATOR_H
#define COMMUNICATOR_H

#include "client.h"
#include "client_imp.h"
#include "sockets.h"
#include "threads.h"
#include <queue>

class SocketClient;

class ExtendedHook : public hook
{
private:
	SocketClient * clientCommunicator_;
public:
	ExtendedHook(SocketClient * lowClient);
	virtual action acceptMessage(message * messageToAccept);
};

class ASocketClient
{
public:
    virtual void receiveMessage(message * messageToReceive) = 0;
	virtual void sendAndFreeMessage(const char * messageToSend) = 0;
    virtual bool connectToServer(const std::string & server, unsigned long port) = 0;
    virtual void disconnectFromServer() = 0;	
    virtual message * getNextMessage() = 0;
	virtual void pingServer() = 0;
	virtual bool isActive() = 0;
};

class SocketClient : public ASocketClient
{
private:
    client * client_;        
    ExtendedHook * hook_;
    std::queue<message *> receivedMessages_;      
	threads::mutex listLock_;
public:
    void receiveMessage(message * messageToReceive);
	void sendAndFreeMessage(const char * messageToSend);

    SocketClient();

    bool connectToServer(const std::string & server, unsigned long port);
    void disconnectFromServer();	

    message * getNextMessage();

	void pingServer();
	bool isActive();
};


#endif