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.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 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 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 protected: 00087 00088 //! Deletes all clients. 00089 virtual void deleteAllClients(); 00090 00091 //! Protected constructor. 00092 XFuBluetoothMultiNetwork(); 00093 00094 //! Initializes this Bluetooth communication manager. 00095 INT init(); 00096 00097 //! Initializes enable service. 00098 INT initEnable(UINT16 aPort, INT aIsServer); 00099 00100 public: 00101 00102 //! Static constructor. 00103 static XFuBluetoothMultiNetwork * create(); 00104 00105 //! Enables the Bluetooth communication handler and opens it for service. Opens device as bluetooth slave. 00106 /*! 00107 * \param aPort is clients BT-Slave port. If port is set to 0 the port is selected by system. 00108 */ 00109 virtual INT enableClientService(UINT16 aPort); 00110 00111 //! Enables the Bluetooth communication handler and opens it for service. Opens device as bluetooth master. 00112 virtual INT enableHostService(); 00113 00114 //! Closes the currently active service (communication handler). 00115 virtual void closeService(); 00116 00117 //! Resets the communication manager. 00118 virtual void reset(); 00119 00120 //! Runs the communication scheduler. 00121 virtual void runCommunicationScheduler(); 00122 00123 //! Connection lost handler (XFuClientLost) (callback). 00124 virtual void clientLost(INT32 aClientId); 00125 00126 //! Adds a client with the specific address. 00127 /*! \return The client id or XFCNET_CLIENTADD_ERROR if failed. 00128 */ 00129 virtual INT32 addClient(XFcAddress *aAddress, INT32 aTimeoutTime = 15000); 00130 00131 //! Returns the specified client. 00132 virtual XFcClientCommWin * getClient(INT32 aClientId); 00133 00134 //! Removes the specified client. 00135 virtual void removeClient(INT32 aClientId); 00136 00137 //! Removes all clients. 00138 virtual void removeAllClients(); 00139 00140 //! Returns the game token that is checked before new clients are allowed to connect. 00141 virtual UINT32 getAcceptGameToken(); 00142 00143 //! Sets the game token that is checked before new clients are allowed to connect. 00144 virtual void setAcceptGameToken(UINT32 aAcceptGameToken); 00145 00146 //! Sends a game connection packet. 00147 virtual void sendGameConnectPacket(INT32 aClientId, UINT32 aGameToken); 00148 00149 //! Returns a pointer to the default data receiver. 00150 virtual XFcDataReceiver * getDefaultDataReceiver(); 00151 00152 //! Returns the specified data receiver. 00153 virtual XFcDataReceiver * getDataReceiver(UINT32 aId); 00154 00155 //! Adds a new data receiver. 00156 virtual INT addDataReceiver(UINT32 aId, XFcDataReceiver *aReceiver); 00157 00158 //! Sets the default data receiver. 00159 virtual void setDefaultDataReceiver(XFcDataReceiver *aReceiver); 00160 00161 //! Removes a data receiver. 00162 virtual XFcDataReceiver * removeDataReceiver(UINT32 aId); 00163 00164 //! Handle data from an unknown client (callback). 00165 virtual INT handleSender(const void *aAddress, const CHAR8 *aData, INT32 aLen); 00166 00167 //! Get packet frame. 00168 virtual XFcObjectDataFrame * getPacketFrame(INT32 aClientId, XFCNET_MESSAGE_SLOT aSlot); 00169 00170 //! Get recent state frame. 00171 virtual XFcObjectDataFrame * getRecentStateFrame(INT32 aClientId, INT32 aRecentId); 00172 00173 //! Remove recent state frame. 00174 virtual void removeRecentStateFrame(INT32 aClientId, INT32 aRecentId); 00175 00176 //! Returns the round trip time for the specified client. 00177 virtual INT32 getRoundTripTime(INT32 aClientId); 00178 00179 //! Sends a serializable object to the specified client. 00180 virtual INT32 send(INT32 aClientId, UINT32 aReceiverId, XFCNET_MESSAGE_SLOT aSlot, XFuSerializable *aSerializable); 00181 00182 //! Sends a serializable object to the specified client as a recent state packet. 00183 virtual INT32 sendRecentState(INT32 aClientId, UINT32 aReceiverId, INT32 aRecentId, XFuSerializable *aSerializable); 00184 00185 //! Adds a communication event handler. 00186 virtual void addEventHandler(XFuNetworkEventHandler *aHandler); 00187 00188 //! Removes a communication event handler. 00189 virtual void removeEventHandler(XFuNetworkEventHandler *aHandler); 00190 00191 //! Removes all communication event handlers. 00192 virtual void removeAllEventHandlers(); 00193 00194 //! Stops device discovery. 00195 virtual void stopDeviceDiscovery(); 00196 00197 //! Stops server discovery. 00198 virtual void stopClientDiscovery(); 00199 00200 //! Stops server advertiser. 00201 virtual void stopAdvertiser(); 00202 00203 //! Starts device discovery. 00204 virtual INT startDeviceDiscovery(); 00205 00206 //! Starts server discovery, if address is NULL engine will search througth all available bt devices. 00207 virtual INT startClientDiscovery(const XFcBtAddress *aAddress); 00208 00209 //! Starts advertiser, if message is NULL default message is used. 00210 virtual INT startAdvertiser(const CHAR8 *aMessage); 00211 00212 //! Callback for device discovery. 00213 virtual void deviceDiscovery(const XFcLinkedList<XFcHostEntry *> &aHostEntry); 00214 //! Callback for server discovery. 00215 virtual void deviceDiscovery(const XFcLinkedList<XFcAdvertiser *> &aAdvertiser); 00216 00217 //! Virtual destructor. Closes all open tasks and deletes all created objects. 00218 virtual ~XFuBluetoothMultiNetwork(); 00219 00220 }; 00221 00222 00223 #endif // !XFUBLUETOOTHMULTINETWORK_H_INCLUDED
![]() | ||||
![]() |
Confidential Copyright © 2002-2003 Fathammer | with doxygen by Dimitri van Heesch |