2013-12-03 13:04:53 +01:00
|
|
|
#ifndef NETWORK_DEPENDENCIES_THREADED_CLIENT_H
|
|
|
|
#define NETWORK_DEPENDENCIES_THREADED_CLIENT_H
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
// Created by Sam Svensson 2013 //
|
|
|
|
//////////////////////////////////
|
|
|
|
|
2014-02-17 10:38:11 +01:00
|
|
|
#include "Thread/IThreadObject.h"
|
2013-12-08 23:56:17 +01:00
|
|
|
#include "PostBox.h"
|
|
|
|
#include "Connection.h"
|
2014-02-17 10:38:11 +01:00
|
|
|
#include "Thread/OysterThread.h"
|
|
|
|
#include "Utilities.h"
|
2013-12-03 13:04:53 +01:00
|
|
|
|
2013-12-09 10:48:43 +01:00
|
|
|
#include <mutex>
|
|
|
|
|
2013-12-03 13:04:53 +01:00
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Network
|
|
|
|
{
|
2013-12-11 21:45:43 +01:00
|
|
|
class CustomNetProtocol;
|
2013-12-08 23:56:17 +01:00
|
|
|
class OysterByte;
|
|
|
|
class ThreadedClient : public Thread::IThreadObject
|
2013-12-03 13:04:53 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThreadedClient();
|
|
|
|
ThreadedClient(unsigned int socket);
|
2013-12-11 21:45:43 +01:00
|
|
|
ThreadedClient(IPostBox<CustomNetProtocol*> *postBox, unsigned int socket);
|
2013-12-03 13:04:53 +01:00
|
|
|
virtual ~ThreadedClient();
|
|
|
|
|
2013-12-11 21:45:43 +01:00
|
|
|
void Send(CustomNetProtocol* protocol);
|
|
|
|
|
|
|
|
bool IsConnected();
|
2013-12-03 13:04:53 +01:00
|
|
|
|
|
|
|
int Connect(unsigned short port, const char serverName[]);
|
|
|
|
|
2013-12-11 21:45:43 +01:00
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
void setRecvPostBox(IPostBox<CustomNetProtocol*> *postBox);
|
2013-12-03 13:04:53 +01:00
|
|
|
|
2013-12-11 21:45:43 +01:00
|
|
|
protected:
|
2013-12-03 13:04:53 +01:00
|
|
|
virtual int Send();
|
|
|
|
virtual int Recv();
|
|
|
|
|
2013-12-11 21:45:43 +01:00
|
|
|
//These functions should not be called by any other than the thread.
|
2013-12-03 13:04:53 +01:00
|
|
|
virtual void ThreadEntry();
|
|
|
|
virtual void ThreadExit();
|
|
|
|
virtual bool DoWork();
|
|
|
|
|
2013-12-11 21:45:43 +01:00
|
|
|
protected:
|
2013-12-03 13:04:53 +01:00
|
|
|
Connection* connection;
|
2013-12-11 21:45:43 +01:00
|
|
|
IPostBox<CustomNetProtocol*> *sendPostBox;
|
|
|
|
IPostBox<CustomNetProtocol*> *recvPostBox;
|
2013-12-03 13:04:53 +01:00
|
|
|
Oyster::Thread::OysterThread thread;
|
2013-12-09 10:48:43 +01:00
|
|
|
std::mutex stdMutex;
|
2013-12-03 13:04:53 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|