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

XFuBluetoothMultiNetwork.cpp

Go to the documentation of this file.
00001 /*!
00002  * \file
00003  * X-Forge Engine <br>
00004  * Copyright 2000-2002 Fathammer Ltd
00005  *
00006  * \brief Default implementation for a Bluetooth communication manager.
00007  *
00008  * $Id: XFuBluetoothMultiNetwork.cpp,v 1.9 2003/10/02 11:43:01 slehti Exp $
00009  * $Date: 2003/10/02 11:43:01 $
00010  * $Revision: 1.9 $
00011  */
00012 
00013 #include <xforge.h>
00014 
00015 #include <xfcore/net/XFcBtHandler.h>
00016 #include <xfcore/net/XFcBtClientWin.h>
00017 #include <xfcore/net/XFcObjectDataFrame.h>
00018 #include <xfcore/net/XFcCommunicationScheduler.h>
00019 #include <xfcore/net/XFcCommunicationConstants.h>
00020 #include <xfcore/net/socket/XFcSocketConstants.h>
00021 #include <xfcore/net/socket/XFcBtAddress.h>
00022 #include <xfcore/net/XFcUnknownSender.h>
00023 #include <xfcore/net/XFcClientLost.h>
00024 #include <xfcore/net/XFcDataReceiver.h>
00025 #include <xfcore/net/XFcObjectDataFrame.h>
00026 #include <xfcore/net/socket/XFcHostEntry.h>
00027 #include <xfcore/net/socket/XFcBtHostResolver.h>
00028 #include <xfcore/net/socket/XFcBtAdvertiser.h>
00029 #include <xfcore/net/XFcUdpEngine.h>
00030 #include <xfcore/net/socket/XFcBtCommService.h>
00031 #include <xfcore/net/socket/XFcBtServerSearch.h>
00032 #include <xfcore/net/socket/XFcBtUUID.h>
00033 #include <xfcore/net/socket/XFcName.h>
00034 #include <xfutil/XFuSerializable.h>
00035 #include <xfutil/XFuNetwork.h>
00036 #include <xfutil/XFuNetworkEventHandler.h>
00037 #include <xfutil/XFuBluetoothMultiNetwork.h>
00038 
00039 
00040 XFuBluetoothMultiNetwork * XFuBluetoothMultiNetwork::create()
00041 {
00042     XFuBluetoothMultiNetwork * manager = new XFuBluetoothMultiNetwork;
00043     if (manager != NULL && !manager->init())
00044     {
00045         delete manager;
00046         return NULL;
00047     }
00048     return manager;
00049 }
00050 
00051 
00052 XFuBluetoothMultiNetwork::XFuBluetoothMultiNetwork() 
00053 {
00054     mNetworkEventHandlers = NULL;
00055     mCommunicationScheduler = NULL;
00056     mCommunicationHandler = NULL;
00057     mDefaultDataReceiver = NULL;
00058     mHostResolver = NULL;
00059     mCommunicationService = NULL;
00060    
00061     mAcceptGameToken = 0;
00062     mCommunicationHandlerId = -1;
00063     mGamePort = 0;
00064     mSlaveClientId = -1;
00065 
00066     mService = NULL;
00067     mBtServerSearch = NULL;
00068 }
00069 
00070 
00071 XFuBluetoothMultiNetwork::~XFuBluetoothMultiNetwork()
00072 {
00073     closeService();
00074     deleteAllClients();
00075 
00076     removeAllEventHandlers();
00077 
00078     delete mService;
00079     delete mHostResolver;
00080     delete mNetworkEventHandlers;
00081 }
00082 
00083 
00084 INT XFuBluetoothMultiNetwork::init()
00085 {
00086     mCommunicationScheduler = (XFcCommunicationScheduler *)XFcCore::getCommunicationScheduler();
00087     if (mNetworkEventHandlers == NULL)
00088         mNetworkEventHandlers = XFuDynamicArray<XFuNetworkEventHandler*>::create(5);
00089 
00090     if (mCommunicationScheduler == NULL ||
00091         mNetworkEventHandlers == NULL) return 0;
00092 
00093     return 1;
00094 
00095 }
00096 
00097 
00098 void XFuBluetoothMultiNetwork::runCommunicationScheduler()
00099 {
00100     mCommunicationScheduler->runScheduler();
00101 }
00102 
00103 
00104 void XFuBluetoothMultiNetwork::reset()
00105 {
00106     XFCLOGFUNC("reset()", 3);
00107     closeService();
00108     deleteAllClients();
00109     removeAllEventHandlers();
00110 
00111     
00112     mAcceptGameToken = 0;
00113     init();
00114 
00115 }
00116 
00117 
00118 INT XFuBluetoothMultiNetwork::initEnable(UINT16 aPort, INT aIsServer)
00119 {
00120     XFCLOGFUNC("initEnable()", 3);
00121     closeService();
00122     deleteAllClients();
00123 
00124 
00125     mService = XFcBtCommService::create();
00126 
00127     mGamePort = aPort;
00128     
00129     // Are we bluetooth server, bt-slave.
00130     if (aIsServer)
00131     {
00132         if (aPort == 0 && mService)
00133             mGamePort = mService->getFirstFreeRFCOMMPort();
00134 
00135     }
00136     else
00137     {
00138         // Create piconet. Works only with master device.
00139         mService->createPiconet();
00140         mService->lockPiconet();
00141     }
00142     
00143     if (mGamePort == XFCNET_NOT_SUPPORTED)
00144         mGamePort  = 0;
00145 
00146     mCommunicationHandler = XFcBtHandler::create(aIsServer);
00147     
00148     return (mCommunicationHandler && mService) ? 1 : 0;
00149 
00150 }
00151 
00152 
00153 INT XFuBluetoothMultiNetwork::enableClientService(UINT16 aPort)
00154 {
00155     XFCLOGFUNC("enableClientService()", 3);
00156 
00157     XFcBtAddress *address = XFcBtAddress::create();
00158     XFcBtClientWin *client = XFcBtClientWin::create(NULL);
00159 
00160     if (address && client && initEnable(aPort, 1))
00161     {
00162         address->setPort(mGamePort);
00163 
00164         // Max client count must be more than 1
00165         INT32 maxClients = 2;
00166 
00167         // Open server, will return 1 if success else 0
00168         if (mCommunicationHandler->openServer(*address, maxClients))
00169         {
00170             mCommunicationHandler->setUnknownSenderHandler(this);
00171             mCommunicationHandler->setClientLost(this);
00172 
00173             mCommunicationHandlerId = mCommunicationScheduler->addCommunicationHandler(mCommunicationHandler);
00174             mCommunicationHandler->listenConnection(*client);
00175 
00176             INT32 clientId = mCommunicationScheduler->addClient(client);
00177 
00178             if (clientId != XFCNET_CLIENTADD_ERROR)
00179             {
00180 
00181                 // XXXX
00182                 mClients.put(clientId, client);
00183                 delete address;
00184                 address = NULL;
00185                 mSlaveClientId = clientId;
00186 
00187                 return 1;
00188             }
00189         }
00190     }
00191     delete address;
00192     address = NULL;
00193     delete client;
00194     client = NULL;
00195 
00196     return 0;
00197 }
00198 
00199 
00200 INT XFuBluetoothMultiNetwork::enableHostService()
00201 {
00202     XFCLOGFUNC("enableServerService()", 3);
00203     INT error = 0;
00204 
00205     if (initEnable(0, 0))
00206     {
00207         mCommunicationHandler->setUnknownSenderHandler(this);
00208         mCommunicationHandler->setClientLost(this);
00209 
00210         mCommunicationHandlerId = mCommunicationScheduler->addCommunicationHandler(mCommunicationHandler);
00211         error = 1;
00212     }
00213     return error;
00214 }
00215 
00216 
00217 void XFuBluetoothMultiNetwork::closeService()
00218 {
00219     XFCLOGFUNC("closeService()", 3);
00220 
00221     // Unlock and destroy piconet if any.
00222     mService->unlockPiconet();
00223     mService->destroyPiconet();
00224 
00225     stopDeviceDiscovery();
00226     stopClientDiscovery();
00227     stopAdvertiser();
00228 
00229     if (mCommunicationHandler != NULL)
00230     {
00231         mCommunicationHandler->closeService();
00232         mCommunicationScheduler->removeCommunicationHandler(mCommunicationHandlerId);
00233         delete mCommunicationHandler;
00234         mCommunicationHandler = NULL;
00235     }
00236     delete mService;
00237     mService = NULL;
00238 }
00239 
00240 
00241 UINT32 XFuBluetoothMultiNetwork::getAcceptGameToken()
00242 {
00243     return mAcceptGameToken;
00244 }
00245 
00246 
00247 void XFuBluetoothMultiNetwork::setAcceptGameToken(UINT32 aAcceptGameToken)
00248 {
00249     mAcceptGameToken = aAcceptGameToken;
00250 }
00251 
00252 
00253 void XFuBluetoothMultiNetwork::sendGameConnectPacket(INT32 aClientId, UINT32 aGameToken)
00254 {
00255     XFcObjectDataFrame *frame = getPacketFrame(aClientId, XFCNET_NONGUARANTEED);
00256     if (frame)
00257     {
00258         frame->setReceiverId(0);
00259         void *buffer = frame->lock();
00260         if (buffer)
00261         {
00262             memcpy(buffer, &aGameToken, 4);
00263             frame->setPacketSize(4);
00264         }
00265         frame->unlock();
00266     }
00267 }
00268 
00269 
00270 
00271 void XFuBluetoothMultiNetwork::deleteAllClients()
00272 {
00273     XFCLOGFUNC("deleteAllClients()", 3);
00274     if (!mCommunicationScheduler)
00275         return;
00276 
00277     XFcHashtableIterator<UINT32, XFcBtClientWin *> itClient;
00278 
00279     while (mClients.size() > 0)
00280     {
00281         itClient = mClients.begin();
00282         INT32 key = itClient.getKey();
00283         XFcClientCommWin *base_client = getClient(key);
00284         mCommunicationScheduler->removeClient(key);
00285         base_client->deinitializeClient();
00286         mClients.remove(key);
00287         delete base_client;
00288     }
00289     mSlaveClientId = -1;
00290 }
00291 
00292 
00293 void XFuBluetoothMultiNetwork::removeAllClients()
00294 {
00295     XFCLOGFUNC("removeAllClients()", 3);
00296     if (!mCommunicationHandler)
00297         return;
00298 
00299     XFcHashtableIterator<UINT32, XFcBtClientWin *> itClient;
00300 
00301     while (mClients.size() > 0)
00302     {
00303         itClient = mClients.begin();
00304         INT32 key = itClient.getKey();
00305         removeClient(key);
00306     }
00307 
00308 }
00309 
00310 
00311 XFcDataReceiver * XFuBluetoothMultiNetwork::getDefaultDataReceiver()
00312 {
00313     return mDefaultDataReceiver;
00314 }
00315 
00316 
00317 void XFuBluetoothMultiNetwork::setDefaultDataReceiver(XFcDataReceiver *aReceiver)
00318 {
00319     mDefaultDataReceiver = aReceiver;
00320     mCommunicationScheduler->setDataReceiver(aReceiver);
00321 }
00322 
00323 
00324 XFcDataReceiver * XFuBluetoothMultiNetwork::getDataReceiver(UINT32 aId)
00325 {
00326     return mCommunicationScheduler->getDataReceiver(aId);
00327 }
00328 
00329 
00330 INT XFuBluetoothMultiNetwork::addDataReceiver(UINT32 aId, XFcDataReceiver *aReceiver)
00331 {
00332     return mCommunicationScheduler->addDataReceiver(aId, aReceiver);
00333 }
00334 
00335 
00336 XFcDataReceiver * XFuBluetoothMultiNetwork::removeDataReceiver(UINT32 aId)
00337 {
00338     return mCommunicationScheduler->removeDataReceiver(aId);
00339 }
00340 
00341 
00342 void XFuBluetoothMultiNetwork::addEventHandler(XFuNetworkEventHandler *aHandler)
00343 {
00344     mNetworkEventHandlers->put(aHandler);
00345 }
00346 
00347 
00348 void XFuBluetoothMultiNetwork::removeEventHandler(XFuNetworkEventHandler *aHandler)
00349 {
00350     mNetworkEventHandlers->remove(aHandler);
00351 }
00352 
00353 
00354 void XFuBluetoothMultiNetwork::removeAllEventHandlers()
00355 {
00356     while (!mNetworkEventHandlers->isEmpty()) mNetworkEventHandlers->remove();
00357 }
00358 
00359 
00360 XFcClientCommWin * XFuBluetoothMultiNetwork::getClient(INT32 aClientId)
00361 {
00362     XFCLOGFUNC("getClient()", 3);
00363     XFcHashtable<UINT32, XFcBtClientWin *>::iterator it;
00364     XFcClientCommWin * value = NULL;
00365 
00366     it = mClients.find(aClientId);
00367 
00368     if(it.isValid())
00369     {
00370         value = it.getValue();
00371     }
00372 
00373     return value;
00374 }
00375 
00376 
00377 INT32 XFuBluetoothMultiNetwork::addClient(XFcAddress *aAddress, INT32 /*aTimeoutTime*/)
00378 {
00379     XFCLOGFUNC("addClient()", 3);
00380     XFcBtClientWin *client = NULL;
00381     INT32 clientId = -1;
00382 
00383     if (!aAddress)
00384         return -1;
00385 
00386     if ((client = XFcBtClientWin::create(aAddress)) == NULL)
00387         return -1;
00388 
00389     switch (aAddress->getType())
00390     {
00391         case XFCNET_AFBT:
00392             if (client->openClient() != -1)
00393             {
00394                 clientId = mCommunicationScheduler->addClient(client);
00395                 if (clientId != XFCNET_CLIENTADD_ERROR && clientId != XFCNET_ERROR)
00396                 {
00397                     // XXXX
00398                     mClients.put(clientId, client);
00399                 }
00400             }
00401 
00402             break;
00403         default:
00404             XFcCore::systemPanic(XFCSTR("This address type is not supported"));
00405             break;
00406     }
00407 
00408     if (clientId == -1)
00409         delete client;
00410 
00411     return clientId;
00412 }
00413 
00414 
00415 void XFuBluetoothMultiNetwork::removeClient(INT32 aClientId)
00416 {
00417     XFCLOGFUNC("removeClient()", 3);
00418     INT32 cId = 0;
00419 
00420     // If communication handler is not created we do not have anything to do.
00421     if (!mCommunicationHandler)
00422         return;
00423 
00424     XFcBtClientWin * oldClient = (XFcBtClientWin *)getClient(aClientId);
00425 
00426     if (oldClient)
00427         oldClient->deinitializeClient();
00428     {
00429         // Remove client and deinitialize it
00430         mCommunicationScheduler->removeClient(aClientId);
00431         mClients.remove(aClientId);
00432 
00433         // Listening client is created to backbuffer for incoming connections.
00434         // If client is removed we create new for new connection.
00435         // Service works as BT-Slave
00436         if (mCommunicationHandler->isServer())
00437         {
00438             XFcBtClientWin *client = NULL;
00439             if ((client = XFcBtClientWin::create(NULL)) != NULL)
00440             {
00441                 mCommunicationHandler->listenConnection(*client);
00442                 cId = mCommunicationScheduler->addClient(client);
00443 
00444                 if (cId != XFCNET_CLIENTADD_ERROR && cId != XFCNET_ERROR)
00445                 {
00446                     // XXXX
00447                     mClients.put(cId, client);
00448                     mSlaveClientId = cId;
00449                 }
00450                 else
00451                     XFcCore::systemPanic(XFCSTR("removeClient(), add client"));
00452             }
00453             else
00454                 XFcCore::systemPanic(XFCSTR("removeClient(), new listener"));
00455         }
00456     }
00457     delete oldClient;
00458 }
00459 
00460 
00461 INT32 XFuBluetoothMultiNetwork::getRoundTripTime(INT32 aClientId)
00462 {
00463     return mCommunicationScheduler->getRoundTripTime(aClientId);
00464 }
00465 
00466 
00467 XFcObjectDataFrame * XFuBluetoothMultiNetwork::getPacketFrame(INT32 aClientId, XFCNET_MESSAGE_SLOT aSlot)
00468 {
00469     return mCommunicationScheduler->getPacketFrame(aClientId, aSlot);
00470 }
00471 
00472 
00473 XFcObjectDataFrame * XFuBluetoothMultiNetwork::getRecentStateFrame(INT32 aClientId, INT32 aRecentId)
00474 {
00475     return mCommunicationScheduler->getRecentStateFrame(aClientId, aRecentId);
00476 }
00477 
00478 
00479 void XFuBluetoothMultiNetwork::removeRecentStateFrame(INT32 aClientId, INT32 aRecentId)
00480 {
00481     mCommunicationScheduler->removeRecentStateFrame(aClientId, aRecentId);
00482 }
00483 
00484 
00485 INT32 XFuBluetoothMultiNetwork::send(INT32 aClientId,
00486                                                UINT32 aReceiverId,
00487                                                XFCNET_MESSAGE_SLOT aSlot,
00488                                                XFuSerializable *aSerializable)
00489 {
00490     XFcObjectDataFrame *frame = getPacketFrame(aClientId, aSlot);
00491     INT32 size = -1;
00492     if (frame)
00493     {
00494 
00495         void *buffer = frame->lock();
00496         if (buffer)
00497         {
00498             size = aSerializable->serialize((CHAR8*)buffer, frame->sizeofBuffer());
00499             // If size is set to -1 XForge does not send the frame and frame is released.
00500             frame->setPacketSize(size);
00501             frame->setReceiverId(aReceiverId);
00502 
00503         }
00504         frame->unlock();
00505     }
00506     return size;
00507 }
00508 
00509 
00510 INT32 XFuBluetoothMultiNetwork::sendRecentState(INT32 aClientId,
00511                                                           UINT32 aReceiverId,
00512                                                           INT32 aRecentId,
00513                                                           XFuSerializable *aSerializable)
00514 {
00515     XFcObjectDataFrame *frame = getRecentStateFrame(aClientId, aRecentId);
00516     INT32 size = -1;
00517 
00518     if (frame)
00519     {
00520         void *buffer = frame->lock();
00521         if (buffer)
00522         {
00523             size = aSerializable->serialize((CHAR8*)buffer, frame->sizeofBuffer());
00524             frame->setPacketSize(size);
00525             frame->setReceiverId(aReceiverId);
00526 
00527         }
00528         frame->unlock();
00529     }
00530     return size;
00531 }
00532 
00533 
00534 void XFuBluetoothMultiNetwork::clientLost(INT32 aClientId)
00535 {
00536     XFCLOGFUNC("clientLost()", 3);
00537     removeClient(aClientId);
00538 
00539     INT32 handlersNum = mNetworkEventHandlers->size();
00540     INT32 i;
00541 
00542     for (i = 0; i < handlersNum; i++)
00543     {
00544         mNetworkEventHandlers->get(i)->handleClientLost(aClientId);
00545     }
00546 }
00547 
00548 
00549 INT XFuBluetoothMultiNetwork::handleSender(const void *aAddress, const CHAR8 *aData, INT32 aLen)
00550 {
00551     XFCLOGFUNC("handleSender()", 3);
00552 
00553     // Used magic number mAcceptGameToken here.
00554     // Make sure that gameToken is not addjusted with same value than mAcceptGameToken is.
00555     UINT32 gameToken = ~mAcceptGameToken;
00556 
00557     if (((XFcAddress *)aAddress)->getType() == (INT32)XFCNET_AFBT && aLen == 4)
00558     {
00559         XFcBtClientWin * slaveClient = (XFcBtClientWin *)getClient(mSlaveClientId);
00560         // Get packet data
00561         memcpy(&gameToken, aData, 4);
00562 
00563         // Test if packet data is game connect token packet
00564         if (gameToken == mAcceptGameToken)
00565         {
00566             if (slaveClient->isClientActive() == XFCNET_BT_LINESTATUS_ONHOLD)
00567             {
00568                 // Accept client connection
00569                 slaveClient->acceptConnection(1);
00570 
00571                 INT32 i;
00572                 for (i = 0; i < (INT32)mNetworkEventHandlers->size(); i++)
00573                 {
00574                     // Notify event handler
00575                     mNetworkEventHandlers->get(i)->handleClientAccepted(i);
00576 
00577                 }
00578             }
00579         }
00580     }
00581     if (((XFcAddress *)aAddress)->getType() != (INT32)XFCNET_AFBT ||
00582         aLen != 4 ||
00583         gameToken != mAcceptGameToken)
00584     {
00585 
00586         XFcBtClientWin * slaveClient = (XFcBtClientWin *)getClient(mSlaveClientId);
00587 
00588         if (slaveClient->isClientActive() == XFCNET_BT_LINESTATUS_ONHOLD)
00589         {
00590             // Disconnect client
00591             slaveClient->acceptConnection(0);
00592 
00593             // Remove client, if we are bt-slave new listener is automatically created by remove client.
00594             removeClient(mSlaveClientId);
00595 
00596         }
00597     }
00598     return 0;
00599 }
00600 
00601 
00602 INT XFuBluetoothMultiNetwork::startDeviceDiscovery()
00603 {
00604     XFCLOGFUNC("startDeviceDiscovery()", 3);
00605     // Stop device discovery
00606     stopDeviceDiscovery();
00607 
00608     // Delete host resolver
00609     if (!mHostResolver)
00610         mHostResolver = XFcBtHostResolver::create();
00611 
00612     // Do the device discovery, async found devices are returned througth deviceDiscovery callback.
00613     if (mHostResolver)
00614         return (mHostResolver->inquiry(this) == XFCNET_ERROR) ? 0 : 1;
00615 
00616     return 0;
00617 }
00618 
00619 
00620 void XFuBluetoothMultiNetwork::stopDeviceDiscovery()
00621 {
00622     XFCLOGFUNC("stopDeviceDiscovery()", 3);
00623     if (mHostResolver)
00624         mHostResolver->cancelInquiry();
00625 }
00626 
00627 
00628 INT XFuBluetoothMultiNetwork::startClientDiscovery(const XFcBtUUID &aUuid, const XFcBtAddress *aAddress)
00629 {
00630     XFCLOGFUNC("startClientDiscovery()", 3);
00631 
00632     INT retval = 0;
00633 
00634     if (!mService)
00635         return 0;
00636 
00637     mUUID = aUuid;
00638     
00639     if (aAddress)
00640     {
00641         // Have to fix this.
00642         XFcAdvertiser *advr = NULL;
00643         if ((advr = XFcBtAdvertiser::create(*aAddress, NULL, 0)) != NULL)
00644             retval = mService->inquiry(*advr, this, &mUUID);
00645         delete advr;
00646         return retval;
00647     }
00648     else
00649     {
00650         delete mBtServerSearch;
00651         if ((mBtServerSearch = XFcBtServerSearch::create()) != NULL)
00652             return (mBtServerSearch->inquiry(this, mUUID) == XFCNET_ERROR) ? 0 : 1;
00653     }
00654     return retval;
00655     //return 0;
00656 }
00657 
00658 
00659 void XFuBluetoothMultiNetwork::stopClientDiscovery()
00660 {
00661     // Not supported for 1.1 release
00662     XFCLOGFUNC("stopClientDiscovery()", 3);
00663 
00664     if (mService)
00665         mService->cancelInquiry();
00666 
00667     if (mBtServerSearch)
00668         mBtServerSearch->cancelInquiry();
00669 
00670     delete mBtServerSearch;
00671     mBtServerSearch = NULL;
00672 }
00673 
00674 
00675 void XFuBluetoothMultiNetwork::deviceDiscovery(const XFcLinkedList<XFcHostEntry *> &aHostEntry)
00676 {
00677     XFcLinkedList<XFcHostEntry *>::forwardIterator it;
00678     INT32 handlersNum = mNetworkEventHandlers->size();
00679     INT32 i;
00680 
00681     if (aHostEntry.size() != 0)
00682     {
00683         for (it = aHostEntry.forwardBegin(); it != aHostEntry.forwardEnd(); it++)
00684         {
00685             for (i = 0; i < handlersNum; ++i)
00686                 mNetworkEventHandlers->get(i)->handleDeviceDiscovered(it.getData());
00687         }
00688     }
00689 }
00690 
00691 
00692 void XFuBluetoothMultiNetwork::deviceDiscovery(const XFcLinkedList<XFcAdvertiser *> &aAdvertiser)
00693 {
00694     XFcLinkedList<XFcAdvertiser *>::forwardIterator it;
00695     INT32 handlersNum = mNetworkEventHandlers->size();
00696     INT32 i;
00697 
00698     if (aAdvertiser.size() != 0)
00699     {
00700         for (it = aAdvertiser.forwardBegin(); it != aAdvertiser.forwardEnd(); it++)
00701         {
00702             for (i = 0; i < handlersNum; i++)
00703                 mNetworkEventHandlers->get(i)->handleAdvertiseDiscovered(it.getData());
00704         }
00705     }
00706 }
00707 
00708 
00709 INT XFuBluetoothMultiNetwork::startAdvertiser(const XFcBtUUID &aUuid, const CHAR8 *aMessage)
00710 {
00711     XFCLOGFUNC("startAdveriser()", 3);
00712     
00713     XFcBtAdvertiser *advertise = NULL;
00714 
00715     if (!mService)
00716         return 0;
00717 
00718     if ((advertise = XFcBtAdvertiser::create()) == NULL)
00719         return 0;
00720 
00721     mUUID = aUuid;
00722     
00723     // Create default message if not given any
00724     if (aMessage == NULL)
00725         advertise->setMessageHeader("X-Forge server", 14);
00726     else
00727         advertise->setMessageHeader(aMessage, strlen(aMessage));
00728 
00729     // Set game port for advertiser
00730     advertise->setGamePort(mGamePort);
00731 
00732     advertise->setAvailability(0xff); // Fully available.
00733 
00734     INT error = mService->advertise(*advertise, &mUUID);
00735 
00736     delete advertise;
00737 
00738     return (error == XFCNET_ERROR) ? 0 : 1;
00739 
00740 }
00741 
00742 
00743 void XFuBluetoothMultiNetwork::stopAdvertiser()
00744 {
00745     XFCLOGFUNC("stopAdvertiser()", 3);
00746    
00747     if (!mService)
00748         return;
00749 
00750     mService->cancelAdvertise();
00751 }
00752 
00753 
00754 INT XFuBluetoothMultiNetwork::deviceLocalName(XFcName &aName)
00755 {
00756     // Delete host resolver
00757     if (!mHostResolver)
00758         mHostResolver = XFcBtHostResolver::create();
00759 
00760     // Do the device discovery, async found devices are returned througth deviceDiscovery callback.
00761     if (mHostResolver)
00762     {
00763         INT error = mHostResolver->localName(aName);
00764 
00765         if (error != XFCNET_ERROR)
00766         {
00767             if (aName.mLen < 0x40)
00768                 aName.mName[aName.mLen] = '\0';
00769 
00770             return 1;
00771         }
00772     }
00773     return 0;
00774 }

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