00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifdef WIN32
00016 #pragma warning (disable:4786)
00017 #endif
00018
00019 #include "API/Core/System/error.h"
00020 #include "API/Core/System/cl_assert.h"
00021 #include "API/Network/netsession.h"
00022 #include "netsession_generic.h"
00023 #include "netsession_server.h"
00024 #include "netsession_client.h"
00025 #include "network_delivery_socket.h"
00026
00027
00028 extern CL_ConnectionProvider *connection_provider;
00029
00031
00032
00033 CL_NetSession::CL_NetSession(
00034 const std::string &app_id,
00035 int port)
00036 :
00037 impl(NULL)
00038 {
00039 impl = new CL_NetSession_Server(connection_provider, app_id.c_str(), port);
00040 }
00041
00042 CL_NetSession::CL_NetSession(
00043 const std::string &app_id,
00044 const std::string &hostname,
00045 int port)
00046 :
00047 impl(NULL)
00048 {
00049
00050 unsigned int addr = inet_addr(hostname.c_str());
00051
00052 if (addr == INADDR_NONE)
00053 {
00054
00055
00056 hostent *host = gethostbyname(hostname.c_str());
00057 if (host == NULL) throw CL_Error("Could not lookup DNS name");
00058
00059 addr = *((unsigned int*) host->h_addr_list[0]);
00060 }
00061
00062 impl = new CL_NetSession_Client(addr, port, app_id, connection_provider);
00063 }
00064
00065 CL_NetSession::CL_NetSession(
00066 const CL_ServerInfo &server)
00067 :
00068 impl(NULL)
00069 {
00070 cl_assert(false);
00071 }
00072
00073 CL_NetSession::~CL_NetSession()
00074 {
00075 if (impl) impl->release_ref();
00076 }
00077
00079
00080
00081 CL_EventTrigger *CL_NetSession::get_trigger()
00082 {
00083 return impl->get_trigger();
00084 }
00085
00086 CL_NetComputer &CL_NetSession::get_server()
00087 {
00088 return impl->get_server();
00089 }
00090
00091 CL_NetGroup &CL_NetSession::get_all()
00092 {
00093 return impl->get_all();
00094 }
00095
00096 bool CL_NetSession::peek(int channel) const
00097 {
00098 return impl->peek(channel);
00099 }
00100
00101 CL_NetMessage CL_NetSession::receive(int channel, int timeout)
00102 {
00103 return impl->receive(channel, timeout);
00104 }
00105
00106 int CL_NetSession::access_status(int channel) const
00107 {
00108 return impl->access_status(channel);
00109 }
00110
00111 bool CL_NetSession::is_writable(int channel) const
00112 {
00113 return impl->is_writable(channel);
00114 }
00115
00116 bool CL_NetSession::is_readable(int channel) const
00117 {
00118 return impl->is_readable(channel);
00119 }
00120
00122
00123
00124 void CL_NetSession::send(
00125 const int dest_channel,
00126 const CL_NetGroup &dest,
00127 const CL_NetMessage &message,
00128 bool reliable)
00129 {
00130 impl->send(
00131 dest_channel,
00132 dest,
00133 message,
00134 reliable);
00135 }
00136
00137 CL_NetComputer CL_NetSession::receive_computer_leave()
00138 {
00139 return impl->receive_computer_leave();
00140 }
00141
00142 CL_NetComputer CL_NetSession::receive_computer_join()
00143 {
00144 return impl->receive_computer_join();
00145 }
00146
00147 CL_NetComputer CL_NetSession::receive_computer_rejoin()
00148 {
00149 return impl->receive_computer_rejoin();
00150 }
00151
00152 bool CL_NetSession::receive_session_closed()
00153 {
00154 return impl->receive_session_closed();
00155 }
00156
00157 int CL_NetSession::receive_access_changed()
00158 {
00159 return impl->receive_access_changed();
00160 }
00161
00162 void CL_NetSession::set_access(
00163 int channel,
00164 const CL_NetGroup &group,
00165 int access_rights)
00166 {
00167 impl->set_access(channel, group, access_rights);
00168 }
00169
00171
00172
00173 CL_NetSession::CL_NetSession(CL_NetSession_Generic *impl)
00174 : impl(impl)
00175 {
00176 impl->add_ref();
00177 }