[Telepathy-commits] [telepathy-qt4/master] DBusProxy: rethink API to not use QDBusAbstractInterface, and add stub StatefulDBusProxy, StatelessDBusProxy subclasses
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue Dec 2 09:02:15 PST 2008
---
TelepathyQt4/cli-channel.cpp | 6 +-
TelepathyQt4/cli-channel.h | 2 +-
TelepathyQt4/cli-dbus-proxy.cpp | 43 +++++++++----
TelepathyQt4/cli-dbus-proxy.h | 127 ++++++++++++++++++++++++++++++++++----
4 files changed, 148 insertions(+), 30 deletions(-)
diff --git a/TelepathyQt4/cli-channel.cpp b/TelepathyQt4/cli-channel.cpp
index 372c1ad..7869315 100644
--- a/TelepathyQt4/cli-channel.cpp
+++ b/TelepathyQt4/cli-channel.cpp
@@ -401,10 +401,12 @@ struct Channel::Private
Channel::Channel(Connection* connection,
const QString& objectPath,
QObject* parent)
- : DBusProxy(connection, parent),
+ : StatefulDBusProxy(connection->connection(), connection->service(),
+ objectPath, parent),
mPriv(new Private(*this, connection))
{
- mPriv->baseInterface = new ChannelInterface(connection->service(), objectPath, this);
+ mPriv->baseInterface = new ChannelInterface(this->dbusConnection(),
+ this->busName(), this->objectPath(), this);
// Introspection continued here so mPriv will be initialized (unlike if we
// continued it from the Private constructor)
diff --git a/TelepathyQt4/cli-channel.h b/TelepathyQt4/cli-channel.h
index 46603a8..7bcb4b9 100644
--- a/TelepathyQt4/cli-channel.h
+++ b/TelepathyQt4/cli-channel.h
@@ -93,7 +93,7 @@ namespace Client
* signaled by Connection::readinessChanged) or is deleted, the Channel object
* will transition to ReadinessDead too.
*/
-class Channel : public DBusProxy, private OptionalInterfaceFactory
+class Channel : public StatefulDBusProxy, private OptionalInterfaceFactory
{
Q_OBJECT
Q_ENUMS(Readiness)
diff --git a/TelepathyQt4/cli-dbus-proxy.cpp b/TelepathyQt4/cli-dbus-proxy.cpp
index b2ade1f..9a4d654 100644
--- a/TelepathyQt4/cli-dbus-proxy.cpp
+++ b/TelepathyQt4/cli-dbus-proxy.cpp
@@ -33,21 +33,26 @@ struct DBusProxy::Private
// Public object
DBusProxy& parent;
- QDBusAbstractInterface* baseInterface;
+ QDBusConnection dbusConnection;
+ QString busName;
+ QString objectPath;
- Private(QDBusAbstractInterface* interface, DBusProxy& p)
- : parent(p),
- baseInterface(interface)
+ Private(const QDBusConnection& dbusConnection, const QString& busName,
+ const QString& objectPath, DBusProxy& p)
+ : parent(p),
+ dbusConnection(dbusConnection),
+ busName(busName),
+ objectPath(objectPath)
{
debug() << "Creating new DBusProxy";
}
};
-DBusProxy::DBusProxy(QDBusAbstractInterface* baseInterface, QObject* parent)
+DBusProxy::DBusProxy(const QDBusConnection& dbusConnection,
+ const QString& busName, const QString& path, QObject* parent)
: QObject(parent),
- mPriv(new Private(baseInterface, *this))
+ mPriv(new Private(dbusConnection, busName, path, *this))
{
-
}
DBusProxy::~DBusProxy()
@@ -55,19 +60,31 @@ DBusProxy::~DBusProxy()
delete mPriv;
}
-QDBusConnection DBusProxy::connection() const
+QDBusConnection DBusProxy::dbusConnection() const
+{
+ return mPriv->dbusConnection;
+}
+
+QString DBusProxy::objectPath() const
+{
+ return mPriv->objectPath;
+}
+
+QString DBusProxy::busName() const
{
- return mPriv->baseInterface->connection();
+ return mPriv->busName;
}
-QString DBusProxy::path() const
+StatelessDBusProxy::StatelessDBusProxy(const QDBusConnection& dbusConnection,
+ const QString& busName, const QString& objectPath, QObject* parent)
+ : DBusProxy(dbusConnection, busName, objectPath, parent)
{
- return mPriv->baseInterface->path();
}
-QString DBusProxy::service() const
+StatefulDBusProxy::StatefulDBusProxy(const QDBusConnection& dbusConnection,
+ const QString& busName, const QString& objectPath, QObject* parent)
+ : DBusProxy(dbusConnection, busName, objectPath, parent)
{
- return mPriv->baseInterface->service();
}
}
diff --git a/TelepathyQt4/cli-dbus-proxy.h b/TelepathyQt4/cli-dbus-proxy.h
index 2b2243f..79e4097 100644
--- a/TelepathyQt4/cli-dbus-proxy.h
+++ b/TelepathyQt4/cli-dbus-proxy.h
@@ -37,8 +37,10 @@ namespace Client
* \ingroup FIXME: what group is it in?
* \headerfile TelepathyQt4/cli-dbus-proxy.h <TelepathyQt4/Client/DBusProxy>
*
- * Base class which all TelepathyQt4 client convenience classes that wrap
- * Telepathy interfaces inherit from in order to provide basic DBus interface
+ * Base class representing a remote object available over D-Bus.
+ *
+ * All TelepathyQt4 client convenience classes that wrap Telepathy interfaces
+ * inherit from this class in order to provide basic D-Bus interface
* information.
*
*/
@@ -50,33 +52,131 @@ public:
/**
* Constructor
*/
- DBusProxy(QDBusAbstractInterface* baseInterface, QObject* parent = 0);
+ DBusProxy(const QDBusConnection& dbusConnection, const QString& busName,
+ const QString& objectPath, QObject* parent = 0);
/**
* Destructor
*/
- ~DBusProxy();
+ virtual ~DBusProxy();
+
+ /**
+ * Returns the D-Bus connection through which the remote object is
+ * accessed.
+ *
+ * \return The connection the object is associated with.
+ */
+ QDBusConnection dbusConnection() const;
+
+ /**
+ * Returns the D-Bus bus name (either a unique name or a well-known
+ * name) of the service that provides the remote object.
+ *
+ * \return The service name the object is associated with.
+ */
+ QString busName() const;
/**
- * Returns the DBus connection the base interface is associated with.
+ * Returns the D-Bus object path of the remote object within the service.
*
- * \return The connection the interface is associated with.
+ * \return The object path the object is associated with.
*/
- QDBusConnection connection() const;
+ QString objectPath() const;
/**
- * Returns the DBus object path the base interface is associated with.
+ * If this object is usable (has not emitted #invalidated()), returns
+ * <code>true</code>. Otherwise returns <code>false</code>.
*
- * \return The object path the interface is associated with.
+ * \return <code>true</code> if this object is still fully usable
*/
- QString path() const;
+ bool isValid() const;
/**
- * Returns the DBus service name the base interface is associated with.
+ * If this object is no longer usable (has emitted #invalidated()),
+ * returns the error name indicating the reason it became invalid in a
+ * machine-readable way. Otherwise, returns a null QString.
*
- * \return The service name the interface is associated with.
+ * \return A D-Bus error name, or QString() if this object is still valid
*/
- QString service() const;
+ QString invalidationReason() const;
+
+ /**
+ * If this object is no longer usable (has emitted #invalidated()),
+ * returns a debugging message indicating the reason it became invalid.
+ * Otherwise, returns a null QString.
+ *
+ * \return A debugging message, or QString() if this object is still valid
+ */
+ QString invalidationMessage() const;
+
+Q_SIGNALS:
+ /**
+ * Emitted when this object is no longer usable.
+ *
+ * After this signal is emitted, any D-Bus method calls on the object
+ * will fail, but it may be possible to retrieve information that has
+ * already been retrieved and cached.
+ *
+ * \param proxy This proxy
+ * \param errorName A D-Bus error name (a string in a subset
+ * of ASCII, prefixed with a reversed domain name)
+ * \param errorMessage A debugging message associated with the error
+ */
+ void invalidated(DBusProxy* proxy, QString errorName,
+ QString errorMessage);
+
+private:
+ struct Private;
+ friend struct Private;
+ Private *mPriv;
+};
+
+/**
+ * \class StatelessDBusProxy
+ * \ingroup FIXME: what group is it in?
+ * \headerfile TelepathyQt4/cli-dbus-proxy.h <TelepathyQt4/Client/DBusProxy>
+ *
+ * Base class representing a remote object whose API is basically stateless.
+ * These objects can remain valid even if the service providing them exits
+ * and is restarted.
+ *
+ * Examples in Telepathy include the AccountManager, Account and
+ * ConnectionManager.
+ */
+class StatelessDBusProxy : public DBusProxy
+{
+ Q_OBJECT
+
+public:
+ StatelessDBusProxy(const QDBusConnection& dbusConnection,
+ const QString& busName, const QString& objectPath,
+ QObject* parent = 0);
+
+private:
+ struct Private;
+ friend struct Private;
+ Private *mPriv;
+};
+
+/**
+ * \class StatefulDBusProxy
+ * \ingroup FIXME: what group is it in?
+ * \headerfile TelepathyQt4/cli-dbus-proxy.h <TelepathyQt4/Client/DBusProxy>
+ *
+ * Base class representing a remote object whose API is stateful. These
+ * objects do not remain useful if the service providing them exits or
+ * crashes, so they emit #invalidated() if this happens.
+ *
+ * Examples in Telepathy include the Connection and Channel.
+ */
+class StatefulDBusProxy : public DBusProxy
+{
+ Q_OBJECT
+
+public:
+ StatefulDBusProxy(const QDBusConnection& dbusConnection,
+ const QString& busName, const QString& objectPath,
+ QObject* parent = 0);
private:
struct Private;
@@ -88,4 +188,3 @@ private:
}
#endif
-
--
1.5.6.5
More information about the Telepathy-commits
mailing list