From 0788ae12a26bede78995f22fa803f580c1038ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Fri, 24 Jun 2016 18:28:22 +0200 Subject: [PATCH] Implemented YACReaderHttpSessionStore. --- .../server/yacreader_http_session_store.cpp | 40 ++++++++++++++++++- .../server/yacreader_http_session_store.h | 26 +++++++++++- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/YACReaderLibrary/server/yacreader_http_session_store.cpp b/YACReaderLibrary/server/yacreader_http_session_store.cpp index e1458141..10f71105 100644 --- a/YACReaderLibrary/server/yacreader_http_session_store.cpp +++ b/YACReaderLibrary/server/yacreader_http_session_store.cpp @@ -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); + } + } } diff --git a/YACReaderLibrary/server/yacreader_http_session_store.h b/YACReaderLibrary/server/yacreader_http_session_store.h index 56cc3abe..fe88cbdf 100644 --- a/YACReaderLibrary/server/yacreader_http_session_store.h +++ b/YACReaderLibrary/server/yacreader_http_session_store.h @@ -2,16 +2,38 @@ #define YACREADERHTTPSESSIONSTORE_H #include +#include + + + +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 sessions; + HttpSessionStore *sessionStore; + QTimer cleanupTimer; + + QMutex mutex; + +private slots: + + void sessionTimerEvent(); }; -#endif // YACREADERHTTPSESSIONSTORE_H \ No newline at end of file +#endif // YACREADERHTTPSESSIONSTORE_H