signon  8.42
pluginproxy.h
Go to the documentation of this file.
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 
23 #ifndef PLUGINPROXY_H
24 #define PLUGINPROXY_H
25 
26 #include <QDBusConnection>
27 #include <QDBusMessage>
28 #include <QtCore>
29 
30 namespace SignOn {
31  class BlobIOHandler;
32  class EncryptedDevice;
33 };
34 
35 namespace SignonDaemonNS {
36 
42 class PluginProcess: public QProcess
43 {
44  Q_OBJECT
45  friend class PluginProxy;
46 
47  PluginProcess(QObject* parent = NULL);
48  ~PluginProcess();
49 };
50 
56 class PluginProxy: public QObject
57 {
58  Q_OBJECT
59 
60  friend class SignonIdentity;
61  friend class TestAuthSession;
62 
63 public:
64  static PluginProxy *createNewPluginProxy(const QString &type);
65  virtual ~PluginProxy();
66 
67  bool restartIfRequired();
68  bool isProcessing();
69 
70 public Q_SLOTS:
71  QString type() const { return m_type; }
72  QStringList mechanisms() const { return m_mechanisms; }
73  bool process(const QString &cancelKey,
74  const QVariantMap &inData,
75  const QString &mechanism);
76  bool processUi(const QString &cancelKey, const QVariantMap &inData);
77  bool processRefresh(const QString &cancelKey, const QVariantMap &inData);
78  void cancel();
79  void stop();
80 
81 Q_SIGNALS:
82  void processResultReply(const QString &cancelKey, const QVariantMap &data);
83  void processStore(const QString &cancelKey, const QVariantMap &data);
84  void processUiRequest(const QString &cancelKey, const QVariantMap &data);
85  void processRefreshRequest(const QString &cancelKey,
86  const QVariantMap &data);
87  void processError(const QString &cancelKey,
88  int error,
89  const QString &message);
90  void stateChanged(const QString &cancelKey,
91  int state,
92  const QString &message);
93 
94 private:
95  QString queryType();
96  QStringList queryMechanisms();
97 
98  bool waitForStarted(int timeout);
99  bool waitForFinished(int timeout);
100 
101  bool readOnReady(QByteArray &buffer, int timeout);
102 
103  void handlePluginResponse(const quint32 resultOperation,
104  const QVariantMap &sessionDataMap = QVariantMap());
105 
106  bool isResultOperationCodeValid(const int opCode) const;
107 
108 private Q_SLOTS:
109  void onReadStandardOutput();
110  void onReadStandardError();
111  void onExit(int exitCode, QProcess::ExitStatus exitStatus);
112  void onError(QProcess::ProcessError err);
113  void sessionDataReceived(const QVariantMap &map);
114  void blobIOError();
115 
116 private:
117  PluginProxy(QString type, QObject *parent = NULL);
118 
119  bool m_isProcessing;
120  bool m_isResultObtained;
121  QString m_type;
122  QString m_cancelKey;
123  QStringList m_mechanisms;
124  int m_uiPolicy;
125  int m_currentResultOperation;
126 
127  PluginProcess *m_process;
128  SignOn::BlobIOHandler *m_blobIOHandler;
129 };
130 
131 } //namespace SignonDaemonNS
132 
133 #endif /* PLUGINPROXY_H */