00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef header_netsession_client
00016 #define header_netsession_client
00017
00018 #include <string>
00019 #include <list>
00020 #include <queue>
00021
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_NetChannelQueue_Client;
00028 class CL_NetSession_Client;
00029
00030 class CL_NetComputer_Server : public CL_NetComputer_Generic
00031 {
00032 public:
00033 CL_NetComputer_Server(CL_NetSession_Client *session);
00034 virtual ~CL_NetComputer_Server();
00035
00036 virtual unsigned long get_address() const;
00037 virtual void disconnect();
00038
00039 CL_NetSession_Client *get_session();
00040 };
00041
00042 class CL_NetSession_Client : public CL_NetSession_Generic, CL_Runnable
00043 {
00044 public:
00045 CL_NetSession_Client(
00046 int ip_addr,
00047 int port,
00048 const std::string &game_id,
00049 CL_ConnectionProvider *provider);
00050 virtual ~CL_NetSession_Client();
00051
00052 virtual CL_NetComputer &get_server();
00053 virtual CL_NetGroup &get_all();
00054
00055 virtual bool peek(int channel) const;
00056 virtual CL_NetMessage receive(int channel, int timeout=-1);
00057
00058 virtual void send(
00059 const int dest_channel,
00060 const CL_NetGroup &dest,
00061 const CL_NetMessage &message,
00062 bool reliable = true);
00063
00064 virtual CL_NetComputer receive_computer_leave();
00065 virtual CL_NetComputer receive_computer_join();
00066 virtual CL_NetComputer receive_computer_rejoin();
00067 virtual bool receive_session_closed();
00068 virtual int access_status(int channel) const;
00069 virtual bool is_writable(int channel) const;
00070 virtual bool is_readable(int channel) const;
00071
00072
00073 virtual int receive_access_changed();
00074
00075
00076 virtual void set_access(
00077 int channel,
00078 const CL_NetComputer &computer,
00079 int access_rights=ACCESS_CHANNEL_READ|ACCESS_CHANNEL_WRITE);
00080 virtual void set_access(
00081 int channel,
00082 const CL_NetGroup &group,
00083 int access_rights=ACCESS_CHANNEL_READ|ACCESS_CHANNEL_WRITE);
00084
00085 protected:
00086 virtual void keep_alive();
00087
00088 private:
00089 CL_NetChannelQueue_Client *find_queue(int netchannel) const;
00090 CL_NetChannelQueue_Client *create_queue(int netchannel);
00091 void check_trigger();
00092
00093 private:
00094 CL_Connection *tcp_connection;
00095 CL_UDPConnection *udp_connection;
00096 std::list<CL_NetChannelQueue_Client*> netchannels;
00097 std::queue<CL_NetChannelQueue_Client*> access_queue;
00098 int our_id;
00099
00100 CL_NetComputer server;
00101 CL_NetGroup all;
00102
00103 private:
00104 CL_Mutex *mutex;
00105 CL_Thread *thread;
00106 volatile bool exit_thread;
00107
00108 virtual void run();
00109
00110 friend CL_NetComputer_Server;
00111 };
00112
00113 class CL_NetChannelQueue_Client : public std::queue<CL_NetMessage>
00114 {
00115 public:
00116 int channel_id;
00117 int access;
00118 };
00119
00120 #endif