00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SIGNON_ASYNC_DBUS_PROXY_H
00026 #define SIGNON_ASYNC_DBUS_PROXY_H
00027
00028 #include <QDBusError>
00029 #include <QObject>
00030 #include <QQueue>
00031 #include <QVariant>
00032
00033 class QDBusAbstractInterface;
00034 class QDBusConnection;
00035 class QDBusObjectPath;
00036 class QDBusPendingCallWatcher;
00037
00038
00039
00040
00041 namespace SignOn {
00042
00043 class AsyncDBusProxy;
00044 class Connection;
00045 class DBusInterface;
00046
00047 class PendingCall: public QObject
00048 {
00049 Q_OBJECT
00050
00051 public:
00052 ~PendingCall();
00053
00054 bool cancel();
00055
00056 Q_SIGNALS:
00057 void finished(QDBusPendingCallWatcher *watcher);
00058 void success(QDBusPendingCallWatcher *watcher);
00059 void error(const QDBusError &error);
00060 void requeueRequested();
00061
00062 private Q_SLOTS:
00063 void onFinished(QDBusPendingCallWatcher *watcher);
00064 void onInterfaceDestroyed();
00065 void fail(const QDBusError &error);
00066
00067 private:
00068 friend class AsyncDBusProxy;
00069 PendingCall(const QString &method,
00070 const QList<QVariant> &args,
00071 QObject *parent = 0);
00072 void doCall(QDBusAbstractInterface *interface);
00073
00074 private:
00075 QString m_method;
00076 QList<QVariant> m_args;
00077 QDBusPendingCallWatcher *m_watcher;
00078 bool m_interfaceWasDestroyed;
00079 };
00080
00081 class AsyncDBusProxy: public QObject
00082 {
00083 Q_OBJECT
00084
00085 public:
00086 AsyncDBusProxy(const QString &service,
00087 const char *interface,
00088 QObject *clientObject);
00089 ~AsyncDBusProxy();
00090
00091 void setObjectPath(const QDBusObjectPath &objectPath);
00092 void setError(const QDBusError &error);
00093
00094 PendingCall *queueCall(const QString &method,
00095 const QList<QVariant> &args,
00096 const char *replySlot = 0,
00097 const char *errorSlot = 0);
00098 PendingCall *queueCall(const QString &method,
00099 const QList<QVariant> &args,
00100 QObject *receiver,
00101 const char *replySlot,
00102 const char *errorSlot);
00103 bool connect(const char *name, QObject *receiver, const char *slot);
00104
00105 public Q_SLOTS:
00106 void setConnection(const QDBusConnection &connection);
00107 void setDisconnected();
00108
00109 Q_SIGNALS:
00110 void connectionNeeded();
00111 void objectPathNeeded();
00112
00113 private:
00114 enum Status {
00115 Incomplete,
00116 Ready,
00117 Invalid
00118 };
00119 void setStatus(Status status);
00120 void update();
00121 void enqueue(PendingCall *call);
00122
00123 private Q_SLOTS:
00124 void onCallFinished(QDBusPendingCallWatcher *watcher);
00125 void onRequeueRequested();
00126
00127 private:
00128 QString m_serviceName;
00129 const char *m_interfaceName;
00130 QString m_path;
00131 QDBusConnection *m_connection;
00132 QObject *m_clientObject;
00133 QQueue<PendingCall *> m_operationsQueue;
00134 QQueue<Connection *> m_connectionsQueue;
00135 DBusInterface *m_interface;
00136 Status m_status;
00137 QDBusError m_lastError;
00138 };
00139
00140 class SignondAsyncDBusProxy: public AsyncDBusProxy
00141 {
00142 Q_OBJECT
00143 public:
00144 SignondAsyncDBusProxy(const char *interface,
00145 QObject *clientObject);
00146 ~SignondAsyncDBusProxy();
00147
00148 private:
00149 void setupConnection();
00150 };
00151
00152 }
00153
00154
00155
00156
00157
00158 #endif // SIGNON_ASYNC_DBUS_PROXY_H