void CGpsDataHandler::ResolveAndConnectL() { TInt aResult; #ifndef __SERIES60_3X__ if((aResult = iSocketServ.Connect()) == KErrNone) { if(iGpsDeviceResolved) { if((aResult = iSocket.Open(iSocketServ, KBTAddrFamily, KSockStream, KRFCOMM)) == KErrNone) { iEngineStatus = EGpsConnecting; iSocket.Connect(iBTAddr, iStatus); SetActive(); } } else { _LIT(KLinkMan, "BTLinkManager"); //_LIT(KLinkMan, "RFCOMM"); TProtocolName aProtocolName(KLinkMan); if((aResult = iSocketServ.FindProtocol(aProtocolName, iProtocolDesc)) == KErrNone) { if((aResult = iResolver.Open(iSocketServ, iProtocolDesc.iAddrFamily, iProtocolDesc.iProtocol)) == KErrNone) { TInquirySockAddr aInquiry; aInquiry.SetIAC(KGIAC); //aInquiry.SetMajorServiceClass(EMajorServicePositioning); aInquiry.SetAction(KHostResName | KHostResInquiry | KHostResIgnoreCache); iResolver.GetByAddress(aInquiry, iNameEntry, iStatus); iEngineStatus = EGpsResolving; SetActive(); } } } } if(aResult != KErrNone) { iEngineStatus = EGpsDisconnected; iSocketServ.Close(); iObserver->GpsError(EGpsConnectionFailed); } #else TBool aDeviceFound = false; if((aResult = iPositionServ.Connect()) == KErrNone) { iEngineStatus = EGpsConnecting; TUint aNumOfModules; if((aResult = iPositionServ.GetNumModules(aNumOfModules)) == KErrNone) { TPositionModuleInfo aModuleInfo; TUid aModuleId; for(TUint i = 0; i < aNumOfModules && aResult == KErrNone && !aDeviceFound; i++) { if((aResult = iPositionServ.GetModuleInfoByIndex(i, aModuleInfo)) == KErrNone) { aModuleId = aModuleInfo.ModuleId(); if(aModuleInfo.IsAvailable() && aModuleInfo.TechnologyType() != TPositionModuleInfo::ETechnologyNetwork) { aDeviceFound = true; } } } if(aResult == KErrNone && aDeviceFound) { if((aResult = iPositioner.Open(iPositionServ, aModuleId)) == KErrNone) { iEngineStatus = EGpsConnected; if((aResult = iPositioner.SetRequestor(CRequestor::ERequestorService, CRequestor::EFormatApplication, _L("Buddycloud"))) == KErrNone) { iEngineStatus = EGpsReading; TPositionUpdateOptions aOptions; aOptions.SetAcceptPartialUpdates(true); iPositioner.SetUpdateOptions(aOptions); iPositioner.NotifyPositionUpdate(iPositionInfo, iStatus); SetActive(); } if(aResult != KErrNone) { iPositioner.Close(); } } } } } if(aResult != KErrNone || !aDeviceFound) { iEngineStatus = EGpsDisconnected; iPositionServ.Close(); iObserver->GpsError(EGpsConnectionFailed); } #endif }
// Performs a device discovery. Blocks until all devices are found. // Arguments: // - aDevDataList - details of each found device will be put in a TDeviceData // and added to this list // - lookupNames - whether to perform name lookups // // Returns an error code. static TInt DiscoverDevices(TDeviceDataList* aDevDataList, bool lookupNames) { TInt err = KErrNone; RSocketServ socketServer; RHostResolver hostResolver; TInquirySockAddr addr; TRequestStatus status; TNameEntry nameEntry; // connect err = socketServer.Connect(); if (err) return err; // load protocol for discovery TProtocolDesc protocolDesc; err = socketServer.FindProtocol(_L("BTLinkManager"), protocolDesc); if (!err) { // initialize host resolver err = hostResolver.Open(socketServer, protocolDesc.iAddrFamily, protocolDesc.iProtocol); if (!err) { // start device discovery by invoking remote address lookup addr.SetIAC(KGIAC); if (lookupNames) { addr.SetAction(KHostResInquiry|KHostResName|KHostResIgnoreCache); } else { addr.SetAction(KHostResInquiry|KHostResIgnoreCache); } hostResolver.GetByAddress(addr, nameEntry, status); while( User::WaitForRequest( status ), (status == KErrNone || status == KRequestPending) ) { // store new device data entry TDeviceData *devData = new (ELeave) TDeviceData(); if (lookupNames) devData->iDeviceName = nameEntry().iName; devData->iDeviceAddr = static_cast<TBTSockAddr>(nameEntry().iAddr).BTAddr(); TInquirySockAddr &isa = TInquirySockAddr::Cast(nameEntry().iAddr); devData->iServiceClass = (TInt16)isa.MajorServiceClass(); devData->iMajorClass = (TInt8)isa.MajorClassOfDevice(); devData->iMinorClass = (TInt8)isa.MinorClassOfDevice(); // add device data entry to list aDevDataList->Append(devData); // get next discovered device hostResolver.Next( nameEntry, status ); } hostResolver.Close(); } } socketServer.Close(); return err; }