signon  8.58
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 QVariantMap &inData,
00074                  const QString &mechanism);
00075     bool processUi(const QVariantMap &inData);
00076     bool processRefresh(const QVariantMap &inData);
00077     void cancel();
00078     void stop();
00079 
00080 Q_SIGNALS:
00081     void processResultReply(const QVariantMap &data);
00082     void processStore(const QVariantMap &data);
00083     void processUiRequest(const QVariantMap &data);
00084     void processRefreshRequest(const QVariantMap &data);
00085     void processError(int error,
00086                       const QString &message);
00087     void stateChanged(int state,
00088                       const QString &message);
00089 
00090 private:
00091     QString queryType();
00092     QStringList queryMechanisms();
00093 
00094     bool waitForStarted(int timeout);
00095     bool waitForFinished(int timeout);
00096 
00097     bool readOnReady(QByteArray &buffer, int timeout);
00098 
00099     void handlePluginResponse(const quint32 resultOperation,
00100                               const QVariantMap &sessionDataMap = QVariantMap());
00101 
00102     bool isResultOperationCodeValid(const int opCode) const;
00103 
00104 private Q_SLOTS:
00105     void onReadStandardOutput();
00106     void onReadStandardError();
00107     void onExit(int exitCode, QProcess::ExitStatus exitStatus);
00108     void onError(QProcess::ProcessError err);
00109     void sessionDataReceived(const QVariantMap &map);
00110     void blobIOError();
00111 
00112 private:
00113     PluginProxy(QString type, QObject *parent = NULL);
00114 
00115     bool m_isProcessing;
00116     bool m_isResultObtained;
00117     QString m_type;
00118     QStringList m_mechanisms;
00119     int m_uiPolicy;
00120     int m_currentResultOperation;
00121 
00122     PluginProcess *m_process;
00123     SignOn::BlobIOHandler *m_blobIOHandler;
00124 };
00125 
00126 } //namespace SignonDaemonNS
00127 
00128 #endif /* PLUGINPROXY_H */