// ---------------------------------------------------------------------------- // CBluetoothEngine::HandleConnectorErrorL(THostName aName,TInt aError) // ---------------------------------------------------------------------------- void CBluetoothEngine::HandleConnectorErrorL(THostName aName, TInt aError) { if (aError) { // delete errored connection for (TInt idx = 0; idx < KMaxConnectedDevices; idx++) { if (iConnectedDevices[idx]) { THostName name; name = iConnectedDevices[idx]->iName; //echo to other slaves than the sender if (name.Compare(aName) == 0) { delete iConnectedDevices[idx]; iConnectedDevices[idx] = NULL; } } } // Is there more connection running? iIsMaster = EFalse; for (TInt idx = 0; idx < KMaxConnectedDevices; idx++) { if (iConnectedDevices[idx]) { iIsMaster = ETrue; break; } } } }
// Wraps DiscoverDevices() to provide a Python method interface. // Arguments: // - boolean value of whether to perform name lookup // // Returns list of (address, name, (service,major,minor)) tuples detailing the // found devices. static PyObject* LightBlue_DiscoverDevices(PyObject* self, PyObject* args) { bool lookupNames; if (!PyArg_ParseTuple(args, "b", &lookupNames)) return NULL; // run the discovery TDeviceDataList devDataList; TInt err = DiscoverDevices(&devDataList, lookupNames); if (err) return SPyErr_SetFromSymbianOSErr(err); // put the results into a python list TInt i; TDeviceData *devData; TBuf8<6*2+5> addrString; PyObject *addrList = PyList_New(0); // python list to hold results for( i=0; i<devDataList.Count(); i++ ) { devData = devDataList[i]; // convert address to string DevAddressToString(devData->iDeviceAddr, addrString); PyObject *devValues; if (lookupNames) { THostName name = devData->iDeviceName; devValues = Py_BuildValue("(s#u#(iii))", addrString.Ptr(), addrString.Length(), // s# - address name.Ptr(), name.Length(), // u# - name devData->iServiceClass, // i - service class devData->iMajorClass, // i - major class devData->iMinorClass // i - minor class ); } else { devValues = Py_BuildValue("(s#O(iii))", addrString.Ptr(), addrString.Length(), // s# - address Py_None, devData->iServiceClass, // i - service class devData->iMajorClass, // i - major class devData->iMinorClass // i - minor class ); } // add tuple to list PyList_Append(addrList, devValues); } devDataList.ResetAndDestroy(); return addrList; }
// Wraps LookupName() to provide a Python method interface. // Arguments: // - address of the device to look up. Note that the address // is expected without colons!! e.g. "000D9319C868" // - True/False - if True, performs a remote name request even if the device // name is known in the cache from a previous request. // // Returns the name (a Python unicode string). static PyObject* LightBlue_LookupName(PyObject* self, PyObject* args) { const char *addr; bool ignoreCache; if (!PyArg_ParseTuple(args, "sb", &addr, &ignoreCache)) return NULL; THostName deviceName; TBTDevAddr wantedAddr; TBuf16<128> buf; buf.Copy(_L8(addr)); wantedAddr.SetReadable(buf); TInt err = LookupName(wantedAddr, &deviceName, ignoreCache); if (err) return SPyErr_SetFromSymbianOSErr(err); return Py_BuildValue("u#", deviceName.Ptr(), deviceName.Length()); }
/* * Get hostname. */ PJ_DEF(const pj_str_t*) pj_gethostname(void) { static char buf[PJ_MAX_HOSTNAME]; static pj_str_t hostname; PJ_CHECK_STACK(); if (hostname.ptr == NULL) { RHostResolver &resv = PjSymbianOS::Instance()->GetResolver(PJ_AF_INET); TRequestStatus reqStatus; THostName tmpName; resv.GetHostName(tmpName, reqStatus); User::WaitForRequest(reqStatus); hostname.ptr = pj_unicode_to_ansi((const wchar_t*)tmpName.Ptr(), tmpName.Length(), buf, sizeof(buf)); hostname.slen = tmpName.Length(); } return &hostname; }
TBool CDHCPOptionSipServerDomains::GetSipServerDomains(TInt aIndex, THostName& aName) { TInt domainIdx = 0; TUint8* pChar = const_cast<TUint8*>(GetBodyDes().Ptr()); TUint labelLength = 0; // Walk the list of domain names while(*pChar++ != NULL && domainIdx != aIndex) { labelLength = *(pChar - 1); *(pChar - 1) = '.'; TBuf8<0x100> tmp; tmp.Copy(pChar, labelLength); aName.Copy(tmp); pChar += labelLength; } return EFalse; }
void CGpsDataHandler::RunL() { #ifndef __SERIES60_3X__ TPtr8 pBuffer = iBuffer->Des(); THostName aHostName; TInquirySockAddr aInquiry; TInt aServiceClass; switch(iEngineStatus) { case EGpsResolving: if(iStatus == KErrNone) { // Next device found aHostName = iNameEntry().iName; aInquiry = TInquirySockAddr::Cast(iNameEntry().iAddr); aServiceClass = aInquiry.MajorServiceClass(); iBTAddr.SetBTAddr(aInquiry.BTAddr()); iBTAddr.SetPort(1); if(aServiceClass & 0x08 || aHostName.Find(_L("GPS")) != KErrNotFound || aHostName.Find(_L("gps")) != KErrNotFound) { // Found Positioning device if(iSocket.Open(iSocketServ, KBTAddrFamily, KSockStream, KRFCOMM) == KErrNone) { iEngineStatus = EGpsConnecting; //iResolver.Close(); iSocket.Connect(iBTAddr, iStatus); SetActive(); } else { iSocketServ.Close(); iEngineStatus = EGpsDisconnected; iObserver->GpsError(EGpsConnectionFailed); } } else { // Get next iResolver.Next(iNameEntry, iStatus); SetActive(); } // TODO - Is correct device? } else if(iStatus == KErrHostResNoMoreResults) { // No (more) devices found iSocketServ.Close(); iEngineStatus = EGpsDisconnected; iGpsDeviceResolved = false; iObserver->GpsError(EGpsDeviceUnavailable); } else { iSocketServ.Close(); iEngineStatus = EGpsDisconnected; iObserver->GpsError(EGpsDeviceUnavailable); } break; case EGpsConnecting: if(iStatus == KErrNone) { iEngineStatus = EGpsReading; iGpsDeviceResolved = true; iResolver.Close(); pBuffer.Zero(); iSocket.Recv(iChar, 0, iStatus); SetActive(); } else { if(iGpsDeviceResolved) { iSocket.Close(); iSocketServ.Close(); iEngineStatus = EGpsDisconnected; iObserver->GpsError(EGpsConnectionFailed); } else { // Get next iEngineStatus = EGpsResolving; iResolver.Next(iNameEntry, iStatus); SetActive(); } } break; case EGpsReading: if(iStatus == KErrNone) { iEngineStatus = EGpsConnected; if(pBuffer.Length() + iChar.Length() > pBuffer.MaxLength()) { iBuffer = iBuffer->ReAlloc(pBuffer.MaxLength()+iChar.Length()); pBuffer.Set(iBuffer->Des()); } pBuffer.Append(iChar); ProcessData(); } else { iSocket.Close(); iSocketServ.Close(); iEngineStatus = EGpsDisconnected; iObserver->GpsError(EGpsConnectionFailed); } break; case EGpsDisconnecting: iResolver.Close(); iSocket.Close(); iSocketServ.Close(); iEngineStatus = EGpsDisconnected; break; default:; } #else switch(iEngineStatus) { case EGpsReading: iEngineStatus = EGpsConnected; if(iStatus == KErrNone) { TPosition aPosition; iPositionInfo.GetPosition(aPosition); iObserver->GpsData(aPosition.Latitude(), aPosition.Longitude(), aPosition.HorizontalAccuracy()); if( !iGpsWarmedUp ) { iGpsWarmedUp = true; TPositionUpdateOptions aOptions; aOptions.SetUpdateTimeOut(30000000); aOptions.SetAcceptPartialUpdates(true); iPositioner.SetUpdateOptions(aOptions); } } else { iObserver->GpsError(EGpsDeviceUnavailable); } break; case EGpsDisconnecting: iPositioner.Close(); iPositionServ.Close(); iEngineStatus = EGpsDisconnected; break; default:; } #endif }
/*! Transforms Symbian device name, address and service classes to QBluetootDeviceInfo. */ QBluetoothDeviceInfo BluetoothLinkManagerDeviceDiscoverer::currentDeviceDataToQBluetoothDeviceInfo() const { // extract device information from results and map them to QBluetoothDeviceInfo #ifdef EIR_SUPPORTED TBluetoothNameRecordWrapper eir(m_entry()); TInt bufferlength = 0; TInt err = KErrNone; QString deviceName; bufferlength = eir.GetDeviceNameLength(); if (bufferlength > 0) { TBool nameComplete; HBufC *deviceNameBuffer = 0; TRAP(err,deviceNameBuffer = HBufC::NewLC(bufferlength)); if(err) deviceName = QString(); else { TPtr ptr = deviceNameBuffer->Des(); err = eir.GetDeviceName(ptr,nameComplete); if (err == KErrNone /*&& nameComplete*/) { if(!nameComplete) qWarning() << "device name incomplete"; // isn't it better to get an incomplete name than getting nothing? deviceName = QString::fromUtf16(ptr.Ptr(), ptr.Length()).toUpper(); } else deviceName = QString(); CleanupStack::PopAndDestroy(deviceNameBuffer); } } QList<QBluetoothUuid> serviceUidList; RExtendedInquiryResponseUUIDContainer uuidContainer; QBluetoothDeviceInfo::DataCompleteness completenes = QBluetoothDeviceInfo::DataUnavailable; if (eir.GetServiceClassUuids(uuidContainer) == KErrNone) { TInt uuidCount = uuidContainer.UUIDs().Count(); if (uuidCount > 0) { for (int i = 0; i < uuidCount; ++i) { TPtrC8 shortFormUUid(uuidContainer.UUIDs()[i].ShortestForm()); if (shortFormUUid.Size() == 2) { QBluetoothUuid uuid(ntohs(*reinterpret_cast<const quint16 *>(shortFormUUid.Ptr()))); if (uuidContainer.GetCompleteness(RExtendedInquiryResponseUUIDContainer::EUUID16)) completenes = QBluetoothDeviceInfo::DataComplete; else completenes = QBluetoothDeviceInfo::DataIncomplete; serviceUidList.append(uuid); }else if (shortFormUUid.Size() == 4) { QBluetoothUuid uuid(ntohl(*reinterpret_cast<const quint32 *>(shortFormUUid.Ptr()))); if (uuidContainer.GetCompleteness(RExtendedInquiryResponseUUIDContainer::EUUID32)) completenes = QBluetoothDeviceInfo::DataComplete; else completenes = QBluetoothDeviceInfo::DataIncomplete; serviceUidList.append(uuid); }else if (shortFormUUid.Size() == 16) { QBluetoothUuid uuid(*reinterpret_cast<const quint128 *>(shortFormUUid.Ptr())); if (uuidContainer.GetCompleteness(RExtendedInquiryResponseUUIDContainer::EUUID128)) completenes = QBluetoothDeviceInfo::DataComplete; else completenes = QBluetoothDeviceInfo::DataIncomplete; serviceUidList.append(uuid); } } } } uuidContainer.Close(); bufferlength = 0; QByteArray manufacturerData; bufferlength = eir.GetVendorSpecificDataLength(); if (bufferlength > 0) { HBufC8 *msd = 0; TRAP(err,HBufC8::NewLC(bufferlength)); if(err) manufacturerData = QByteArray(); else { TPtr8 temp = msd->Des(); if (eir.GetVendorSpecificData(temp)) manufacturerData = s60Desc8ToQByteArray(temp); else manufacturerData = QByteArray(); CleanupStack::PopAndDestroy(msd); } } // Get transmission power level TInt8 transmissionPowerLevel = 0; eir.GetTxPowerLevel(transmissionPowerLevel); // unique address of the device const TBTDevAddr symbianDeviceAddress = static_cast<TBTSockAddr> (m_entry().iAddr).BTAddr(); QBluetoothAddress bluetoothAddress = qTBTDevAddrToQBluetoothAddress(symbianDeviceAddress); // format symbian major/minor numbers quint32 deviceClass = qTPackSymbianDeviceClass(m_addr); QBluetoothDeviceInfo deviceInfo(bluetoothAddress, deviceName, deviceClass); deviceInfo.setRssi(transmissionPowerLevel); deviceInfo.setServiceUuids(serviceUidList, completenes); deviceInfo.setManufacturerSpecificData(manufacturerData); #else // device name THostName symbianDeviceName = m_entry().iName; QString deviceName = QString::fromUtf16(symbianDeviceName.Ptr(), symbianDeviceName.Length()).toUpper(); // unique address of the device const TBTDevAddr symbianDeviceAddress = static_cast<TBTSockAddr> (m_entry().iAddr).BTAddr(); QBluetoothAddress bluetoothAddress = qTBTDevAddrToQBluetoothAddress(symbianDeviceAddress); // format symbian major/minor numbers quint32 deviceClass = qTPackSymbianDeviceClass(m_addr); QBluetoothDeviceInfo deviceInfo(bluetoothAddress, deviceName, deviceClass); if (m_addr.Rssi()) deviceInfo.setRssi(m_addr.Rssi()); #endif if (!deviceInfo.rssi()) deviceInfo.setRssi(1); deviceInfo.setCached(false); //TODO cache support missing from devicediscovery API //qDebug()<< "Discovered device: name="<< deviceName <<", address=" << bluetoothAddress.toString() <<", class=" << deviceClass; return deviceInfo; }