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

netsession.h

Go to the documentation of this file.
00001 /*
00002         $Id: netsession.h,v 1.7 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 
00016 
00017 #ifndef header_netsession
00018 #define header_netsession
00019 
00020 #include <string>
00021 
00022 #define ACCESS_CHANNEL_READ 1
00023 #define ACCESS_CHANNEL_WRITE 2
00024 
00025 class CL_NetComputer;
00026 class CL_NetGroup;
00027 class CL_NetMessage;
00028 class CL_ServerInfo;
00029 class CL_EventTrigger;
00030 
00031 class CL_NetSession
00032 //: CL_NetSession is the interface to communcation with a network session/game.
00033 {
00035 public:
00036         CL_NetSession(
00037                 const std::string &app_id,
00038                 int port);
00039         //: Create a netsession server on the specified port. Only netsession clients
00040         //: with same application ID will be able to connect to the server.
00041 
00042         CL_NetSession(
00043                 const std::string &app_id,
00044                 const std::string &hostname,
00045                 int port);
00046         //: Create a netsession client and connect to a server.
00047 
00048         CL_NetSession(
00049                 const CL_ServerInfo &server);
00050         //: Connect to a server coming from a server info structure. Usually used together
00051         //: with master browse servers and LAN broadcast browsing.
00052 
00053         virtual ~CL_NetSession();
00054 
00056 public:
00057         CL_EventTrigger *get_trigger();
00058         // Event trigger that triggers when the netsession object changes (on incoming data).
00059 
00060         CL_NetComputer &get_server();
00061         //: The server of the network game.
00062 
00063         CL_NetGroup &get_all();
00064         //: A group of all the computers in the netsession.
00065         
00066         bool peek(int channel) const;
00067         //: Returns true if a message is available on the specified channel.
00068 
00069         int access_status(int channel) const;
00070         //: Returns the access status flags on the channel.
00071 
00072         bool is_writable(int channel) const;
00073         //: Returns true if the ACCESS_CHANNEL_WRITE flag is set on channel.
00074 
00075         bool is_readable(int channel) const;
00076         //: Returns true if the ACCESS_CHANNEL_READ flag is set on channel.
00077 
00079 public:
00080         CL_NetMessage receive(int channel, int timeout = -1);
00081         //: Receives a message from the specified channel. The call is blocking, so
00082         //: don't call it if you aren't completly sure it will arrive (unless you set
00083         //: a timeout).
00087 
00088         void send(
00089                 const int dest_channel,
00090                 const CL_NetGroup &dest,
00091                 const CL_NetMessage &message,
00092                 bool reliable = true);
00093         //: Sends a message to a group of computers at netchannel 'dest_channel'.
00098 
00099         CL_NetComputer receive_computer_leave();
00100         //: Returns the first (if more) computer that has left the game, or NULL if
00101         //: none. The next time the function is called, it returns the next computer,
00102         //: etc.<br>
00103         //: CL_NetComputer instances are reference counted. A computer wont be forgotten
00104         //: until all instances of it has been destroyed. If a computer rejoins the server
00105         //: while there still exist a netcomputer instance, it will be recognized and
00106         //: cause a 'rejoin' event instead of a normal join event.
00107 
00108         CL_NetComputer receive_computer_join();
00109         //: Returns the first (if more) computer that is joining the game, or throws an exception
00110         //: if none joined. The next time the function is called, it returns the next computer,
00111         //: etc.
00112 
00113         CL_NetComputer receive_computer_rejoin();
00114         //: Returns the first (if more) computer that is re-joining the game, or throws an exception
00115         //: if none joined. The next time the function is called, it returns the next computer,
00116         //: etc. <br>
00117         //: A re-joining computer is simply a computer joining the game, that still
00118         //: havn't had its CL_NetComputer reference deleted. This provides a way to
00119         //: recognize a computer that was in the game.
00120 
00121         bool receive_session_closed();
00122         // Returns true if the session was closed.
00123 
00124         int receive_access_changed();
00125         //: Returns the first netchannel that has had its access changed. Returns -1 when no
00126         //: more channels have had their access changed.
00127         //: This function only works on a client netsession.
00128 
00129         void set_access(
00130                 int channel,
00131                 const CL_NetGroup &group,
00132                 int access_rights = ACCESS_CHANNEL_READ | ACCESS_CHANNEL_WRITE);
00133         //: Sets the channel access flags on the channel for the computers specified.
00134         //: This function only has effect on a server netsession.
00135 
00137 public:
00138         CL_NetSession(class CL_NetSession_Generic *impl);
00139         class CL_NetSession_Generic *impl;
00140 };
00141 
00142 #endif

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