mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 16:39:43 -05:00
TokenQueue:
- fixed stop of TokenQueue polling when events are locked RsProtectedTimer: - switched to faster poll when events are locked git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6507 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4edcec6fe9
commit
f4ee02bb01
@ -24,17 +24,27 @@
|
|||||||
|
|
||||||
#include "RsProtectedTimer.h"
|
#include "RsProtectedTimer.h"
|
||||||
|
|
||||||
|
#define TIMER_FAST_POLL 499 // unique time in RetroShare
|
||||||
|
|
||||||
//#define PROTECTED_TIMER_DEBUG
|
//#define PROTECTED_TIMER_DEBUG
|
||||||
|
|
||||||
RsProtectedTimer::RsProtectedTimer(QObject *parent)
|
RsProtectedTimer::RsProtectedTimer(QObject *parent)
|
||||||
: QTimer(parent)
|
: QTimer(parent)
|
||||||
{
|
{
|
||||||
|
mInterval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsProtectedTimer::timerEvent(QTimerEvent *e)
|
void RsProtectedTimer::timerEvent(QTimerEvent *e)
|
||||||
{
|
{
|
||||||
if(RsAutoUpdatePage::eventsLocked())
|
if(RsAutoUpdatePage::eventsLocked())
|
||||||
{
|
{
|
||||||
|
if (!mInterval && interval() > TIMER_FAST_POLL) {
|
||||||
|
/* Save interval */
|
||||||
|
mInterval = interval();
|
||||||
|
/* Set fast interval */
|
||||||
|
setInterval(TIMER_FAST_POLL); // restart timer
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PROTECTED_TIMER_DEBUG
|
#ifdef PROTECTED_TIMER_DEBUG
|
||||||
if (isSingleShot()) {
|
if (isSingleShot()) {
|
||||||
/* Singleshot timer will be stopped in QTimer::timerEvent */
|
/* Singleshot timer will be stopped in QTimer::timerEvent */
|
||||||
@ -56,4 +66,15 @@ void RsProtectedTimer::timerEvent(QTimerEvent *e)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTimer::timerEvent(e) ;
|
QTimer::timerEvent(e) ;
|
||||||
|
|
||||||
|
if (mInterval) {
|
||||||
|
if (interval() == TIMER_FAST_POLL) {
|
||||||
|
/* Still fast poll */
|
||||||
|
if (!isSingleShot()) {
|
||||||
|
/* Restore interval */
|
||||||
|
setInterval(mInterval); // restart timer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mInterval = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void timerEvent(QTimerEvent *e);
|
virtual void timerEvent(QTimerEvent *e);
|
||||||
|
|
||||||
|
private:
|
||||||
// do not use, please use setInterval, setSingleShot and connect signal timeout
|
// do not use, please use setInterval, setSingleShot and connect signal timeout
|
||||||
static void singleShot(int /*msec*/, QObject */*receiver*/, const char */*member*/) {}
|
static void singleShot(int /*msec*/, QObject */*receiver*/, const char */*member*/) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int mInterval;
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "util/TokenQueue.h"
|
#include "util/TokenQueue.h"
|
||||||
#include "retroshare-gui/RsAutoUpdatePage.h"
|
#include "util/RsProtectedTimer.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@ -35,6 +35,9 @@
|
|||||||
TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *resp)
|
TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *resp)
|
||||||
: QObject(NULL), mService(service), mResponder(resp)
|
: QObject(NULL), mService(service), mResponder(resp)
|
||||||
{
|
{
|
||||||
|
mTrigger = new RsProtectedTimer(this);
|
||||||
|
mTrigger->setSingleShot(true);
|
||||||
|
connect(mTrigger, SIGNAL(timeout()), this, SLOT(pollRequests()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TokenQueue::requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, std::list<RsGxsGroupId>& ids, uint32_t usertype)
|
bool TokenQueue::requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, std::list<RsGxsGroupId>& ids, uint32_t usertype)
|
||||||
@ -73,8 +76,7 @@ bool TokenQueue::requestMsgRelatedInfo(uint32_t &token, uint32_t anstype, const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const std::list<RsGxsGroupId> &grpIds, uint32_t usertype)
|
||||||
const std::list<RsGxsGroupId> &grpIds, uint32_t usertype)
|
|
||||||
{
|
{
|
||||||
uint32_t basictype = TOKENREQ_MSGINFO;
|
uint32_t basictype = TOKENREQ_MSGINFO;
|
||||||
mService->requestMsgInfo(token, anstype, opts, grpIds);
|
mService->requestMsgInfo(token, anstype, opts, grpIds);
|
||||||
@ -83,7 +85,6 @@ bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokRe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype)
|
void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype)
|
||||||
{
|
{
|
||||||
std::cerr << "TokenQueue::queueRequest() Token: " << token << " Type: " << basictype;
|
std::cerr << "TokenQueue::queueRequest() Token: " << token << " Type: " << basictype;
|
||||||
@ -99,10 +100,8 @@ void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t ansty
|
|||||||
gettimeofday(&req.mRequestTs, NULL);
|
gettimeofday(&req.mRequestTs, NULL);
|
||||||
req.mPollTs = req.mRequestTs;
|
req.mPollTs = req.mRequestTs;
|
||||||
|
|
||||||
|
|
||||||
mRequests.push_back(req);
|
mRequests.push_back(req);
|
||||||
|
|
||||||
|
|
||||||
if (mRequests.size() == 1)
|
if (mRequests.size() == 1)
|
||||||
{
|
{
|
||||||
/* start the timer */
|
/* start the timer */
|
||||||
@ -113,15 +112,11 @@ void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t ansty
|
|||||||
void TokenQueue::doPoll(float dt)
|
void TokenQueue::doPoll(float dt)
|
||||||
{
|
{
|
||||||
/* single shot poll */
|
/* single shot poll */
|
||||||
//mTrigger->singlesshot(dt * 1000);
|
mTrigger->start(dt * 1000);
|
||||||
QTimer::singleShot((int) (dt * 1000.0), this, SLOT(pollRequests()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenQueue::pollRequests()
|
void TokenQueue::pollRequests()
|
||||||
{
|
{
|
||||||
if(RsAutoUpdatePage::eventsLocked())
|
|
||||||
return ;
|
|
||||||
|
|
||||||
double pollPeriod = 1.0; // max poll period.
|
double pollPeriod = 1.0; // max poll period.
|
||||||
|
|
||||||
if (mRequests.empty()) {
|
if (mRequests.empty()) {
|
||||||
@ -130,11 +125,9 @@ void TokenQueue::pollRequests()
|
|||||||
|
|
||||||
TokenRequest req;
|
TokenRequest req;
|
||||||
|
|
||||||
|
|
||||||
req = mRequests.front();
|
req = mRequests.front();
|
||||||
mRequests.pop_front();
|
mRequests.pop_front();
|
||||||
|
|
||||||
|
|
||||||
if (checkForRequest(req.mToken))
|
if (checkForRequest(req.mToken))
|
||||||
{
|
{
|
||||||
/* clean it up and handle */
|
/* clean it up and handle */
|
||||||
@ -148,9 +141,7 @@ void TokenQueue::pollRequests()
|
|||||||
/* drop old requests too */
|
/* drop old requests too */
|
||||||
if (time(NULL) - req.mRequestTs.tv_sec < MAX_REQUEST_AGE)
|
if (time(NULL) - req.mRequestTs.tv_sec < MAX_REQUEST_AGE)
|
||||||
{
|
{
|
||||||
|
|
||||||
mRequests.push_back(req);
|
mRequests.push_back(req);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -176,8 +167,6 @@ bool TokenQueue::checkForRequest(uint32_t token)
|
|||||||
|
|
||||||
bool TokenQueue::activeRequestExist(const uint32_t& userType) const
|
bool TokenQueue::activeRequestExist(const uint32_t& userType) const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||||
|
|
||||||
for(; lit != mRequests.end(); lit++)
|
for(; lit != mRequests.end(); lit++)
|
||||||
@ -186,20 +175,15 @@ bool TokenQueue::activeRequestExist(const uint32_t& userType) const
|
|||||||
|
|
||||||
if(req.mUserType == userType)
|
if(req.mUserType == userType)
|
||||||
{
|
{
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens) const
|
void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens) const
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||||
|
|
||||||
for(; lit != mRequests.end(); lit++)
|
for(; lit != mRequests.end(); lit++)
|
||||||
@ -209,8 +193,6 @@ void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_
|
|||||||
if(req.mUserType == userType)
|
if(req.mUserType == userType)
|
||||||
tokens.push_back(req.mToken);
|
tokens.push_back(req.mToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenQueue::cancelActiveRequestTokens(const uint32_t& userType)
|
void TokenQueue::cancelActiveRequestTokens(const uint32_t& userType)
|
||||||
@ -242,7 +224,6 @@ bool TokenQueue::cancelRequest(const uint32_t token)
|
|||||||
|
|
||||||
std::list<TokenRequest>::iterator it;
|
std::list<TokenRequest>::iterator it;
|
||||||
|
|
||||||
|
|
||||||
for(it = mRequests.begin(); it != mRequests.end(); it++)
|
for(it = mRequests.begin(); it != mRequests.end(); it++)
|
||||||
{
|
{
|
||||||
if (it->mToken == token)
|
if (it->mToken == token)
|
||||||
@ -252,13 +233,10 @@ bool TokenQueue::cancelRequest(const uint32_t token)
|
|||||||
std::cerr << "TokenQueue::cancelRequest() Cleared Request: " << token;
|
std::cerr << "TokenQueue::cancelRequest() Cleared Request: " << token;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cerr << "TokenQueue::cancelRequest() Failed to Find Request: " << token;
|
std::cerr << "TokenQueue::cancelRequest() Failed to Find Request: " << token;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#define TOKENREQ_MSGINFO 2
|
#define TOKENREQ_MSGINFO 2
|
||||||
#define TOKENREQ_MSGRELATEDINFO 3
|
#define TOKENREQ_MSGRELATEDINFO 3
|
||||||
|
|
||||||
|
|
||||||
class TokenQueue;
|
class TokenQueue;
|
||||||
|
|
||||||
class TokenRequest
|
class TokenRequest
|
||||||
|
Loading…
Reference in New Issue
Block a user