本文整理汇总了C++中QBluetoothAddress::isNull方法的典型用法代码示例。如果您正苦于以下问题:C++ QBluetoothAddress::isNull方法的具体用法?C++ QBluetoothAddress::isNull怎么用?C++ QBluetoothAddress::isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBluetoothAddress
的用法示例。
在下文中一共展示了QBluetoothAddress::isNull方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tst_construction
void tst_QBluetoothHostInfo::tst_construction()
{
QFETCH(QString, btAddress);
QFETCH(QString, name);
QFETCH(bool, validBtAddress);
QBluetoothAddress empty;
QVERIFY(empty.isNull());
QBluetoothHostInfo setter;
QBluetoothAddress addr(btAddress);
setter.setName(name);
setter.setAddress(addr);
QCOMPARE(setter.name(), name);
QCOMPARE(setter.address().toString(), btAddress);
QCOMPARE(setter.address().isNull(), !validBtAddress);
setter.setAddress(empty);
QCOMPARE(setter.name(), name);
QCOMPARE(setter.address().toString(), QString("00:00:00:00:00:00"));
QCOMPARE(setter.address().isNull(), true);
setter.setName(QString());
QCOMPARE(setter.name(), QString());
QCOMPARE(setter.address().toString(), QString("00:00:00:00:00:00"));
QCOMPARE(setter.address().isNull(), true);
setter.setAddress(addr);
QCOMPARE(setter.name(), QString());
QCOMPARE(setter.address().toString(), btAddress);
QCOMPARE(setter.address().isNull(), !validBtAddress);
}
示例2: tst_construction
void tst_QBluetoothAddress::tst_construction()
{
QFETCH(quint64, addressUInt);
QFETCH(QString, addressS12);
QFETCH(QString, addressS17);
{
QBluetoothAddress address;
QVERIFY(address.isNull());
}
{
/* construct from quint64 */
QBluetoothAddress address(addressUInt);
QVERIFY(!address.isNull());
QVERIFY(address.toUInt64() == addressUInt);
QCOMPARE(address.toString(), addressS17);
}
{
/* construct from string without colons */
QBluetoothAddress address(addressS12);
QVERIFY(!address.isNull());
QVERIFY(address.toUInt64() == addressUInt);
QCOMPARE(address.toString(), addressS17);
}
{
/* construct from string with colons */
QBluetoothAddress address(addressS17);
QVERIFY(!address.isNull());
QVERIFY(address.toUInt64() == addressUInt);
QCOMPARE(address.toString(), addressS17);
}
{
QString empty;
QBluetoothAddress address(empty);
QVERIFY(address.isNull());
}
{
QBluetoothAddress address(addressUInt);
QBluetoothAddress copy(address);
QVERIFY(address.toUInt64() == copy.toUInt64());
}
}
示例3: localName
QString QBluetoothSocketPrivate::localName() const
{
const QBluetoothAddress address = localAddress();
if (address.isNull())
return QString();
QBluetoothLocalDevice device(address);
return device.name();
}
示例4: setRemoteAddress
/*!
Sets the remote device address to \a address. If \a address is default constructed,
services will be discovered on all contactable Bluetooth devices. A new remote
address can only be set while there is no service discovery in progress; otherwise
this function returns false.
On some platforms such as Blackberry the service discovery might lead to pairing requests.
Therefore it is not recommended to do service discoveries on all devices.
\sa remoteAddress()
*/
bool QBluetoothServiceDiscoveryAgent::setRemoteAddress(const QBluetoothAddress &address)
{
if (isActive())
return false;
if (!address.isNull())
d_ptr->singleDevice = true;
d_ptr->deviceAddress = address;
return true;
}
示例5: findAdapterForAddress
/*!
Finds the path for the local adapter with \a wantedAddress or an empty string
if no local adapter with the given address can be found.
If \a wantedAddress is \c null it returns the first/default adapter or an empty
string if none is available.
If \a ok is false the lookup was aborted due to a dbus error and this function
returns an empty string.
*/
QString findAdapterForAddress(const QBluetoothAddress &wantedAddress, bool *ok = 0)
{
OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"),
QStringLiteral("/"),
QDBusConnection::systemBus());
QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects();
reply.waitForFinished();
if (reply.isError()) {
if (ok)
*ok = false;
return QString();
}
typedef QPair<QString, QBluetoothAddress> AddressForPathType;
QList<AddressForPathType> localAdapters;
ManagedObjectList managedObjectList = reply.value();
for (ManagedObjectList::const_iterator it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) {
const QDBusObjectPath &path = it.key();
const InterfaceList &ifaceList = it.value();
for (InterfaceList::const_iterator jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) {
const QString &iface = jt.key();
if (iface == QStringLiteral("org.bluez.Adapter1")) {
AddressForPathType pair;
pair.first = path.path();
pair.second = QBluetoothAddress(ifaceList.value(iface).value(
QStringLiteral("Address")).toString());
if (!pair.second.isNull())
localAdapters.append(pair);
break;
}
}
}
if (ok)
*ok = true;
if (localAdapters.isEmpty())
return QString(); // -> no local adapter found
if (wantedAddress.isNull())
return localAdapters.front().first; // -> return first found adapter
foreach (const AddressForPathType &pair, localAdapters) {
if (pair.second == wantedAddress)
return pair.first; // -> found local adapter with wanted address
}
return QString(); // nothing matching found
}
示例6: _q_readNotify
/*!
* Process all incoming HCI events. Function cannot process anything else but events.
*/
void HciManager::_q_readNotify()
{
unsigned char buffer[HCI_MAX_EVENT_SIZE];
int size;
size = ::read(hciSocket, buffer, sizeof(buffer));
if (size < 0) {
if (errno != EAGAIN && errno != EINTR)
qCWarning(QT_BT_BLUEZ) << "Failed reading HCI events:" << qt_error_string(errno);
return;
}
const unsigned char *data = buffer;
// Not interested in anything but valid HCI events
if ((size < HCI_EVENT_HDR_SIZE + 1) || buffer[0] != HCI_EVENT_PKT)
return;
hci_event_hdr *header = (hci_event_hdr *)(&buffer[1]);
size = size - HCI_EVENT_HDR_SIZE - 1;
data = data + HCI_EVENT_HDR_SIZE + 1;
if (header->plen != size) {
qCWarning(QT_BT_BLUEZ) << "Invalid HCI event packet size";
return;
}
qCDebug(QT_BT_BLUEZ) << "HCI event triggered, type:" << hex << header->evt;
switch (header->evt) {
case EVT_ENCRYPT_CHANGE:
{
const evt_encrypt_change *event = (evt_encrypt_change *) data;
qCDebug(QT_BT_BLUEZ) << "HCI Encrypt change, status:"
<< (event->status == 0 ? "Success" : "Failed")
<< "handle:" << hex << event->handle
<< "encrypt:" << event->encrypt;
QBluetoothAddress remoteDevice = addressForConnectionHandle(event->handle);
if (!remoteDevice.isNull())
emit encryptionChangedEvent(remoteDevice, event->status == 0);
}
break;
default:
break;
}
}
示例7: error
/*!
Constructs a new QBluetoothServiceDiscoveryAgent for \a deviceAdapter and with \a parent.
It uses \a deviceAdapter for the service search. If \a deviceAdapter is default constructed
the resulting QBluetoothServiceDiscoveryAgent object will use the local default Bluetooth adapter.
If a \a deviceAdapter is specified that is not a local adapter \l error() will be set to
\l InvalidBluetoothAdapterError. Therefore it is recommended to test the error flag immediately after
using this constructor.
\sa error()
*/
QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent)
: QObject(parent), d_ptr(new QBluetoothServiceDiscoveryAgentPrivate(deviceAdapter))
{
d_ptr->q_ptr = this;
if (!deviceAdapter.isNull()) {
const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
foreach (const QBluetoothHostInfo &hostInfo, localDevices) {
if (hostInfo.address() == deviceAdapter)
return;
}
d_ptr->error = InvalidBluetoothAdapterError;
d_ptr->errorString = tr("Invalid Bluetooth adapter address");
}
}
示例8: tst_address
void tst_QBluetoothHostInfo::tst_address()
{
QFETCH(QString, addressString);
QBluetoothAddress address(addressString);
QVERIFY(!address.isNull());
QCOMPARE(address.toString(), addressString);
QBluetoothHostInfo info;
QBluetoothAddress result = info.address();
QVERIFY(result.isNull());
info.setAddress(address);
QCOMPARE(info.address().toString(), addressString);
}
示例9: requestPairing
void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing)
{
if (address.isNull()) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error,
QBluetoothLocalDevice::PairingError));
return;
}
const Pairing current_pairing = pairingStatus(address);
if (current_pairing == pairing) {
QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection,
Q_ARG(QBluetoothAddress, address),
Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
return;
}
d_ptr->requestPairing(address, pairing);
}
示例10: hciForAddress
int HciManager::hciForAddress(const QBluetoothAddress &deviceAdapter)
{
if (hciSocket < 0)
return -1;
bdaddr_t adapter;
convertAddress(deviceAdapter.toUInt64(), adapter.b);
struct hci_dev_req *devRequest = 0;
struct hci_dev_list_req *devRequestList = 0;
struct hci_dev_info devInfo;
const int devListSize = sizeof(struct hci_dev_list_req)
+ HCI_MAX_DEV * sizeof(struct hci_dev_req);
devRequestList = (hci_dev_list_req *) malloc(devListSize);
if (!devRequestList)
return -1;
QScopedPointer<hci_dev_list_req, QScopedPointerPodDeleter> p(devRequestList);
memset(p.data(), 0, devListSize);
p->dev_num = HCI_MAX_DEV;
devRequest = p->dev_req;
if (ioctl(hciSocket, HCIGETDEVLIST, devRequestList) < 0)
return -1;
for (int i = 0; i < devRequestList->dev_num; i++) {
devInfo.dev_id = (devRequest+i)->dev_id;
if (ioctl(hciSocket, HCIGETDEVINFO, &devInfo) < 0) {
continue;
}
int result = memcmp(&adapter, &devInfo.bdaddr, sizeof(bdaddr_t));
if (result == 0 || deviceAdapter.isNull()) // addresses match
return devInfo.dev_id;
}
return -1;
}
示例11: pairingStatus
QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const
{
if (address.isNull())
return Unpaired;
OrgBluezDeviceInterface *device = getDevice(address, d_ptr);
if(!device)
return Unpaired;
QDBusPendingReply<QVariantMap> deviceReply = device->GetProperties();
deviceReply.waitForFinished();
if (deviceReply.isError())
return Unpaired;
QVariantMap map = deviceReply.value();
if (map.value(QLatin1String("Trusted")).toBool() && map.value(QLatin1String("Paired")).toBool())
return AuthorizedPaired;
else if (map.value(QLatin1String("Paired")).toBool())
return Paired;
else
return Unpaired;
}
示例12: _q_processFetchedUuids
void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids(
const QBluetoothAddress &address, const QList<QBluetoothUuid> &uuids)
{
//don't leave more data through if we are not interested anymore
if (discoveredDevices.count() == 0)
return;
//could not find any service for the current address/device -> go to next one
if (address.isNull() || uuids.isEmpty()) {
_q_serviceDiscoveryFinished();
return;
}
if (QT_BT_ANDROID().isDebugEnabled()) {
qCDebug(QT_BT_ANDROID) << "Found UUID for" << address.toString()
<< "\ncount: " << uuids.count();
QString result;
for (int i = 0; i<uuids.count(); i++)
result += uuids.at(i).toString() + QStringLiteral("**");
qCDebug(QT_BT_ANDROID) << result;
}
/* In general there are two uuid events per device.
* We'll wait for the second event to arrive before we process the UUIDs.
* We utilize a timeout to catch cases when the second
* event doesn't arrive at all.
* Generally we assume that the second uuid event carries the most up-to-date
* set of uuids and discard the first events results.
*/
if (sdpCache.contains(address)) {
//second event
QPair<QBluetoothDeviceInfo,QList<QBluetoothUuid> > pair = sdpCache.take(address);
//prefer second uuid set over first
populateDiscoveredServices(pair.first, uuids);
if (discoveredDevices.count() == 1 && sdpCache.isEmpty()) {
//last regular uuid data set from OS -> we finish here
_q_serviceDiscoveryFinished();
}
} else {
//first event
QPair<QBluetoothDeviceInfo,QList<QBluetoothUuid> > pair;
pair.first = discoveredDevices.at(0);
pair.second = uuids;
if (pair.first.address() != address)
return;
sdpCache.insert(address, pair);
//the discovery on the last device cannot immediately finish
//we have to grant the 2 seconds timeout delay
if (discoveredDevices.count() == 1) {
Q_Q(QBluetoothServiceDiscoveryAgent);
QTimer::singleShot(4000, q, SLOT(_q_fetchUuidsTimeout()));
return;
}
_q_serviceDiscoveryFinished();
}
}
示例13: requestPairing
void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing)
{
if (address.isNull()) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
return;
}
const Pairing current_pairing = pairingStatus(address);
if (current_pairing == pairing) {
QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
Q_ARG(QBluetoothLocalDevice::Pairing, pairing));
return;
}
if(pairing == Paired || pairing == AuthorizedPaired) {
d_ptr->address = address;
d_ptr->pairing = pairing;
if(!d_ptr->agent) {
d_ptr->agent = new OrgBluezAgentAdaptor(d_ptr);
bool res = QDBusConnection::systemBus().registerObject(d_ptr->agent_path, d_ptr);
if(!res) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
qWarning() << "Failed to register agent";
return;
}
}
if(current_pairing == Paired && pairing == AuthorizedPaired) {
OrgBluezDeviceInterface *device = getDevice(address, d_ptr);
if (!device) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
return;
}
QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(true));
deviceReply.waitForFinished();
if(deviceReply.isError()) {
qWarning() << Q_FUNC_INFO << "reply failed" << deviceReply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
return;
}
delete device;
QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::AuthorizedPaired));
}
else if(current_pairing == AuthorizedPaired && pairing == Paired) {
OrgBluezDeviceInterface *device = getDevice(address, d_ptr);
if (!device) {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
return;
}
QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(false));
deviceReply.waitForFinished();
if(deviceReply.isError()) {
qWarning() << Q_FUNC_INFO << "reply failed" << deviceReply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
return;
}
delete device;
QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Paired));
}
else {
QDBusPendingReply<QDBusObjectPath> reply =
d_ptr->adapter->CreatePairedDevice(address.toString(),
QDBusObjectPath(d_ptr->agent_path),
QLatin1String("NoInputNoOutput"));
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), d_ptr, SLOT(pairingCompleted(QDBusPendingCallWatcher*)));
if(reply.isError())
qWarning() << Q_FUNC_INFO << reply.error() << d_ptr->agent_path;
}
}
else if(pairing == Unpaired) {
QDBusPendingReply<QDBusObjectPath> reply = this->d_ptr->adapter->FindDevice(address.toString());
reply.waitForFinished();
if(reply.isError()) {
qWarning() << Q_FUNC_INFO << "failed to find device" << reply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
return;
}
QDBusPendingReply<> removeReply = this->d_ptr->adapter->RemoveDevice(reply.value());
removeReply.waitForFinished();
if(removeReply.isError()) {
qWarning() << Q_FUNC_INFO << "failed to remove device" << removeReply.error();
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError));
} else {
QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address),
Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Unpaired));
//.........这里部分代码省略.........