BluezQt

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

KDE's Doxygen guidelines are available online.