13#include "agentadaptor.h"
15#include "initmanagerjob.h"
17#include "pendingcall.h"
20#include "profileadaptor.h"
27 , d(new ManagerPrivate(this))
29 Instance::setManager(
this);
41 return d->m_initialized;
46 return d->m_initialized && d->m_bluezRunning && d->m_loaded;
51 return !d->m_bluetoothBlocked && d->m_bluezRunning && d->m_loaded && d->m_usableAdapter;
56 return d->m_bluetoothBlocked;
64 d->m_rfkill->unblock();
70 return d->m_usableAdapter;
75 return d->m_adapters.values();
80 return d->m_devices.values();
86 QStringLiteral(
"/org/freedesktop/DBus"),
87 Strings::orgFreedesktopDBus(),
88 QStringLiteral(
"StartServiceByName"));
89 msg << Strings::orgBluez();
92 return new PendingCall(DBusConnection::orgBluez().asyncCall(msg), PendingCall::ReturnUint32);
97 for (
AdapterPtr adapter : std::as_const(d->m_adapters)) {
98 if (adapter->address() == address) {
107 return d->m_adapters.value(ubi);
114 for (
AdapterPtr adapter : std::as_const(d->m_adapters)) {
115 DevicePtr oneDevice = adapter->deviceForAddress(address);
123 }
else if (adapter->isPowered()) {
133 return d->m_devices.value(ubi);
140 if (!d->m_bluezAgentManager) {
146 switch (agent->capability()) {
147 case Agent::DisplayOnly:
148 capability = QStringLiteral(
"DisplayOnly");
150 case Agent::DisplayYesNo:
151 capability = QStringLiteral(
"DisplayYesNo");
153 case Agent::KeyboardOnly:
154 capability = QStringLiteral(
"KeyboardOnly");
156 case Agent::NoInputNoOutput:
157 capability = QStringLiteral(
"NoInputNoOutput");
160 capability = QStringLiteral(
"DisplayYesNo");
164 new AgentAdaptor(agent,
this);
166 if (!DBusConnection::orgBluez().registerObject(agent->
objectPath().
path(), agent)) {
167 qCDebug(BLUEZQT) <<
"Cannot register object" << agent->
objectPath().
path();
170 return new PendingCall(d->m_bluezAgentManager->RegisterAgent(agent->
objectPath(), capability), PendingCall::ReturnVoid,
this);
177 if (!d->m_bluezAgentManager) {
181 DBusConnection::orgBluez().unregisterObject(agent->
objectPath().
path());
183 return new PendingCall(d->m_bluezAgentManager->UnregisterAgent(agent->
objectPath()), PendingCall::ReturnVoid,
this);
190 if (!d->m_bluezAgentManager) {
194 return new PendingCall(d->m_bluezAgentManager->RequestDefaultAgent(agent->
objectPath()), PendingCall::ReturnVoid,
this);
201 if (!d->m_bluezProfileManager) {
205 new ProfileAdaptor(profile,
this);
207 if (!DBusConnection::orgBluez().registerObject(profile->
objectPath().
path(), profile)) {
208 qCDebug(BLUEZQT) <<
"Cannot register object" << profile->
objectPath().
path();
211 return new PendingCall(d->m_bluezProfileManager->RegisterProfile(profile->
objectPath(), profile->uuid(), profile->d->options),
212 PendingCall::ReturnVoid,
220 if (!d->m_bluezProfileManager) {
224 DBusConnection::orgBluez().unregisterObject(profile->
objectPath().
path());
226 return new PendingCall(d->m_bluezProfileManager->UnregisterProfile(profile->
objectPath()), PendingCall::ReturnVoid,
this);
229Rfkill *Manager::rfkill()
const
236#include "moc_manager.cpp"
virtual QDBusObjectPath objectPath() const =0
D-Bus object path of the agent.
PendingCall * unregisterProfile(Profile *profile)
Unregisters profile.
bool isBluetoothOperational() const
Returns whether Bluetooth is operational.
DevicePtr deviceForAddress(const QString &address) const
Returns a device for specified address.
static PendingCall * startService()
Attempts to start org.bluez service by D-Bus activation.
DevicePtr deviceForUbi(const QString &ubi) const
Returns a device for specified UBI.
bool isOperational() const
Returns whether the manager is operational.
PendingCall * unregisterAgent(Agent *agent)
Unregisters agent.
bool isInitialized() const
Returns whether the manager is initialized.
Manager(QObject *parent=nullptr)
Creates a new Manager object.
PendingCall * registerAgent(Agent *agent)
Registers agent.
PendingCall * requestDefaultAgent(Agent *agent)
Requests default agent.
AdapterPtr adapterForUbi(const QString &ubi) const
Returns an adapter for specified UBI.
AdapterPtr adapterForAddress(const QString &address) const
Returns an adapter for specified address.
void setBluetoothBlocked(bool blocked)
Sets a Bluetooth blocked state.
PendingCall * registerProfile(Profile *profile)
Registers profile.
bool isBluetoothBlocked() const
Returns whether Bluetooth is blocked.
~Manager() override
Destroys a Manager object.
InitManagerJob * init()
Creates a new init job.
@ InternalError
Indicates an internal error.
virtual QDBusObjectPath objectPath() const =0
D-Bus object path of the profile.
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
QString path() const const