00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef NETTHREAD_H
00023 #define NETTHREAD_H
00024
00025 #include "basicthread.h"
00026 #include "basicobject.h"
00027 #include <list>
00028 #include "SDL/SDL_net.h"
00029
00036 using namespace std;
00037 class NetSocket;
00038
00056 class DECLSPEC NetThread : public BasicThread
00057 {
00058 public:
00059 #ifdef WEB_CLIENT
00060
00065 DECLSPEC NetThread( const char *name, BasicObject *p, bool debug = true );
00066 #else
00067
00074 DECLSPEC NetThread( const char *name, BasicObject *p, bool server = true, bool debug = true );
00075 #endif
00076
00081 DECLSPEC NetThread( TiXmlElement *el, BasicObject *p );
00082 DECLSPEC ~NetThread();
00083
00084 virtual const char *getClassName() { return "NetThread"; }
00085
00095 DECLSPEC void connectSocket( NetSocket *s, const IPaddress &ip, BasicObject::Callback c, BasicObject *obj = NULL );
00096
00097 #ifndef WEB_CLIENT
00098
00102 void setServerCheck(bool active) {bServer = active;}
00103 #endif
00104
00107 static NetThread *the;
00115 DECLSPEC static NetThread *getThe();
00116 protected:
00117 virtual DECLSPEC int onRun();
00118 virtual DECLSPEC void onCycle();
00119 virtual DECLSPEC void onInit();
00120 virtual DECLSPEC void onDestroy();
00121
00122 private:
00123 #ifndef WEB_CLIENT
00124 bool bServer;
00125 #endif
00126 struct DATA
00127 {
00128 DATA(){}
00129 DATA( NetSocket *sock, const IPaddress &addr, BasicObject::FunctionData c )
00130 {
00131 s = sock;
00132 ip = addr;
00133 cb = c;
00134 }
00135 NetSocket * s;
00136 IPaddress ip;
00137 BasicObject::FunctionData cb;
00138 };
00139 list<DATA> lToConnect;
00140 };
00141
00142 #endif