authpluginif.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  * Copyright (C) 2012-2016 Canonical Ltd.
00006  *
00007  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00028 #ifndef AUTHPLUGINIF_H
00029 #define AUTHPLUGINIF_H
00030 
00031 #include <QtCore/qobject.h>
00032 #include <QtCore/qpointer.h>
00033 #include <QtCore/qplugin.h>
00034 
00035 #include <QVariantMap>
00036 #include <SignOn/sessiondata.h>
00037 #include <SignOn/uisessiondata.h>
00038 #include <SignOn/signonerror.h>
00039 
00040 QT_BEGIN_NAMESPACE
00041 class QString;
00042 class QStringList;
00043 class QByteArray;
00044 class QVariant;
00045 QT_END_NAMESPACE
00046 
00050 enum AuthPluginState {
00051     PLUGIN_STATE_NONE = 0,             
00052     PLUGIN_STATE_RESOLVING,          
00053     PLUGIN_STATE_CONNECTING,      
00054     PLUGIN_STATE_SENDING,             
00055     PLUGIN_STATE_WAITING,            
00056     PLUGIN_STATE_PENDING,             
00057     PLUGIN_STATE_REFRESHING,       
00058     PLUGIN_STATE_CANCELING,         
00059     PLUGIN_STATE_HOLDING,            
00060     PLUGIN_STATE_DONE                    
00061 };
00062 
00067 #define SIGNON_PLUGIN_INSTANCE(pluginclass) \
00068         { \
00069             static AuthPluginInterface *_instance = 0; \
00070             if (!_instance)      \
00071                 _instance = static_cast<AuthPluginInterface *>(new pluginclass()); \
00072             return _instance; \
00073         }
00074 
00075 #define SIGNON_DECL_AUTH_PLUGIN(pluginclass) \
00076         Q_EXTERN_C AuthPluginInterface *auth_plugin_instance() \
00077         SIGNON_PLUGIN_INSTANCE(pluginclass)
00078 
00083 class AuthPluginInterface : public QObject
00084 {
00085     Q_OBJECT
00086 
00087 public:
00088     AuthPluginInterface(QObject *parent = 0) : QObject(parent)
00089         { qRegisterMetaType<SignOn::Error>("SignOn::Error"); }
00090 
00094     virtual ~AuthPluginInterface() {}
00095 
00101     virtual QString type() const = 0;
00102 
00108     virtual QStringList mechanisms() const = 0;
00109 
00116     virtual void cancel() {}
00117 
00124     virtual void abort() {}
00125 
00139     virtual void process(const SignOn::SessionData &inData,
00140                          const QString &mechanism = QString()) = 0;
00141 
00142 Q_SIGNALS:
00149     void result(const SignOn::SessionData &data);
00150 
00161     void store(const SignOn::SessionData &data);
00162 
00170     void error(const SignOn::Error &err);
00171 
00184     void userActionRequired(const SignOn::UiSessionData &data);
00185 
00193     void refreshed(const SignOn::UiSessionData &data);
00194 
00202     void statusChanged(const AuthPluginState state,
00203                        const QString &message = QString());
00204 
00205 public Q_SLOTS:
00216     virtual void userActionFinished(const SignOn::UiSessionData &data) {
00217         Q_UNUSED(data);
00218     }
00219 
00232     virtual void refresh(const SignOn::UiSessionData &data) {
00233         emit refreshed(data);
00234     }
00235 
00236 };
00237 
00238 QT_BEGIN_NAMESPACE
00239  Q_DECLARE_INTERFACE(AuthPluginInterface,
00240                      "com.nokia.SingleSignOn.PluginInterface/1.3")
00241 QT_END_NAMESPACE
00242 #endif // AUTHPLUGINIF_H