Added GUI as parameter for client thread constructor. Fixed linux header for getaddrinfo.

This commit is contained in:
lotodore
2007-02-18 00:10:26 +00:00
parent 296399f166
commit fc25ae5a8b
4 changed files with 18 additions and 6 deletions
+5 -2
View File
@@ -27,11 +27,12 @@
class ClientData; class ClientData;
class ClientState; class ClientState;
class GuiInterface;
class ClientThread : public Thread class ClientThread : public Thread
{ {
public: public:
ClientThread(); ClientThread(GuiInterface &gui);
virtual ~ClientThread(); virtual ~ClientThread();
// Set the parameters. Does not do any error checking. // Set the parameters. Does not do any error checking.
@@ -47,13 +48,15 @@ protected:
const ClientData &GetData() const; const ClientData &GetData() const;
ClientData &GetData(); ClientData &GetData();
ClientState &GetState();
void SetState(ClientState &newState); void SetState(ClientState &newState);
private: private:
std::auto_ptr<ClientData> m_data; std::auto_ptr<ClientData> m_data;
ClientState *m_curState; ClientState *m_curState;
GuiInterface &m_gui;
friend class ClientStateInit; friend class ClientStateInit;
friend class ClientStateResolve; friend class ClientStateResolve;
+10 -2
View File
@@ -26,8 +26,8 @@
using namespace std; using namespace std;
ClientThread::ClientThread() ClientThread::ClientThread(GuiInterface &gui)
: m_curState(NULL) : m_curState(NULL), m_gui(gui)
{ {
m_data.reset(new ClientData); m_data.reset(new ClientData);
m_curState = &CLIENT_INITIAL_STATE::Instance(); m_curState = &CLIENT_INITIAL_STATE::Instance();
@@ -53,6 +53,7 @@ ClientThread::Main()
{ {
while (!ShouldTerminate()) while (!ShouldTerminate())
{ {
GetState().Process(*this, m_gui);
} }
} }
@@ -70,6 +71,13 @@ ClientThread::GetData()
return *m_data; return *m_data;
} }
ClientState &
ClientThread::GetState()
{
assert(m_curState);
return *m_curState;
}
void void
ClientThread::SetState(ClientState &newState) ClientThread::SetState(ClientState &newState)
{ {
+2 -2
View File
@@ -29,12 +29,12 @@ socket_set_port(unsigned port, int addrFamily, struct sockaddr *addr, int addrLe
if (addr) if (addr)
{ {
if (addrFamily == AF_INET && addrLen >= sizeof(sockaddr_in)) if (addrFamily == AF_INET && addrLen >= (int)sizeof(sockaddr_in))
{ {
((sockaddr_in *)&addr)->sin_port = htons(port); ((sockaddr_in *)&addr)->sin_port = htons(port);
retVal = true; retVal = true;
} }
else if (addrFamily == AF_INET6 && addrLen >= sizeof(sockaddr_in6)) else if (addrFamily == AF_INET6 && addrLen >= (int)sizeof(sockaddr_in6))
{ {
((sockaddr_in6 *)&addr)->sin6_port = htons(port); ((sockaddr_in6 *)&addr)->sin6_port = htons(port);
retVal = true; retVal = true;
+1
View File
@@ -29,6 +29,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#endif #endif