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