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

network_delivery_impl.h

Go to the documentation of this file.
00001 /*
00002         $Id: network_delivery_impl.h,v 1.1 2001/02/15 13:18:52 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         File purpose:
00015                 Contains interfaces to the implementation dependent code.
00016 
00017 */
00018 
00020 
00021 #ifndef header_network_delivery_impl
00022 #define header_network_delivery_impl
00023 
00024 class CL_ConnectionPacket
00025 //: A packet sent through a CL_Connection.
00027 {
00028 public:
00029         int size;
00030         //: Size of the packet data.
00031 
00032         void *data;
00033         //: The packet data.
00034 
00035         CL_ConnectionPacket() { data = NULL; }
00036         //: Default constructor
00037 
00038         CL_ConnectionPacket(void *data, int size)
00039         {
00040                 this->data = data;
00041                 this->size = size;
00042         }
00043 
00044 };
00045 
00046 class CL_UDPConnectionPacket
00047 {
00048 public:
00049         unsigned int ip_addr;
00050         //: IP address the packet should be sent to - or was received from.
00051 
00052         unsigned int port;
00053         //: udp port the packet should be sent to - or was received from.
00054         
00055         int size;
00056         //: Size of the packet data.
00057 
00058         void *data;
00059         //: The packet data.
00060 };
00061 
00062 class CL_Connection
00063 //: Class representing a connection to a host or a local process.
00071 {
00072 public:
00073         virtual ~CL_Connection() {;}
00074 
00075         virtual bool peek()=0;
00076         //: Returns true if a message is available - but doesn't retrieve it.
00078 
00079         virtual CL_ConnectionPacket receive()=0;
00080         //: Gets the next net message available from this connection.
00081 
00082         virtual void send(CL_ConnectionPacket message)=0;
00083         //: Sends some data to the connection.
00085 
00086         virtual bool connection_lost()=0;
00087         //: If the connection is lost in the other end (eg. socket closed), this 
00088         //: function will return true, otherwise false.
00090 };
00091 
00092 class CL_UDPConnection
00093 //: Class representing a UDP socket connection.
00096 {
00097 public:
00098         virtual bool peek()=0;
00099         //: Returns true if a message is available - but doesn't retrieve it.
00101 
00102         virtual CL_UDPConnectionPacket receive()=0;
00103         //: Gets the next net message available from this connection.
00104 
00105         virtual void send(CL_UDPConnectionPacket message)=0;
00106         //: Sends some data from the connection.
00108 
00109         virtual void broadcast(CL_UDPConnectionPacket message)=0;
00110         //: Broadcasts some data from the connection.
00112 
00113         virtual unsigned int get_port()=0;
00114         //: Returns the udp port that this connection listens at.
00116 };
00117 
00118 class CL_Mutex;
00119 class CL_ConnectionProvider
00120 //: Interface to platform dependent connections.
00126 {
00127 public:
00128         virtual ~CL_ConnectionProvider() {;}
00129         
00130         virtual CL_UDPConnection *create_udp_connection(unsigned int port)=0;
00131         //: Creates a udp connection that listens on the udp port 'port'.
00134 
00135         virtual CL_Connection *get_client()=0;
00136         //: Returns the connection to the NetSession layer.
00138 
00139         virtual CL_Connection *create_tcp_connection(
00140                 int ip_addr,
00141                 int port)=0;
00142         //: Connects to the specified IP address and port number.
00146 
00147         virtual CL_Connection *accept()=0;
00148         //: Returns a pointer to new connections when someone connects to us.
00149         //: This function must be implemented as a nonblocking function, which
00150         //: only accepts on a socket if a peek determines that a connection is waiting -
00151         //: otherwise, the function must return NULL.
00153 
00154         virtual void start_accept_on_port(int port)=0;
00155         //: Accept new connections on the specified port.
00157 
00158         virtual void stop_accept_on_port(int port)=0;
00159         //: Stop accepting new connections on the specified port.
00161         
00162         virtual void wait_for_connection_data(CL_Mutex *mutex)=0;
00163         //: This function will sleep until one of the connections has any new data
00164         //: available, or if a connection changes state (eg. a connection is lost).
00165         //: This is a platform independent way of doing a select() on all the
00166         //: connection file descriptors.
00167 
00168         virtual void remove_connection(CL_Connection *removed_connection)=0;
00169         //: This function is called by the generic delivery service, when a connection
00170         //: is about to be deleted following a connection-lost. The connection provider
00171         //: should remove any references to 'removed_connection' as it will be deleted.
00172 };
00173 
00174 #endif

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