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

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

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