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