1/*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014-2015 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#ifndef BLUEZQT_OBEXMANAGER_H
10#define BLUEZQT_OBEXMANAGER_H
11
12#include <QObject>
13
14#include "bluezqt_export.h"
15#include "types.h"
16
17#include <memory>
18
19class QDBusObjectPath;
20
21namespace BluezQt
22{
23class ObexAgent;
24class PendingCall;
25class InitObexManagerJob;
26
27/**
28 * @class BluezQt::ObexManager obexmanager.h <BluezQt/ObexManager>
29 *
30 * OBEX manager.
31 *
32 * The entry point to communicate with session BlueZ obex daemon.
33 *
34 * You must call init() before other functions can be used.
35 *
36 * @note If manager is not operational, all methods that returns a PendingCall
37 * will fail with PendingCall::InternalError.
38 */
39class BLUEZQT_EXPORT ObexManager : public QObject
40{
41 Q_OBJECT
42
43 Q_PROPERTY(bool initialized READ isInitialized)
44 Q_PROPERTY(bool operational READ isOperational NOTIFY operationalChanged)
45 Q_PROPERTY(QList<ObexSessionPtr> sessions READ sessions)
46
47public:
48 /**
49 * Creates a new ObexManager object.
50 *
51 * @param parent
52 */
53 explicit ObexManager(QObject *parent = nullptr);
54
55 /**
56 * Destroys an ObexManager object.
57 */
58 ~ObexManager() override;
59
60 /**
61 * Creates a new init job.
62 *
63 * @return init manager job
64 */
65 InitObexManagerJob *init();
66
67 /**
68 * Returns whether the manager is initialized.
69 *
70 * @return true if manager is initialized
71 */
72 bool isInitialized() const;
73
74 /**
75 * Returns whether the manager is operational.
76 *
77 * The manager is operational when initialization was successful
78 * and BlueZ session daemon is running.
79 *
80 * @return true if manager is operational
81 */
82 bool isOperational() const;
83
84 /**
85 * Returns a list of all sessions.
86 *
87 * @return list of sessions
88 */
89 QList<ObexSessionPtr> sessions() const;
90
91 /**
92 * Returns a session for specified path.
93 *
94 * The @p path does not need to be equal to ObexSession path, startsWith
95 * test is performed in the search. That means you can use this method
96 * to get ObexSession from path returned by createSession().
97 *
98 * @param path path of session
99 * @return null if there is no session with specified path
100 */
101 ObexSessionPtr sessionForPath(const QDBusObjectPath &path) const;
102
103 /**
104 * Attempts to start org.bluez.obex service by D-Bus activation.
105 *
106 * Possible return values are 1 if the service was started,
107 * 2 if the service is already running or error if the service
108 * could not be started.
109 *
110 * @return quint32 pending call
111 */
112 static PendingCall *startService();
113
114public Q_SLOTS:
115 /**
116 * Registers agent.
117 *
118 * This agent will be used to authorize an incoming object push requests.
119 *
120 * Possible errors: PendingCall::AlreadyExists
121 *
122 * @param agent agent to be registered
123 * @return void pending call
124 */
125 PendingCall *registerAgent(ObexAgent *agent);
126
127 /**
128 * Unregisters agent.
129 *
130 * Possible errors: PendingCall::DoesNotExist
131 *
132 * @param agent agent to be unregistered
133 * @return void pending call
134 */
135 PendingCall *unregisterAgent(ObexAgent *agent);
136
137 /**
138 * Creates a new OBEX session.
139 *
140 * The @p args parameter is a dictionary to hold optional or
141 * type-specific parameters.
142 *
143 * Typical parameters:
144 * <ul>
145 * <li>QString target - type of session to be created</li>
146 * <li>QString source - device address to be used</li>
147 * </ul>
148 *
149 * Supported targets:
150 * <ul>
151 * <li>ftp - ObexFileTransfer</li>
152 * <li>map</li>
153 * <li>opp - ObexObjectPush</li>
154 * <li>pbap</li>
155 * <li>sync</li>
156 * </ul>
157 *
158 * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed
159 *
160 * @param destination address of target device
161 * @param args session parameters
162 * @return QDBusObjectPath pending call
163 */
164 PendingCall *createSession(const QString &destination, const QVariantMap &args);
165
166 /**
167 * Removes an existing OBEX session.
168 *
169 * Possible errors: PendingCall::InvalidArguments, PendingCall::NotAuthorized
170 *
171 * @param session session to be removed
172 * @return void pending call
173 */
174 PendingCall *removeSession(const QDBusObjectPath &session);
175
176Q_SIGNALS:
177 /**
178 * Indicates that operational state have changed.
179 */
180 void operationalChanged(bool operational);
181
182 /**
183 * Indicates that the session was added.
184 */
185 void sessionAdded(ObexSessionPtr session);
186
187 /**
188 * Indicates that the session was removed.
189 */
190 void sessionRemoved(ObexSessionPtr session);
191
192private:
193 std::unique_ptr<class ObexManagerPrivate> const d;
194
195 friend class ObexManagerPrivate;
196 friend class InitObexManagerJobPrivate;
197};
198
199} // namespace BluezQt
200
201#endif // BLUEZQT_OBEXMANAGER_H
202

source code of bluez-qt/src/obexmanager.h