BluezQt

obexmanager.cpp
1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "obexmanager.h"
10#include "debug.h"
11#include "initobexmanagerjob.h"
12#include "obexagent.h"
13#include "obexagentadaptor.h"
14#include "obexmanager_p.h"
15#include "obexsession.h"
16#include "pendingcall.h"
17#include "utils.h"
18
19#include <QDBusServiceWatcher>
20
21namespace BluezQt
22{
24 : QObject(parent)
25 , d(new ObexManagerPrivate(this))
26{
27 Instance::setObexManager(this);
28}
29
31
36
38{
39 return d->m_initialized;
40}
41
43{
44 return d->m_initialized && d->m_obexRunning && d->m_loaded;
45}
46
47QList<ObexSessionPtr> ObexManager::sessions() const
48{
49 return d->m_sessions.values();
50}
51
53{
54 for (ObexSessionPtr session : std::as_const(d->m_sessions)) {
55 if (path.path().startsWith(session->objectPath().path())) {
56 return session;
57 }
58 }
59
60 return ObexSessionPtr();
61}
62
64{
65 QDBusMessage msg = QDBusMessage::createMethodCall(Strings::orgFreedesktopDBus(),
66 QStringLiteral("/org/freedesktop/DBus"),
67 Strings::orgFreedesktopDBus(),
68 QStringLiteral("StartServiceByName"));
69 msg << Strings::orgBluezObex();
70 msg << quint32(0);
71
72 return new PendingCall(DBusConnection::orgBluezObex().asyncCall(msg), PendingCall::ReturnUint32);
73}
74
76{
78
79 if (!d->m_obexAgentManager) {
80 return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!"));
81 }
82
83 new ObexAgentAdaptor(agent, this);
84
85 if (!DBusConnection::orgBluezObex().registerObject(agent->objectPath().path(), agent)) {
86 qCDebug(BLUEZQT) << "Cannot register object" << agent->objectPath().path();
87 }
88
89 return new PendingCall(d->m_obexAgentManager->RegisterAgent(agent->objectPath()), PendingCall::ReturnVoid, this);
90}
91
93{
95
96 if (!d->m_obexAgentManager) {
97 return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!"));
98 }
99
100 DBusConnection::orgBluezObex().unregisterObject(agent->objectPath().path());
101
102 return new PendingCall(d->m_obexAgentManager->UnregisterAgent(agent->objectPath()), PendingCall::ReturnVoid, this);
103}
104
105PendingCall *ObexManager::createSession(const QString &destination, const QVariantMap &args)
106{
107 if (!d->m_obexClient) {
108 return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!"));
109 }
110
111 return new PendingCall(d->m_obexClient->CreateSession(destination, args), PendingCall::ReturnObjectPath, this);
112}
113
115{
116 if (!d->m_obexClient) {
117 return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!"));
118 }
119
120 return new PendingCall(d->m_obexClient->RemoveSession(session), PendingCall::ReturnVoid, this);
121}
122
123} // namespace BluezQt
124
125#include "moc_obexmanager.cpp"
Bluetooth OBEX agent.
Definition obexagent.h:37
static PendingCall * startService()
Attempts to start org.bluez.obex service by D-Bus activation.
PendingCall * removeSession(const QDBusObjectPath &session)
Removes an existing OBEX session.
~ObexManager() override
Destroys an ObexManager object.
PendingCall * registerAgent(ObexAgent *agent)
Registers agent.
bool isOperational() const
Returns whether the manager is operational.
ObexSessionPtr sessionForPath(const QDBusObjectPath &path) const
Returns a session for specified path.
ObexManager(QObject *parent=nullptr)
Creates a new ObexManager object.
InitObexManagerJob * init()
Creates a new init job.
PendingCall * unregisterAgent(ObexAgent *agent)
Unregisters agent.
PendingCall * createSession(const QString &destination, const QVariantMap &args)
Creates a new OBEX session.
bool isInitialized() const
Returns whether the manager is initialized.
Pending method call.
Definition pendingcall.h:35
@ InternalError
Indicates an internal error.
Definition pendingcall.h:97
D-Bus request.
Definition request.h:39
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.