Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

XFuInetNetwork.h

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

   
X-Forge Documentation
Confidential
Copyright © 2002-2003 Fathammer
   
Documentation generated
with doxygen
by Dimitri van Heesch