Main Page   Class Hierarchy   Compound List   File List   Compound Members  

netmanager.h

00001 #ifndef _NETMANAGER_H_
00002 #define _NETMANAGER_H_
00003 
00004 #ifdef _MSC_VER // if the compiler is from Microsoft
00005   #pragma warning(disable:4786)
00006 #endif
00007 
00008 #include <vector>
00009 #include <queue>
00010 
00011 using namespace std;
00012 
00013 #include "messagepacket.h"
00014 #include <SDL.h>
00015 #include <SDL_thread.h>
00016 #include <SDL_net.h>
00017 #include <iostream>
00018 
00019 // $$$ We need to have some kind of error control
00020 // $$$ Also need some flow control
00021 // $$$ Provide a way to clear the output buffers and discard their data
00022 // $$$ Consider to make asyinchronous the data sending, as well
00023 
00034 class NetManager {
00035  public:
00041   NetManager();
00042 
00047   void keepSending(bool go_on=true);
00048 
00053   virtual ~NetManager();
00054 
00061   void waitForData();
00062 
00066   static const Uint16 SERVER_PORT;
00067 
00071   static const int PACKET_SIZE;
00072 
00080   bool dataReady();
00081 
00082  protected:
00088   virtual void onReception(unsigned client) {};
00089 
00093   void transmit(const UDPsocket& sock, const MessagePacket& msg) const;
00094 
00101   friend int receiverCallback(void* data);
00102 
00108   virtual void manageReception();
00109 
00114   virtual bool forwardMessage(const MessagePacket& msg, IPaddress* ip) = 0;
00115 
00119   queue<MessagePacket> inputBuffer;
00120 
00127   IPaddress serverIP;
00128 
00133   UDPsocket receiverSocket;
00134 
00138   Uint16 actualPort;
00139 
00146   SDL_Thread* receiver;
00147 
00154   bool exitControllers;
00155 
00160   bool keepSendingFlag;
00161 
00165   SDL_mutex* sendingMutex;
00166 
00172   SDL_mutex* exitMutex;
00173 
00177   SDL_cond* dataReadyCond;
00178 
00182   SDL_mutex* dataReadyMutex;
00183 
00187   SDLNet_SocketSet receiverSet;
00188 
00195   SDL_mutex * socketOpen;
00196 };
00197 
00198 #endif

Generated on Thu Jun 6 17:22:20 2002 for Perihelion by doxygen1.2.15