10#elif defined(QT_ANDROID_BLUETOOTH)
12#elif defined(QT_WINRT_BLUETOOTH)
14#elif defined(QT_OSX_BLUETOOTH)
22#include <QtCore/QLoggingCategory>
23#include <QSocketNotifier>
234 qCDebug(QT_BT) <<
"Using Bluetooth dbus socket implementation";
237 qCDebug(QT_BT) <<
"Using Bluetooth raw socket implementation";
240#elif defined(QT_ANDROID_BLUETOOTH)
242#elif defined(QT_WINRT_BLUETOOTH)
244#elif defined(QT_OSX_BLUETOOTH)
245 return new QBluetoothSocketPrivateDarwin();
260 Q_D(QBluetoothSocketBase);
290 Q_D(QBluetoothSocketBase);
322 Q_D(
const QBluetoothSocketBase);
332 Q_D(
const QBluetoothSocketBase);
333 return d->bytesToWrite();
358 Q_D(QBluetoothSocketBase);
395 Q_D(QBluetoothSocketBase);
419 Q_D(QBluetoothSocketBase);
432 Q_D(
const QBluetoothSocketBase);
433 return d->socketType;
441 Q_D(
const QBluetoothSocketBase);
450 Q_D(
const QBluetoothSocketBase);
451 return d->socketError;
459 Q_D(
const QBluetoothSocketBase);
460 return d->errorString;
493#ifdef QT_OSX_BLUETOOTH
496 Q_D(QBluetoothSocketBase);
521 Q_D(
const QBluetoothSocketBase);
531 Q_D(QBluetoothSocketBase);
547#ifdef QT_OSX_BLUETOOTH
548 qCWarning(QT_BT) <<
"listening socket is not supported by IOBluetooth";
552 if (
d->readNotifier) {
553 d->readNotifier->setEnabled(
false);
564 Q_D(
const QBluetoothSocketBase);
573 Q_D(QBluetoothSocketBase);
574 d->socketError = error_;
586 Q_D(QBluetoothSocketBase);
589 qCDebug(QT_BT) <<
"Starting Bluetooth service discovery";
591 if(
d->discoveryAgent) {
592 d->discoveryAgent->stop();
593 delete d->discoveryAgent;
597 d->discoveryAgent->setRemoteAddress(service.device().address());
602 this, &QBluetoothSocket::serviceDiscovered);
604 this, &QBluetoothSocket::discoveryFinished);
609 if(!service.serviceUuid().isNull())
610 filterUuids.
append(service.serviceUuid());
613 d->discoveryAgent->setUuidFilter(filterUuids);
616 Q_ASSERT(!
d->discoveryAgent->uuidFilter().isEmpty());
618 qCDebug(QT_BT) <<
"UUID filter" <<
d->discoveryAgent->uuidFilter();
625 Q_D(QBluetoothSocketBase);
626 qCDebug(QT_BT) <<
"FOUND SERVICE!" << service;
627 if (service.protocolServiceMultiplexer() > 0 || service.serverChannel() > 0) {
629 d->discoveryAgent->deleteLater();
630 d->discoveryAgent =
nullptr;
631#ifdef QT_WINRT_BLUETOOTH
632 }
else if (!
service.attribute(0xBEEF).isNull()
633 && !
service.attribute(0xBEF0).isNull()) {
635 d->discoveryAgent->deleteLater();
636 d->discoveryAgent =
nullptr;
639 qCDebug(QT_BT) <<
"Could not find port/psm for potential remote service";
643void QBluetoothSocket::discoveryFinished()
645 qCDebug(QT_BT) <<
"Socket discovery finished";
646 Q_D(QBluetoothSocketBase);
647 if (
d->discoveryAgent){
648 qCDebug(QT_BT) <<
"Didn't find any";
649 d->errorString =
tr(
"Service cannot be found");
652 d->discoveryAgent->deleteLater();
653 d->discoveryAgent =
nullptr;
662 Q_D(QBluetoothSocketBase);
666 d->discoveryAgent->disconnect();
667 d->discoveryAgent->stop();
668 d->discoveryAgent =
nullptr;
682 Q_D(
const QBluetoothSocketBase);
683 return d->localName();
688 Q_D(
const QBluetoothSocketBase);
689 return d->localAddress();
694 Q_D(
const QBluetoothSocketBase);
695 return d->localPort();
700 Q_D(
const QBluetoothSocketBase);
701 return d->peerName();
706 Q_D(
const QBluetoothSocketBase);
707 return d->peerAddress();
712 Q_D(
const QBluetoothSocketBase);
713 return d->peerPort();
718 Q_D(QBluetoothSocketBase);
720 if (!
data || maxSize <= 0) {
726 return d->writeData(
data, maxSize);
731 Q_D(QBluetoothSocketBase);
732 return d->readData(
data, maxSize);
740 Q_D(QBluetoothSocketBase);
744 d->discoveryAgent->disconnect();
745 d->discoveryAgent->stop();
746 d->discoveryAgent =
nullptr;
772 Q_D(QBluetoothSocketBase);
783 Q_D(
const QBluetoothSocketBase);
789#include "moc_qbluetoothsocket.cpp"
QVersionNumber bluetoothdVersion()
void finished()
This signal is emitted when the Bluetooth service discovery completes.
void serviceDiscovered(const QBluetoothServiceInfo &info)
This signal is emitted when the Bluetooth service described by info is discovered.
Protocol
This enum describes the socket protocol used by the service.
bool canReadLine() const override
Returns true if you can read at least one line from the device.
void connectToService(const QBluetoothServiceInfo &service, OpenMode openMode=ReadWrite)
Attempts to connect to the service described by service.
quint16 peerPort() const
Return the port number of the peer socket if available, otherwise returns 0.
void connected()
This signal is emitted when a connection is established.
QBluetooth::SecurityFlags preferredSecurityFlags() const
Returns the security parameters used for the initial connection attempt.
QString peerName() const
Returns the name of the peer device.
SocketError error() const
Returns the last error.
QString errorString() const
Returns a user displayable text string for the error.
virtual ~QBluetoothSocket()
Destroys the Bluetooth socket.
quint16 localPort() const
Returns the port number of the local socket if available, otherwise returns 0.
void doDeviceDiscovery(const QBluetoothServiceInfo &service, OpenMode openMode)
Start device discovery for service and open the socket with openMode.
void stateChanged(QBluetoothSocket::SocketState state)
This signal is emitted when the socket state changes to state.
void abort()
Aborts the current connection and resets the socket.
void setSocketState(SocketState state)
Sets the socket state to state.
qint64 bytesToWrite() const override
Returns the number of bytes that are waiting to be written.
void setPreferredSecurityFlags(QBluetooth::SecurityFlags flags)
Sets the preferred security parameter for the connection attempt to flags.
void disconnectFromService()
Attempts to close the socket.
QString localName() const
Returns the name of the local device.
bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, SocketState socketState=SocketState::ConnectedState, OpenMode openMode=ReadWrite)
Sets the socket to use socketDescriptor with a type of socketType, which is in state socketState,...
void errorOccurred(QBluetoothSocket::SocketError error)
This signal is emitted when an error occurs.
qint64 writeData(const char *data, qint64 maxSize) override
\reimp
QBluetoothSocketBasePrivate * d_ptr
void close() override
Disconnects the socket's connection with the device.
SocketState
This enum describes the state of the Bluetooth socket.
qint64 bytesAvailable() const override
Returns the number of incoming bytes that are waiting to be read.
QBluetoothAddress localAddress() const
Returns the address of the local device.
int socketDescriptor() const
Returns the platform-specific socket descriptor, if available.
QBluetoothAddress peerAddress() const
Returns the address of the peer device.
void setSocketError(SocketError error)
Sets the type of error that last occurred to error_.
QBluetoothServiceInfo::Protocol socketType() const
Returns the socket type.
bool isSequential() const override
\reimp
QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, QObject *parent=nullptr)
Constructs a Bluetooth socket of socketType type, with parent.
SocketState state() const
Returns the current state of the socket.
qint64 readData(char *data, qint64 maxSize) override
\reimp
SocketError
This enum describes Bluetooth socket error types.
void disconnected()
This signal is emitted when the socket is disconnected.
\inmodule QtCore \reentrant
void setOpenMode(QIODeviceBase::OpenMode openMode)
Sets the OpenMode of the device to openMode.
QIODeviceBase::OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false.
bool isEmpty() const noexcept
void append(parameter_type t)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
Combined button and popup list for selecting options.
Q_CORE_EXPORT QtJniTypes::Service service()
static QBluetoothSocketBasePrivate * createSocketPrivate()
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent