authpluginif.h
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  */
00027 #ifndef AUTHPLUGINIF_H
00028 #define AUTHPLUGINIF_H
00029 
00030 #include <QtCore/qobject.h>
00031 #include <QtCore/qpointer.h>
00032 #include <QtCore/qplugin.h>
00033 
00034 #include <QVariantMap>
00035 #include <SignOn/sessiondata.h>
00036 #include <SignOn/uisessiondata.h>
00037 #include <SignOn/signonerror.h>
00038 
00039 QT_BEGIN_NAMESPACE
00040 class QString;
00041 class QStringList;
00042 class QByteArray;
00043 class QVariant;
00044 QT_END_NAMESPACE
00045 
00049 enum AuthPluginState {
00050     PLUGIN_STATE_NONE = 0,             
00051     PLUGIN_STATE_RESOLVING,          
00052     PLUGIN_STATE_CONNECTING,      
00053     PLUGIN_STATE_SENDING,             
00054     PLUGIN_STATE_WAITING,            
00055     PLUGIN_STATE_PENDING,             
00056     PLUGIN_STATE_REFRESHING,       
00057     PLUGIN_STATE_CANCELING,         
00058     PLUGIN_STATE_HOLDING,            
00059     PLUGIN_STATE_DONE                    
00060 };
00061 
00066 #define SIGNON_PLUGIN_INSTANCE(pluginclass) \
00067         { \
00068             static AuthPluginInterface *_instance = 0; \
00069             if (!_instance)      \
00070                 _instance = static_cast<AuthPluginInterface *>(new pluginclass()); \
00071             return _instance; \
00072         }
00073 
00074 #define SIGNON_DECL_AUTH_PLUGIN(pluginclass) \
00075         Q_EXTERN_C AuthPluginInterface *auth_plugin_instance() \
00076         SIGNON_PLUGIN_INSTANCE(pluginclass)
00077 
00082 class AuthPluginInterface : public QObject
00083 {
00084     Q_OBJECT
00085 
00086 public:
00087     AuthPluginInterface(QObject *parent = 0) : QObject(parent)
00088         { qRegisterMetaType<SignOn::Error>("SignOn::Error"); }
00089 
00093     virtual ~AuthPluginInterface() {}
00094 
00100     virtual QString type() const = 0;
00101 
00107     virtual QStringList mechanisms() const = 0;
00108 
00115     virtual void cancel() {}
00116 
00123     virtual void abort() {}
00124 
00138     virtual void process(const SignOn::SessionData &inData,
00139                          const QString &mechanism = QString()) = 0;
00140 
00141 Q_SIGNALS:
00148     void result(const SignOn::SessionData &data);
00149 
00160     void store(const SignOn::SessionData &data);
00161 
00169     void error(const SignOn::Error &err);
00170 
00183     void userActionRequired(const SignOn::UiSessionData &data);
00184 
00192     void refreshed(const SignOn::UiSessionData &data);
00193 
00201     void statusChanged(const AuthPluginState state,
00202                        const QString &message = QString());
00203 
00204 public Q_SLOTS:
00215     virtual void userActionFinished(const SignOn::UiSessionData &data) {
00216         Q_UNUSED(data);
00217     }
00218 
00231     virtual void refresh(const SignOn::UiSessionData &data) {
00232         emit refreshed(data);
00233     }
00234 
00235 };
00236 
00237 QT_BEGIN_NAMESPACE
00238  Q_DECLARE_INTERFACE(AuthPluginInterface,
00239                      "com.nokia.SingleSignOn.PluginInterface/1.3")
00240 QT_END_NAMESPACE
00241 #endif // AUTHPLUGINIF_H