File indexing completed on 2024-04-21 04:42:44

0001 /*
0002     SPDX-FileCopyrightText: 2012 Frederik Gladhorn <gladhorn@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef DBUSCONNECTION_H
0008 #define DBUSCONNECTION_H
0009 
0010 #include <QObject>
0011 #include <QDBusConnection>
0012 #include <QDBusPendingCallWatcher>
0013 
0014 namespace QAccessibleClient {
0015 
0016 
0017 /**
0018     Connection to the a11y dbus bus.
0019     \internal
0020  */
0021 class DBusConnection : public QObject
0022 {
0023     Q_OBJECT
0024 public:
0025     /**
0026         \brief Constructor.
0027 
0028         When called, means the instance is created, we try instantly
0029         to fetch the \a connection . When done the \a connectionFetched
0030         will be emitted. If \a connection is called before it will
0031         block till the connection was fetched and is ready for use.
0032      */
0033     DBusConnection();
0034 
0035     /**
0036         \brief Returns true if the \a connection is not ready yet.
0037 
0038         The initial fetch of the comnnection happens over dbus and
0039         as such can block for a longer time means may need longer.
0040         To make it possible that users of this class do not block
0041         while that happens it is possible to use this method to
0042         determinate if fetching the connection is currently work
0043         in progress and if so connect with the \a connectionFetched
0044         signal to be called back when the connection is ready.
0045      */
0046     bool isFetchingConnection() const;
0047 
0048     /**
0049         \brief Returns the accessibility dbus connection.
0050 
0051         This may either be the session bus or a referenced
0052         accessibility bus. If the connection was not fetched
0053         yet, means \a isFetchingConnection returns true, then
0054         calling this method will block till the connection was
0055         fetched.
0056      */
0057     QDBusConnection connection() const;
0058 
0059     enum Status {
0060         Disconnected,
0061         ConnectionError,
0062         Connected
0063     };
0064 
0065     /**
0066         \brief Returns the state the connection is in.
0067 
0068         If Disconnected then we got not asked to connect yet or
0069         connection is in progress but not finished yet (see
0070         signal \a connectionFetched which will be emitted if the
0071         connection is not Disconnected any longer.
0072         If connection failed then the state is set to ConnectionError
0073         otherwise, in the case everything went fine and we are
0074         proper connected with tthe atspi daemon now Connected
0075         is returned.
0076      */
0077     Status status() const;
0078 
0079 Q_SIGNALS:
0080 
0081     /**
0082         \brief Emitted when the \a connection was fetched.
0083 
0084         This will happen exactly one time during the lifetime
0085         of a DBusConnection instance at the very beginning when
0086         the instance is created.
0087      */
0088     void connectionFetched();
0089 
0090 private Q_SLOTS:
0091     void initFinished();
0092 
0093 private:
0094     void init();
0095 
0096     QDBusConnection m_connection;
0097     mutable Status m_status = Disconnected;
0098     QDBusPendingCallWatcher *m_initWatcher = nullptr;
0099 };
0100 }
0101 
0102 #endif // DBUSCONNECTION_H