Implemented YACReaderHttpSessionStore.

This commit is contained in:
Luis Ángel San Martín 2016-06-24 18:28:22 +02:00
parent 45ab9bc71f
commit 0788ae12a2
2 changed files with 62 additions and 4 deletions

View File

@ -1,6 +1,42 @@
#include "yacreader_http_session_store.h"
YACReaderHttpSessionStore::YACReaderHttpSessionStore(QObject *parent) : QObject(parent)
{
#include "httpsessionstore.h"
YACReaderHttpSessionStore::YACReaderHttpSessionStore(HttpSessionStore *sessionStore, QObject *parent)
: QObject(parent), sessionStore(sessionStore)
{
connect(&cleanupTimer,SIGNAL(timeout()),this,SLOT(sessionTimerEvent()));
cleanupTimer.start(60000);
}
void YACReaderHttpSessionStore::setYACReaderHttpSession(const QByteArray &httpSessionId, YACReaderHttpSession *yacreaderHttpSession)
{
QMutexLocker locker(&mutex);
sessions.insert(httpSessionId, yacreaderHttpSession);
}
YACReaderHttpSession *YACReaderHttpSessionStore::getYACReaderSessionHttpSession(const QByteArray &httpSessionId)
{
QMutexLocker locker(&mutex);
return sessions.value(id, nullptr);
}
void YACReaderHttpSessionStore::sessionTimerEvent()
{
QMutexLocker locker(&mutex);
for(const QByteArray &id : sessions.keys())
{
if(sessionStore->getSession(id).isNull())
{
YACReaderHttpSession *session = sessions.value(id, nullptr);
if(session != nullptr)
delete session;
sessions.remove(id);
}
}
}

View File

@ -2,16 +2,38 @@
#define YACREADERHTTPSESSIONSTORE_H
#include <QObject>
#include <QtCore>
class HttpSessionStore;
class YACReaderHttpSession;
class YACReaderHttpSessionStore : public QObject
{
Q_OBJECT
public:
explicit YACReaderHttpSessionStore(QObject *parent = 0);
explicit YACReaderHttpSessionStore(HttpSessionStore *sessionStore, QObject *parent = 0);
void setYACReaderHttpSession(const QByteArray & httpSessionId, YACReaderHttpSession *yacreaderHttpSession);
YACReaderHttpSession *getYACReaderSessionHttpSession(const QByteArray & httpSessionId);
signals:
public slots:
private:
QMap<QByteArray, YACReaderHttpSession*> sessions;
HttpSessionStore *sessionStore;
QTimer cleanupTimer;
QMutex mutex;
private slots:
void sessionTimerEvent();
};
#endif // YACREADERHTTPSESSIONSTORE_H
#endif // YACREADERHTTPSESSIONSTORE_H