File indexing completed on 2024-05-05 03:52:32

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