signon  8.58
signonauthsession.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  * Copyright (C) 2013 Canonical Ltd.
00006  *
00007  * Conta 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  */
00023 
00024 #include "signond-common.h"
00025 #include "signonauthsession.h"
00026 #include "signonauthsessionadaptor.h"
00027 
00028 using namespace SignonDaemonNS;
00029 
00030 SignonAuthSession::SignonAuthSession(quint32 id,
00031                                      const QString &method,
00032                                      pid_t ownerPid):
00033     m_id(id),
00034     m_method(method),
00035     m_ownerPid(ownerPid)
00036 {
00037     TRACE();
00038 
00039     (void)new SignonAuthSessionAdaptor(this);
00040 
00041     static quint32 incr = 0;
00042     QString objectName = SIGNOND_DAEMON_OBJECTPATH +
00043         QLatin1String("/AuthSession_") + QString::number(incr++, 16);
00044     TRACE() << objectName;
00045 
00046     setObjectName(objectName);
00047 }
00048 
00049 SignonAuthSession::~SignonAuthSession()
00050 {
00051     Q_EMIT unregistered();
00052     TRACE();
00053 }
00054 
00055 SignonAuthSession *SignonAuthSession::createAuthSession(const quint32 id,
00056                                                         const QString &method,
00057                                                         SignonDaemon *parent,
00058                                                         pid_t ownerPid)
00059 {
00060     TRACE();
00061     SignonAuthSession *sas = new SignonAuthSession(id, method, ownerPid);
00062 
00063     SignonSessionCore *core = SignonSessionCore::sessionCore(id, method, parent);
00064     if (!core) {
00065         TRACE() << "Cannot retrieve proper tasks queue";
00066         delete sas;
00067         return NULL;
00068     }
00069 
00070     sas->setParent(core);
00071 
00072     connect(core, SIGNAL(stateChanged(const QString&, int, const QString&)),
00073             sas, SLOT(stateChangedSlot(const QString&, int, const QString&)));
00074 
00075     TRACE() << "SignonAuthSession created successfully:" << sas->objectName();
00076     return sas;
00077 }
00078 
00079 void SignonAuthSession::stopAllAuthSessions()
00080 {
00081     SignonSessionCore::stopAllAuthSessions();
00082 }
00083 
00084 quint32 SignonAuthSession::id() const
00085 {
00086     return m_id;
00087 }
00088 
00089 QString SignonAuthSession::method() const
00090 {
00091     return m_method;
00092 }
00093 
00094 pid_t SignonAuthSession::ownerPid() const
00095 {
00096     return m_ownerPid;
00097 }
00098 
00099 QStringList
00100 SignonAuthSession::queryAvailableMechanisms(const QStringList &wantedMechanisms)
00101 {
00102     return parent()->queryAvailableMechanisms(wantedMechanisms);
00103 }
00104 
00105 QVariantMap SignonAuthSession::process(const QVariantMap &sessionDataVa,
00106                                        const QString &mechanism)
00107 {
00108     setDelayedReply(true);
00109     parent()->process(connection(),
00110                       message(),
00111                       sessionDataVa,
00112                       mechanism,
00113                       objectName());
00114     return QVariantMap();
00115 }
00116 
00117 void SignonAuthSession::cancel()
00118 {
00119     TRACE();
00120     parent()->cancel(objectName());
00121 }
00122 
00123 void SignonAuthSession::setId(quint32 id)
00124 {
00125     m_id = id;
00126     parent()->setId(id);
00127 }
00128 
00129 void SignonAuthSession::objectUnref()
00130 {
00131     //TODO - remove the `objectUnref` functionality from the DBus API
00132     TRACE();
00133     cancel();
00134 
00135     deleteLater();
00136 }
00137 
00138 void SignonAuthSession::stateChangedSlot(const QString &sessionKey,
00139                                          int state,
00140                                          const QString &message)
00141 {
00142     TRACE();
00143 
00144     if (sessionKey == objectName())
00145         emit stateChanged(state, message);
00146 }