BluezQt 5.109.0
Properties | Signals | Public Member Functions | Static Public Member Functions | List of all members
BluezQt::Manager

Bluetooth manager. More...

#include <BluezQt/Manager>

Properties

QList< AdapterPtr > adapters
 
bool bluetoothBlocked
 
bool bluetoothOperational
 
QList< DevicePtr > devices
 
bool initialized
 
bool operational
 
Rfkill * rfkill
 
AdapterPtr usableAdapter
 

Signals

void adapterAdded (AdapterPtr adapter)
 Indicates that adapter was added.
 
void adapterChanged (AdapterPtr adapter)
 Indicates that at least one of the adapter's properties have changed.
 
void adapterRemoved (AdapterPtr adapter)
 Indicates that adapter was removed.
 
void allAdaptersRemoved ()
 Indicates that all adapters were removed.
 
void bluetoothBlockedChanged (bool blocked)
 Indicates that Bluetooth blocked state have changed.
 
void bluetoothOperationalChanged (bool operational)
 Indicates that Bluetooth operational state have changed.
 
void deviceAdded (DevicePtr device)
 Indicates that a new device was added (eg.
 
void deviceChanged (DevicePtr device)
 Indicates that at least one of the device's properties have changed.
 
void deviceRemoved (DevicePtr device)
 Indicates that a device was removed.
 
void operationalChanged (bool operational)
 Indicates that operational state have changed.
 
void usableAdapterChanged (AdapterPtr adapter)
 Indicates that usable adapter have changed.
 

Public Member Functions

 Manager (QObject *parent=nullptr)
 Creates a new Manager object.
 
 ~Manager () override
 Destroys a Manager object.
 
AdapterPtr adapterForAddress (const QString &address) const
 Returns an adapter for specified address.
 
AdapterPtr adapterForUbi (const QString &ubi) const
 Returns an adapter for specified UBI.
 
QList< AdapterPtr > adapters () const
 Returns a list of all adapters.
 
DevicePtr deviceForAddress (const QString &address) const
 Returns a device for specified address.
 
DevicePtr deviceForUbi (const QString &ubi) const
 Returns a device for specified UBI.
 
QList< DevicePtr > devices () const
 Returns a list of all devices.
 
InitManagerJobinit ()
 Creates a new init job.
 
bool isBluetoothBlocked () const
 Returns whether Bluetooth is blocked.
 
bool isBluetoothOperational () const
 Returns whether Bluetooth is operational.
 
bool isInitialized () const
 Returns whether the manager is initialized.
 
bool isOperational () const
 Returns whether the manager is operational.
 
MediaPtr media () const
 Returns the media interface.
 
PendingCallregisterAgent (Agent *agent)
 Registers agent.
 
PendingCallregisterProfile (Profile *profile)
 Registers profile.
 
PendingCallrequestDefaultAgent (Agent *agent)
 Requests default agent.
 
Rfkill * rfkill () const
 
bool setBluetoothBlocked (bool blocked)
 Sets a Bluetooth blocked state.
 
PendingCallunregisterAgent (Agent *agent)
 Unregisters agent.
 
PendingCallunregisterProfile (Profile *profile)
 Unregisters profile.
 
AdapterPtr usableAdapter () const
 Returns a usable adapter.
 

Static Public Member Functions

static PendingCallstartService ()
 Attempts to start org.bluez service by D-Bus activation.
 

Detailed Description

Bluetooth manager.

The entry point to communicate with system BlueZ daemon.

The typical usecase is to work with usableAdapter() (any powered adapter), but it is also possible to use specific adapter.

You must call init() before other functions can be used.

The only functions that can be used before initialization are two rfkill-related functions: isBluetoothBlocked() and setBluetoothBlocked().

Example use in C++ code:

BluezQt::InitManagerJob *job = manager->init();
job->start();
connect(job, &BluezQt::InitManagerJob::result, ...);
Init manager job.
Definition initmanagerjob.h:27
void result(InitManagerJob *job)
Indicates that the job have finished.
void start()
Starts the job asynchronously.
Bluetooth manager.
Definition manager.h:78
InitManagerJob * init()
Creates a new init job.

In QML, manager is a singleton and initialization is started when first using the manager. You don't need to track initialized state, just use property binding.

Example use in QML code:

import QtQuick 2.2
import org.kde.bluezqt 1.0 as BluezQt
Item {
property QtObject manager : BluezQt.Manager
property devicesCount : manager.devices.length
property adaptersCount : manager.adapters.length
Component.onCompleted: {
console.log("Manager operational:", manager.operational)
}
}
Manager(QObject *parent=nullptr)
Creates a new Manager object.
Note
All communication with BlueZ daemon happens asynchronously. Almost all methods returns PendingCall to help track the call progress and to check for any errors.
If manager is not operational, all methods that returns a PendingCall will fail with PendingCall::InternalError.
See also
InitManagerJob

Constructor & Destructor Documentation

◆ Manager()

BluezQt::Manager::Manager ( QObject *  parent = nullptr)
explicit

Creates a new Manager object.

Parameters
parent

◆ ~Manager()

BluezQt::Manager::~Manager ( )
override

Destroys a Manager object.

Member Function Documentation

◆ adapterAdded

void BluezQt::Manager::adapterAdded ( AdapterPtr  adapter)
signal

Indicates that adapter was added.

◆ adapterChanged

void BluezQt::Manager::adapterChanged ( AdapterPtr  adapter)
signal

Indicates that at least one of the adapter's properties have changed.

◆ adapterForAddress()

AdapterPtr BluezQt::Manager::adapterForAddress ( const QString &  address) const

Returns an adapter for specified address.

Parameters
addressaddress of adapter (eg. "1C:E5:C3:BC:94:7E")
Returns
null if there is no adapter with specified address

◆ adapterForUbi()

AdapterPtr BluezQt::Manager::adapterForUbi ( const QString &  ubi) const

Returns an adapter for specified UBI.

Parameters
ubiUBI of adapter (eg. "/org/bluez/hci0")
Returns
null if there is no adapter with specified UBI

◆ adapterRemoved

void BluezQt::Manager::adapterRemoved ( AdapterPtr  adapter)
signal

Indicates that adapter was removed.

◆ adapters()

QList< AdapterPtr > BluezQt::Manager::adapters ( ) const

Returns a list of all adapters.

Returns
list of adapters

◆ allAdaptersRemoved

void BluezQt::Manager::allAdaptersRemoved ( )
signal

Indicates that all adapters were removed.

◆ bluetoothBlockedChanged

void BluezQt::Manager::bluetoothBlockedChanged ( bool  blocked)
signal

Indicates that Bluetooth blocked state have changed.

◆ bluetoothOperationalChanged

void BluezQt::Manager::bluetoothOperationalChanged ( bool  operational)
signal

Indicates that Bluetooth operational state have changed.

◆ deviceAdded

void BluezQt::Manager::deviceAdded ( DevicePtr  device)
signal

Indicates that a new device was added (eg.

found by discovery).

◆ deviceChanged

void BluezQt::Manager::deviceChanged ( DevicePtr  device)
signal

Indicates that at least one of the device's properties have changed.

◆ deviceForAddress()

DevicePtr BluezQt::Manager::deviceForAddress ( const QString &  address) const

Returns a device for specified address.

Note
There may be more devices with the same address (same device in multiple adapters). In this case, the first found device will be returned while preferring powered adapters in search.
Parameters
addressaddress of device (eg. "40:79:6A:0C:39:75")
Returns
null if there is no device with specified address

◆ deviceForUbi()

DevicePtr BluezQt::Manager::deviceForUbi ( const QString &  ubi) const

Returns a device for specified UBI.

Parameters
ubiUBI of device (eg. "/org/bluez/hci0/dev_40_79_6A_0C_39_75")
Returns
null if there is no device with specified UBI

◆ deviceRemoved

void BluezQt::Manager::deviceRemoved ( DevicePtr  device)
signal

Indicates that a device was removed.

◆ devices()

QList< DevicePtr > BluezQt::Manager::devices ( ) const

Returns a list of all devices.

Returns
list of devices

◆ init()

InitManagerJob * BluezQt::Manager::init ( )

Creates a new init job.

Returns
init manager job

◆ isBluetoothBlocked()

bool BluezQt::Manager::isBluetoothBlocked ( ) const

Returns whether Bluetooth is blocked.

Bluetooth is blocked if rfkill state for Bluetooth is either SOFT_BLOCKED or HARD_BLOCKED.

Note
This requires read access to /dev/rfkill.
Returns
true if Bluetooth is blocked

◆ isBluetoothOperational()

bool BluezQt::Manager::isBluetoothOperational ( ) const

Returns whether Bluetooth is operational.

Bluetooth is operational when manager is operational and there is a valid usable adapter.

Returns
true if Bluetooth is operational

◆ isInitialized()

bool BluezQt::Manager::isInitialized ( ) const

Returns whether the manager is initialized.

Returns
true if manager is initialized

◆ isOperational()

bool BluezQt::Manager::isOperational ( ) const

Returns whether the manager is operational.

The manager is operational when initialization was successful and BlueZ system daemon is running.

Returns
true if manager is operational

◆ media()

MediaPtr BluezQt::Manager::media ( ) const

Returns the media interface.

Returns
media
Deprecated:
since 5.57, use Adapter::media() instead.

◆ operationalChanged

void BluezQt::Manager::operationalChanged ( bool  operational)
signal

Indicates that operational state have changed.

◆ registerAgent()

PendingCall * BluezQt::Manager::registerAgent ( Agent agent)

Registers agent.

This agent will be used for for all actions triggered by the application. Eg. show a PIN code in pairing process.

Possible errors: PendingCall::InvalidArguments, PendingCall::AlreadyExists

Parameters
agentagent to be registered
Returns
void pending call

◆ registerProfile()

PendingCall * BluezQt::Manager::registerProfile ( Profile profile)

Registers profile.

Possible errors: PendingCall::InvalidArguments, PendingCall::AlreadyExists

Parameters
profileprofile to be registered
Returns
void pending call

◆ requestDefaultAgent()

PendingCall * BluezQt::Manager::requestDefaultAgent ( Agent agent)

Requests default agent.

This requests to make the application agent the default agent.

Possible errors: PendingCall::DoesNotExist

Parameters
agentregistered agent
Returns
void pending call

◆ setBluetoothBlocked()

bool BluezQt::Manager::setBluetoothBlocked ( bool  blocked)

Sets a Bluetooth blocked state.

This may fail either due to insufficient permissions or because rfkill state is HARD_BLOCKED. In that case, this function returns false.

Note
This requires write access to /dev/rfkill.
Returns
true if unblocking rfkill devices succeeded

◆ startService()

static PendingCall * BluezQt::Manager::startService ( )
static

Attempts to start org.bluez service by D-Bus activation.

Possible return values are 1 if the service was started, 2 if the service is already running or error if the service could not be started.

Returns
quint32 pending call

◆ unregisterAgent()

PendingCall * BluezQt::Manager::unregisterAgent ( Agent agent)

Unregisters agent.

Possible errors: PendingCall::DoesNotExist

Parameters
agentagent to be unregistered
Returns
void pending call

◆ unregisterProfile()

PendingCall * BluezQt::Manager::unregisterProfile ( Profile profile)

Unregisters profile.

Possible errors: PendingCall::DoesNotExist

Parameters
profileprofile to be unregistered
Returns
void pending call

◆ usableAdapter()

AdapterPtr BluezQt::Manager::usableAdapter ( ) const

Returns a usable adapter.

Usable adapter is any adapter that is currently powered on.

Returns
usable adapter

◆ usableAdapterChanged

void BluezQt::Manager::usableAdapterChanged ( AdapterPtr  adapter)
signal

Indicates that usable adapter have changed.