mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Implemented YACReaderHttpSessionStore.
This commit is contained in:
parent
45ab9bc71f
commit
0788ae12a2
@ -1,6 +1,42 @@
|
|||||||
#include "yacreader_http_session_store.h"
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,38 @@
|
|||||||
#define YACREADERHTTPSESSIONSTORE_H
|
#define YACREADERHTTPSESSIONSTORE_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QtCore>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class HttpSessionStore;
|
||||||
|
class YACReaderHttpSession;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class YACReaderHttpSessionStore : public QObject
|
class YACReaderHttpSessionStore : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMap<QByteArray, YACReaderHttpSession*> sessions;
|
||||||
|
HttpSessionStore *sessionStore;
|
||||||
|
QTimer cleanupTimer;
|
||||||
|
|
||||||
|
QMutex mutex;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void sessionTimerEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // YACREADERHTTPSESSIONSTORE_H
|
#endif // YACREADERHTTPSESSIONSTORE_H
|
Loading…
x
Reference in New Issue
Block a user