00001 /*! 00002 * \file 00003 * X-Forge Engine <br> 00004 * Copyright 2000-2003 Fathammer Ltd 00005 * 00006 * \brief Default implementation for a inetcommunication manager. 00007 * 00008 * $Id: XFuInetNetwork.h,v 1.1 2003/08/01 07:41:23 lars Exp $ 00009 * $Date: 2003/08/01 07:41:23 $ 00010 * $Revision: 1.1 $ 00011 */ 00012 00013 #ifndef XFUINETNETWORK_H_INCLUDED 00014 #define XFUINETNETWORK_H_INCLUDED 00015 00016 #include <xfcore/net/XFcUnknownSender.h> 00017 #include <xfcore/net/XFcClientLost.h> 00018 #include <xfcore/net/socket/XFcInetAddress.h> 00019 #include <xfcore/net/XFcCommunicationConstants.h> 00020 #include <xfcore/net/XFcDeviceDiscovery.h> 00021 #include <xfutil/XFuDynamicArray.h> 00022 #include <xfutil/XFuNetwork.h> 00023 00024 00025 class XFuSerializable; 00026 class XFcCommunicationScheduler; 00027 class XFcUnknownSender; 00028 class XFcClientLost; 00029 class XFcDataReceiver; 00030 class XFcObjectDataFrame; 00031 class XFcInetCommService; 00032 class XFcHostEntry; 00033 class XFcHostResolver; 00034 class XFcAdvertiser; 00035 class XFcInetHandler; 00036 class XFcInetClientWin; 00037 class XFcInetHostResolver; 00038 class XFcInetCommService; 00039 00040 //! Default implementation for a communication manager. 00041 00042 class XFuInetNetwork : public XFuNetwork, 00043 public XFcUnknownSender, 00044 public XFcClientLost, 00045 public XFcDeviceDiscovery 00046 { 00047 private: 00048 00049 //! Pointer to array of communication event handlers. 00050 XFuDynamicArray<XFuNetworkEventHandler*> *mNetworkEventHandlers; 00051 00052 //! Pointer to the communication scheduler. 00053 XFcCommunicationScheduler *mCommunicationScheduler; 00054 00055 //! Pointer to the communication handler. 00056 XFcInetHandler *mCommunicationHandler; 00057 00058 //! Pointer to the default data receiver. 00059 XFcDataReceiver *mDefaultDataReceiver; 00060 00061 //! Id of the communication handler. 00062 INT32 mCommunicationHandlerId; 00063 00064 //! Array of pointers to clients. 00065 XFcHashtable<UINT32, XFcInetClientWin *> mClients; 00066 00067 //! Maximum number of clients. 00068 INT32 mMaxClients; 00069 00070 //! Game token that is checked before new clients are allowed to connect. 00071 UINT32 mAcceptGameToken; 00072 00073 //! Holds status of advertiser device query. 00074 INT mAdvertiserStatus; 00075 00076 //! Holds inet server port. 00077 UINT16 mGamePort; 00078 00079 //! Pointer to the communication service. 00080 XFcInetHostResolver *mHostResolver; 00081 00082 //! Pointer to the inet communication service. 00083 XFcInetCommService *mCommService; 00084 00085 protected: 00086 00087 //! Protected constructor. 00088 XFuInetNetwork(); 00089 00090 //! Reserves memory for the client array (mClients) and initializes all the client pointers to NULL. 00091 virtual void initClients(INT32 aMaxClients); 00092 00093 //! Cleanup of all clients. 00094 virtual void deleteAllClients(); 00095 00096 //! Initializes default communication manager specific items that would normally be in the constructor. 00097 virtual INT init(); 00098 00099 public: 00100 00101 //! Static constructor. 00102 static XFuInetNetwork * create(); 00103 00104 //! Destructor. 00105 virtual ~XFuInetNetwork(); 00106 00107 //! Resets the communication manager. 00108 virtual void reset(); 00109 00110 //! Runs the communication scheduler. 00111 virtual void runCommunicationScheduler(); 00112 00113 //! Connection lost handler (XFuClientLost) (callback). 00114 virtual void clientLost(INT32 aClientId); 00115 00116 //! Handle data from an unknown client (callback). 00117 virtual INT handleSender(const void *aAddress, const CHAR8 *aData, INT32 aLen); 00118 00119 //! Enables the inet communication handler and opens it for service. 00120 /*! Use port 0 for random port. 00121 * Default speed is one of the XFuNET_CONNECTION_SPEED values (see XFcClientCommWin.h) 00122 */ 00123 virtual INT enableService(INT32 aMaxClients, UINT16 aPort, INT32 aDefaultSpeed); 00124 00125 //! Closes the currently active service (communication handler). 00126 virtual void closeService(); 00127 00128 //! Returns the specified client. 00129 virtual XFcClientCommWin * getClient(INT32 aClientId); 00130 00131 //! Adds a client with the specific address. 00132 /*! \return The client id or XFCNET_CLIENTADD_ERROR if failed. 00133 */ 00134 virtual INT32 addClient(XFcAddress *aAddress, INT32 aTimeoutTime = 15000); 00135 00136 //! Removes the specified client. 00137 virtual void removeClient(INT32 aClientId); 00138 00139 //! Removes all clients. 00140 virtual void removeAllClients(); 00141 00142 //! Returns the game token that is checked before new clients are allowed to connect. 00143 virtual UINT32 getAcceptGameToken(); 00144 00145 //! Sets the game token that is checked before new clients are allowed to connect. 00146 virtual void setAcceptGameToken(UINT32 aAcceptGameToken); 00147 00148 //! Sends a game connection packet. 00149 virtual void sendGameConnectPacket(INT32 aClientId, UINT32 aGameToken); 00150 00151 //! Returns a pointer to the default data receiver. 00152 virtual XFcDataReceiver * getDefaultDataReceiver(); 00153 00154 //! Sets the default data receiver. 00155 virtual void setDefaultDataReceiver(XFcDataReceiver *aReceiver); 00156 00157 //! Returns the specified data receiver. 00158 virtual XFcDataReceiver * getDataReceiver(UINT32 aId); 00159 00160 //! Adds a new data receiver. 00161 virtual INT addDataReceiver(UINT32 aId, XFcDataReceiver *aReceiver); 00162 00163 //! Removes a data receiver. 00164 virtual XFcDataReceiver * removeDataReceiver(UINT32 aId); 00165 00166 //! Returns the round trip time for the specified client. 00167 virtual INT32 getRoundTripTime(INT32 aClientId); 00168 00169 //! Get packet frame. 00170 virtual XFcObjectDataFrame * getPacketFrame(INT32 aClientId, XFCNET_MESSAGE_SLOT aSlot); 00171 00172 //! Get recent state frame. 00173 virtual XFcObjectDataFrame * getRecentStateFrame(INT32 aClientId, INT32 aRecentId); 00174 00175 //! Remove recent state frame. 00176 virtual void removeRecentStateFrame(INT32 aClientId, INT32 aRecentId); 00177 00178 //! Sends a serializable object to the specified client. 00179 virtual INT32 send(INT32 aClientId, UINT32 aReceiverId, XFCNET_MESSAGE_SLOT aSlot, XFuSerializable *aSerializable); 00180 00181 //! Sends a serializable object to the specified client as a recent state packet. 00182 virtual INT32 sendRecentState(INT32 aClientId, UINT32 aReceiverId, INT32 aRecentId, XFuSerializable *aSerializable); 00183 00184 //! Adds a communication event handler. 00185 virtual void addEventHandler(XFuNetworkEventHandler *aHandler); 00186 00187 //! Removes a communication event handler. 00188 virtual void removeEventHandler(XFuNetworkEventHandler *aHandler); 00189 00190 //! Removes all communication event handlers. 00191 virtual void removeAllEventHandlers(); 00192 00193 //! Cretes advertiser for opened service. 00194 /*! 00195 * \param aMessage message to be sent to the receiver of the advertise, or NULL to use the default message. 00196 * \param aAdvertisePort port where advertiser is created and for bt its 0. 00197 * \return 1 if advertiser service starts successfully, or XFCNET_ERROR otherwise. 00198 */ 00199 virtual INT startAdvertiser(const CHAR8 *aMessage, UINT16 aAdvertisePort); 00200 00201 //! Stops the advertiser service. 00202 virtual void stopAdvertiser(); 00203 00204 //! Starts server device discovery. 00205 /*! 00206 * \param aMessage message to be sent to the receiver of the advertise, or NULL to use the default message. 00207 * \param aAdvertisePort port where advertiser is created and for bt its 0. 00208 * \return 1 if discovery starts successfully, or XFCNET_ERROR otherwise. 00209 */ 00210 virtual INT startServerDiscovery(const CHAR8 *aMessage, UINT16 aAdvertisePort); 00211 00212 //! Stops device discovery. 00213 virtual void stopServerDiscovery(); 00214 00215 //! Inherited from XFcDeviceDiscovery. 00216 virtual void deviceDiscovery(const XFcLinkedList<XFcAdvertiser *> &aAdvertiser); 00217 //! Inherited from XFcDeviceDiscovery. 00218 virtual void deviceDiscovery(const XFcLinkedList<XFcHostEntry *> &) { return; } 00219 }; 00220 00221 #endif // !XFUINETNETWORK_H_INCLUDED
![]() | ||||
![]() |
Confidential Copyright © 2002-2003 Fathammer | with doxygen by Dimitri van Heesch |