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

XFuBluetoothMultiNetwork.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 Bluetooth communication manager.
00007  *
00008  * $Id: XFuBluetoothMultiNetwork.h,v 1.5 2003/10/02 11:43:01 slehti Exp $
00009  * $Date: 2003/10/02 11:43:01 $
00010  * $Revision: 1.5 $
00011  */
00012 
00013 #ifndef XFUBLUETOOTHMULTINETWORK_H_INCLUDED
00014 #define XFUBLUETOOTHMULTINETWORK_H_INCLUDED
00015 
00016 #include <xfcore/net/XFcUnknownSender.h>
00017 #include <xfcore/net/XFcClientLost.h>
00018 #include <xfcore/net/socket/XFcAddress.h>
00019 #include <xfcore/net/XFcCommunicationConstants.h>
00020 #include <xfcore/net/XFcDeviceDiscovery.h>
00021 #include <xfutil/XFuDynamicArray.h>
00022 
00023 
00024 class XFuSerializable;
00025 class XFcCommunicationScheduler;
00026 class XFcUnknownSender;
00027 class XFcClientLost;
00028 class XFcDataReceiver;
00029 class XFcObjectDataFrame;
00030 class XFcBtCommService;
00031 class XFcHostEntry;
00032 class XFcBtHostResolver;
00033 class XFcAdvertiser;
00034 class XFcBtClientWin;
00035 class XFcBtServerSearch;
00036 class XFcBtAddress;
00037 class XFcBtHandler;
00038 class XFcName;
00039 
00040 class XFuBluetoothMultiNetwork : public XFuNetwork,
00041                                            public XFcUnknownSender,
00042                                            public XFcClientLost,
00043                                            public XFcDeviceDiscovery
00044 {
00045 private:
00046 
00047     //! Pointer to array of communication event handlers.
00048     XFuDynamicArray<XFuNetworkEventHandler*> *mNetworkEventHandlers;
00049 
00050     //! Pointer to the communication scheduler.
00051     XFcCommunicationScheduler *mCommunicationScheduler;
00052 
00053     //! Pointer to the communication handler.
00054     XFcBtHandler *mCommunicationHandler;
00055 
00056     //! Holds pointer to the Bluetooth communication services.
00057     XFcBtCommService *mCommunicationService;
00058 
00059     //! Pointer to the default data receiver.
00060     XFcDataReceiver *mDefaultDataReceiver;
00061 
00062     //! Holds pointer to bt server search.
00063     XFcBtServerSearch *mBtServerSearch;
00064 
00065     //! Holds pointer to bt host resolver.
00066     XFcBtHostResolver *mHostResolver;
00067 
00068     //! Id of the communication handler.
00069     INT32 mCommunicationHandlerId;
00070 
00071     //! Array of pointers to clients.
00072     XFcHashtable<UINT32, XFcBtClientWin *> mClients;
00073 
00074     //! Holds ClientId, only one client is supported for now.
00075     INT32 mSlaveClientId;
00076 
00077     //! Game token that is checked before new clients are allowed to connect.
00078     UINT32 mAcceptGameToken;
00079 
00080     //! Holds game port.
00081     UINT16 mGamePort;
00082 
00083     //! Holds bluetooth communication service, needed for bluetooth SDP and first free server port query.
00084     XFcBtCommService *mService;
00085 
00086     //! Holds bluetooth uuid for this game.
00087     XFcBtUUID mUUID;
00088 protected:
00089 
00090     //! Deletes all clients.
00091     virtual void deleteAllClients();
00092 
00093     //! Protected constructor.
00094     XFuBluetoothMultiNetwork();
00095 
00096     //! Initializes this Bluetooth communication manager.
00097     INT init();
00098 
00099     //! Initializes enable service.
00100     INT initEnable(UINT16 aPort, INT aIsServer);
00101 
00102 public:
00103 
00104     //! Static constructor.
00105     static XFuBluetoothMultiNetwork * create();
00106 
00107     //! Enables the Bluetooth communication handler and opens it for service.  Opens device as bluetooth slave.
00108     /*!
00109      * \param aPort is clients BT-Slave port. If port is set to 0 the port is selected by system. 
00110      */
00111     virtual INT enableClientService(UINT16 aPort);
00112 
00113     //! Enables the Bluetooth communication handler and opens it for service. Opens device as bluetooth master.
00114     virtual INT enableHostService();
00115 
00116     //! Closes the currently active service (communication handler).
00117     virtual void closeService();
00118 
00119     //! Resets the communication manager.
00120     virtual void reset();
00121 
00122     //! Runs the communication scheduler.
00123     virtual void runCommunicationScheduler();
00124 
00125     //! Connection lost handler (XFuClientLost) (callback).
00126     virtual void clientLost(INT32 aClientId);
00127 
00128     //! Adds a client with the specific address.
00129     /*! \return The client id or XFCNET_CLIENTADD_ERROR if failed.
00130      */
00131     virtual INT32 addClient(XFcAddress *aAddress, INT32 aTimeoutTime = 15000);
00132 
00133     //! Returns the specified client.
00134     virtual XFcClientCommWin * getClient(INT32 aClientId);
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     //! Returns the specified data receiver.
00155     virtual XFcDataReceiver * getDataReceiver(UINT32 aId);
00156 
00157     //! Adds a new data receiver.
00158     virtual INT addDataReceiver(UINT32 aId, XFcDataReceiver *aReceiver);
00159 
00160     //! Sets the default data receiver.
00161     virtual void setDefaultDataReceiver(XFcDataReceiver *aReceiver);
00162 
00163     //! Removes a data receiver.
00164     virtual XFcDataReceiver * removeDataReceiver(UINT32 aId);
00165 
00166      //! Handle data from an unknown client (callback).
00167     virtual INT handleSender(const void *aAddress, const CHAR8 *aData, INT32 aLen);
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     //! Returns the round trip time for the specified client.
00179     virtual INT32 getRoundTripTime(INT32 aClientId);
00180 
00181     //! Sends a serializable object to the specified client.
00182     virtual INT32 send(INT32 aClientId, UINT32 aReceiverId, XFCNET_MESSAGE_SLOT aSlot, XFuSerializable *aSerializable);
00183 
00184     //! Sends a serializable object to the specified client as a recent state packet.
00185     virtual INT32 sendRecentState(INT32 aClientId, UINT32 aReceiverId, INT32 aRecentId, XFuSerializable *aSerializable);
00186 
00187     //! Adds a communication event handler.
00188     virtual void addEventHandler(XFuNetworkEventHandler *aHandler);
00189 
00190     //! Removes a communication event handler.
00191     virtual void removeEventHandler(XFuNetworkEventHandler *aHandler);
00192 
00193     //! Removes all communication event handlers.
00194     virtual void removeAllEventHandlers();
00195 
00196     //! Stops device discovery.
00197     virtual void stopDeviceDiscovery();
00198 
00199     //! Stops server discovery.
00200     virtual void stopClientDiscovery();
00201 
00202     //! Stops server advertiser.
00203     virtual void stopAdvertiser();
00204 
00205     //! Starts device discovery.
00206     virtual INT startDeviceDiscovery();
00207 
00208     //! Starts server discovery, if address is NULL engine will search througth all available bt devices.
00209     virtual INT startClientDiscovery(const XFcBtUUID &aUuid, const XFcBtAddress *aAddress);
00210 
00211     //! Starts advertiser, if message is NULL default message is used.
00212     virtual INT startAdvertiser(const XFcBtUUID &aUuid, const CHAR8 *aMessage);
00213 
00214     //! Callback for device discovery.
00215     virtual void deviceDiscovery(const XFcLinkedList<XFcHostEntry *> &aHostEntry);
00216     
00217     //! Callback for server discovery.
00218     virtual void deviceDiscovery(const XFcLinkedList<XFcAdvertiser *> &aAdvertiser);
00219 
00220     //! Gets device local name 
00221     virtual INT deviceLocalName(XFcName &aName);
00222     
00223     //! Virtual destructor. Closes all open tasks and deletes all created objects.
00224     virtual ~XFuBluetoothMultiNetwork();
00225 
00226 };
00227 
00228 
00229 #endif // !XFUBLUETOOTHMULTINETWORK_H_INCLUDED
00230 

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