// 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; }
/* * 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; }
// 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()); }
/*! 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; }