netthread.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 2005 by Tobias Nadler                                         */
00005 /*                                                                              */
00006 /*  This library is free software; you can redistribute it and/or               */
00007 /*  modify it under the terms of the GNU Lesser General Public                  */
00008 /*  License as published by the Free Software Foundation; either                */
00009 /*  version 2.1 of the License, or (at your option) any later version.          */
00010 /*                                                                              */
00011 /*  This library is distributed in the hope that it will be useful,             */
00012 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of              */
00013 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
00014 /*  Lesser General Public License for more details.                             */
00015 /*                                                                              */
00016 /*  You should have received a copy of the GNU Lesser General Public            */
00017 /*  License along with this library; if not, write to the Free Software         */
00018 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */
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;// must be true to activate the HTTP-server-functionality
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;// called, when connecting done (successfully or not)
00134         }
00135         NetSocket * s;
00136         IPaddress ip;
00137         BasicObject::FunctionData cb;
00138     };
00139     list<DATA> lToConnect;
00140 };
00141 
00142 #endif

Generated on Wed May 9 17:35:55 2007 for netrinjo by  doxygen 1.5.1