signon  8.40
pluginproxy.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00022 
00023 #ifndef PLUGINPROXY_H
00024 #define PLUGINPROXY_H
00025 
00026 #include <QDBusConnection>
00027 #include <QDBusMessage>
00028 #include <QtCore>
00029 
00030 namespace SignOn {
00031     class BlobIOHandler;
00032     class EncryptedDevice;
00033 };
00034 
00035 namespace SignonDaemonNS {
00036 
00042 class PluginProcess: public QProcess
00043 {
00044     Q_OBJECT
00045     friend class PluginProxy;
00046 
00047     PluginProcess(QObject* parent = NULL);
00048     ~PluginProcess();
00049 };
00050 
00056 class PluginProxy: public QObject
00057 {
00058     Q_OBJECT
00059 
00060     friend class SignonIdentity;
00061     friend class TestAuthSession;
00062 
00063 public:
00064     static PluginProxy *createNewPluginProxy(const QString &type);
00065     virtual ~PluginProxy();
00066 
00067     bool restartIfRequired();
00068     bool isProcessing();
00069 
00070 public Q_SLOTS:
00071     QString type() const { return m_type; }
00072     QStringList mechanisms() const { return m_mechanisms; }
00073     bool process(const QString &cancelKey,
00074                  const QVariantMap &inData,
00075                  const QString &mechanism);
00076     bool processUi(const QString &cancelKey, const QVariantMap &inData);
00077     bool processRefresh(const QString &cancelKey, const QVariantMap &inData);
00078     void cancel();
00079     void stop();
00080 
00081 Q_SIGNALS:
00082     void processResultReply(const QString &cancelKey, const QVariantMap &data);
00083     void processStore(const QString &cancelKey, const QVariantMap &data);
00084     void processUiRequest(const QString &cancelKey, const QVariantMap &data);
00085     void processRefreshRequest(const QString &cancelKey,
00086                                const QVariantMap &data);
00087     void processError(const QString &cancelKey,
00088                       int error,
00089                       const QString &message);
00090     void stateChanged(const QString &cancelKey,
00091                       int state,
00092                       const QString &message);
00093 
00094 private:
00095     QString queryType();
00096     QStringList queryMechanisms();
00097 
00098     bool waitForStarted(int timeout);
00099     bool waitForFinished(int timeout);
00100 
00101     bool readOnReady(QByteArray &buffer, int timeout);
00102 
00103     void handlePluginResponse(const quint32 resultOperation,
00104                               const QVariantMap &sessionDataMap = QVariantMap());
00105 
00106     bool isResultOperationCodeValid(const int opCode) const;
00107 
00108 private Q_SLOTS:
00109     void onReadStandardOutput();
00110     void onReadStandardError();
00111     void onExit(int exitCode, QProcess::ExitStatus exitStatus);
00112     void onError(QProcess::ProcessError err);
00113     void sessionDataReceived(const QVariantMap &map);
00114     void blobIOError();
00115 
00116 private:
00117     PluginProxy(QString type, QObject *parent = NULL);
00118 
00119     bool m_isProcessing;
00120     bool m_isResultObtained;
00121     QString m_type;
00122     QString m_cancelKey;
00123     QStringList m_mechanisms;
00124     int m_uiPolicy;
00125     int m_currentResultOperation;
00126 
00127     PluginProcess *m_process;
00128     SignOn::BlobIOHandler *m_blobIOHandler;
00129 };
00130 
00131 } //namespace SignonDaemonNS
00132 
00133 #endif /* PLUGINPROXY_H */