Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

netsession_server.h

Go to the documentation of this file.
00001 /*
00002         $Id: netsession_server.h,v 1.5 2001/03/20 13:22:20 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #ifndef header_netsession_server
00016 #define header_netsession_server
00017 
00018 #include <list>
00019 #include <queue>
00020 #include <string>
00021 #include <map>
00022 #include "API/Core/System/thread.h"
00023 #include "API/Network/netgroup.h"
00024 #include "netsession_generic.h"
00025 #include "netcomputer_generic.h"
00026 
00027 class CL_NetComputer_Host;
00028 class CL_NetSession_Server;
00029 class CL_Connection;
00030 class CL_UDPConnection;
00031 class CL_Mutex;
00032 
00033 class CL_NetComputer_Host : public CL_NetComputer_Generic
00034 {
00035 public:
00036         CL_NetComputer_Host(CL_NetSession_Server *session, CL_Connection *connection, int id);
00037         virtual ~CL_NetComputer_Host();
00038 
00039         virtual unsigned long get_address() const;
00040         virtual void disconnect();
00041 
00042         int id;
00043         CL_Connection *connection;
00044 };
00045 
00046 class CL_NetChannelQueue : public std::queue<CL_NetMessage>
00047 {
00048 public:
00049         std::map<int, int> access;
00050 };
00051 
00052 
00053 class CL_NetSession_Server : public CL_NetSession_Generic, CL_Runnable
00054 {
00055 // Construction:
00056 public:
00057         CL_NetSession_Server(
00058                 CL_ConnectionProvider *provider,
00059                 const char *game_id,
00060                 int port);
00061 
00062         virtual ~CL_NetSession_Server();
00063 
00064 // Attributes:
00065 public:
00066         virtual CL_NetComputer &get_server();
00067 
00068         virtual CL_NetGroup &get_all();
00069 
00070         virtual bool peek(int channel) const;
00071 
00072         virtual int access_status(int channel) const;
00073 
00074         virtual bool is_writable(int channel) const;
00075 
00076         virtual bool is_readable(int channel) const;
00077 
00078 // Operations:
00079 public:
00080         virtual void keep_alive();
00081 
00082         virtual CL_NetMessage receive(
00083                 int channel,
00084                 int timeout=-1);
00085 
00086         void send(
00087                 const int dest_channel,
00088                 const CL_NetComputer &dest,
00089                 const CL_NetMessage &message,
00090                 bool reliable = true);
00091 
00092         virtual void send(
00093                 const int dest_channel,
00094                 const CL_NetGroup &dest,
00095                 const CL_NetMessage &message,
00096                 bool reliable = true);
00097 
00098         virtual CL_NetComputer receive_computer_leave();
00099 
00100         virtual CL_NetComputer receive_computer_join();
00101 
00102         virtual CL_NetComputer receive_computer_rejoin();
00103 
00104         virtual bool receive_session_closed();
00105 
00106         // Client side only:
00107         virtual int receive_access_changed();
00108 
00109         // Server side only:
00110         virtual void set_access(
00111                 int channel,
00112                 const CL_NetComputer &computer,
00113                 int access_rights=ACCESS_CHANNEL_READ|ACCESS_CHANNEL_WRITE);
00114 
00115         virtual void set_access(
00116                 int channel,
00117                 const CL_NetGroup &group,
00118                 int access_rights=ACCESS_CHANNEL_READ|ACCESS_CHANNEL_WRITE);
00119                 
00120 private: // implementation helper functions:
00121         CL_NetComputer_Host *get_computer_host(const CL_NetComputer &comp)
00122         { return static_cast<CL_NetComputer_Host *>(comp.impl); }
00123         // Casts comp.impl to CL_NetComputer_Host and returns it.
00124 
00125         CL_NetChannelQueue *find_queue(int netchannel) const;
00126         // Returns the queue of the specified netchannel. Returns NULL if no queue exist.
00127 
00128         CL_NetChannelQueue *create_queue(int netchannel);
00129         // Returns the queue of the specified netchannel. Creates a new one if none exist.
00130 
00131         bool has_read_access(
00132                 CL_NetChannelQueue *channel,
00133                 CL_NetComputer_Host *host);
00134 
00135         void check_trigger();
00136         // Resets the trigger if there is no new data pending.
00137 
00138 private: // data vars
00139         CL_NetGroup all;
00140         std::list<CL_NetComputer_Host*> prejoin;
00141         std::list<CL_NetComputer_Host*> computers;
00142 
00143         std::map<int /*netchannel*/,CL_NetChannelQueue> netchannels;
00144         
00145         CL_UDPConnection *udp_connection;
00146 
00147         int id_counter;
00148         std::string game_id;
00149         int port;
00150         
00151         std::queue<CL_NetComputer_Host*> join_queue;
00152         std::queue<CL_NetComputer_Host*> rejoin_queue;
00153         std::queue<CL_NetComputer_Host*> leave_queue;
00154 
00155 private: // multithread:
00156         CL_Mutex *mutex;
00157         CL_Thread *thread;
00158         volatile bool exit_thread;
00159 
00160         virtual void run();
00161 
00162 friend CL_NetComputer_Host;
00163 };
00164 
00165 
00166 #endif

Generated at Wed Apr 4 19:54:02 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001