File indexing completed on 2024-04-28 15:17:55

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #ifndef BLUEZQT_OBEXMANAGER_H
0010 #define BLUEZQT_OBEXMANAGER_H
0011 
0012 #include <QObject>
0013 
0014 #include "bluezqt_export.h"
0015 #include "obexsession.h"
0016 
0017 class QDBusObjectPath;
0018 
0019 namespace BluezQt
0020 {
0021 class ObexAgent;
0022 class PendingCall;
0023 class InitObexManagerJob;
0024 
0025 /**
0026  * @class BluezQt::ObexManager obexmanager.h <BluezQt/ObexManager>
0027  *
0028  * OBEX manager.
0029  *
0030  * The entry point to communicate with session BlueZ obex daemon.
0031  *
0032  * You must call init() before other functions can be used.
0033  *
0034  * @note If manager is not operational, all methods that returns a PendingCall
0035  *       will fail with PendingCall::InternalError.
0036  */
0037 class BLUEZQT_EXPORT ObexManager : public QObject
0038 {
0039     Q_OBJECT
0040 
0041     Q_PROPERTY(bool initialized READ isInitialized)
0042     Q_PROPERTY(bool operational READ isOperational NOTIFY operationalChanged)
0043     Q_PROPERTY(QList<ObexSessionPtr> sessions READ sessions)
0044 
0045 public:
0046     /**
0047      * Creates a new ObexManager object.
0048      *
0049      * @param parent
0050      */
0051     explicit ObexManager(QObject *parent = nullptr);
0052 
0053     /**
0054      * Destroys an ObexManager object.
0055      */
0056     ~ObexManager() override;
0057 
0058     /**
0059      * Creates a new init job.
0060      *
0061      * @return init manager job
0062      */
0063     InitObexManagerJob *init();
0064 
0065     /**
0066      * Returns whether the manager is initialized.
0067      *
0068      * @return true if manager is initialized
0069      */
0070     bool isInitialized() const;
0071 
0072     /**
0073      * Returns whether the manager is operational.
0074      *
0075      * The manager is operational when initialization was successful
0076      * and BlueZ session daemon is running.
0077      *
0078      * @return true if manager is operational
0079      */
0080     bool isOperational() const;
0081 
0082     /**
0083      * Returns a list of all sessions.
0084      *
0085      * @return list of sessions
0086      */
0087     QList<ObexSessionPtr> sessions() const;
0088 
0089     /**
0090      * Returns a session for specified path.
0091      *
0092      * The @p path does not need to be equal to ObexSession path, startsWith
0093      * test is performed in the search. That means you can use this method
0094      * to get ObexSession from path returned by createSession().
0095      *
0096      * @param path path of session
0097      * @return null if there is no session with specified path
0098      */
0099     ObexSessionPtr sessionForPath(const QDBusObjectPath &path) const;
0100 
0101     /**
0102      * Attempts to start org.bluez.obex service by D-Bus activation.
0103      *
0104      * Possible return values are 1 if the service was started,
0105      * 2 if the service is already running or error if the service
0106      * could not be started.
0107      *
0108      * @return quint32 pending call
0109      */
0110     static PendingCall *startService();
0111 
0112 public Q_SLOTS:
0113     /**
0114      * Registers agent.
0115      *
0116      * This agent will be used to authorize an incoming object push requests.
0117      *
0118      * Possible errors: PendingCall::AlreadyExists
0119      *
0120      * @param agent agent to be registered
0121      * @return  void pending call
0122      */
0123     PendingCall *registerAgent(ObexAgent *agent);
0124 
0125     /**
0126      * Unregisters agent.
0127      *
0128      * Possible errors: PendingCall::DoesNotExist
0129      *
0130      * @param agent agent to be unregistered
0131      * @return  void pending call
0132      */
0133     PendingCall *unregisterAgent(ObexAgent *agent);
0134 
0135     /**
0136      * Creates a new OBEX session.
0137      *
0138      * The @p args parameter is a dictionary to hold optional or
0139      * type-specific parameters.
0140      *
0141      * Typical parameters:
0142      * <ul>
0143      *  <li>QString target - type of session to be created</li>
0144      *  <li>QString source - device address to be used</li>
0145      * </ul>
0146      *
0147      * Supported targets:
0148      * <ul>
0149      *   <li>ftp - ObexFileTransfer</li>
0150      *   <li>map</li>
0151      *   <li>opp - ObexObjectPush</li>
0152      *   <li>pbap</li>
0153      *   <li>sync</li>
0154      * </ul>
0155      *
0156      * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed
0157      *
0158      * @param destination address of target device
0159      * @param args session parameters
0160      * @return QDBusObjectPath pending call
0161      */
0162     PendingCall *createSession(const QString &destination, const QVariantMap &args);
0163 
0164     /**
0165      * Removes an existing OBEX session.
0166      *
0167      * Possible errors: PendingCall::InvalidArguments, PendingCall::NotAuthorized
0168      *
0169      * @param session session to be removed
0170      * @return void pending call
0171      */
0172     PendingCall *removeSession(const QDBusObjectPath &session);
0173 
0174 Q_SIGNALS:
0175     /**
0176      * Indicates that operational state have changed.
0177      */
0178     void operationalChanged(bool operational);
0179 
0180     /**
0181      * Indicates that the session was added.
0182      */
0183     void sessionAdded(ObexSessionPtr session);
0184 
0185     /**
0186      * Indicates that the session was removed.
0187      */
0188     void sessionRemoved(ObexSessionPtr session);
0189 
0190 private:
0191     class ObexManagerPrivate *const d;
0192 
0193     friend class ObexManagerPrivate;
0194     friend class InitObexManagerJobPrivate;
0195 };
0196 
0197 } // namespace BluezQt
0198 
0199 #endif // BLUEZQT_OBEXMANAGER_H