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:
thunder2 2013-07-16 00:03:20 +00:00
parent 4edcec6fe9
commit f4ee02bb01
4 changed files with 36 additions and 34 deletions

View File

@ -24,17 +24,27 @@
#include "RsProtectedTimer.h"
#define TIMER_FAST_POLL 499 // unique time in RetroShare
//#define PROTECTED_TIMER_DEBUG
RsProtectedTimer::RsProtectedTimer(QObject *parent)
: QTimer(parent)
{
mInterval = 0;
}
void RsProtectedTimer::timerEvent(QTimerEvent *e)
{
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
if (isSingleShot()) {
/* Singleshot timer will be stopped in QTimer::timerEvent */
@ -56,4 +66,15 @@ void RsProtectedTimer::timerEvent(QTimerEvent *e)
#endif
QTimer::timerEvent(e) ;
if (mInterval) {
if (interval() == TIMER_FAST_POLL) {
/* Still fast poll */
if (!isSingleShot()) {
/* Restore interval */
setInterval(mInterval); // restart timer
}
}
mInterval = 0;
}
}

View File

@ -31,6 +31,10 @@ public:
protected:
virtual void timerEvent(QTimerEvent *e);
private:
// do not use, please use setInterval, setSingleShot and connect signal timeout
static void singleShot(int /*msec*/, QObject */*receiver*/, const char */*member*/) {}
private:
int mInterval;
};

View File

@ -22,7 +22,7 @@
*/
#include "util/TokenQueue.h"
#include "retroshare-gui/RsAutoUpdatePage.h"
#include "util/RsProtectedTimer.h"
#include <iostream>
#include <QTimer>
@ -35,6 +35,9 @@
TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *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)
@ -73,8 +76,7 @@ bool TokenQueue::requestMsgRelatedInfo(uint32_t &token, uint32_t anstype, const
return true;
}
bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
const std::list<RsGxsGroupId> &grpIds, uint32_t usertype)
bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const std::list<RsGxsGroupId> &grpIds, uint32_t usertype)
{
uint32_t basictype = TOKENREQ_MSGINFO;
mService->requestMsgInfo(token, anstype, opts, grpIds);
@ -83,7 +85,6 @@ bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokRe
return true;
}
void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype)
{
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);
req.mPollTs = req.mRequestTs;
mRequests.push_back(req);
if (mRequests.size() == 1)
{
/* start the timer */
@ -113,15 +112,11 @@ void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t ansty
void TokenQueue::doPoll(float dt)
{
/* single shot poll */
//mTrigger->singlesshot(dt * 1000);
QTimer::singleShot((int) (dt * 1000.0), this, SLOT(pollRequests()));
mTrigger->start(dt * 1000);
}
void TokenQueue::pollRequests()
{
if(RsAutoUpdatePage::eventsLocked())
return ;
double pollPeriod = 1.0; // max poll period.
if (mRequests.empty()) {
@ -130,11 +125,9 @@ void TokenQueue::pollRequests()
TokenRequest req;
req = mRequests.front();
mRequests.pop_front();
if (checkForRequest(req.mToken))
{
/* clean it up and handle */
@ -148,9 +141,7 @@ void TokenQueue::pollRequests()
/* drop old requests too */
if (time(NULL) - req.mRequestTs.tv_sec < MAX_REQUEST_AGE)
{
mRequests.push_back(req);
}
else
{
@ -176,8 +167,6 @@ bool TokenQueue::checkForRequest(uint32_t token)
bool TokenQueue::activeRequestExist(const uint32_t& userType) const
{
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
for(; lit != mRequests.end(); lit++)
@ -186,20 +175,15 @@ bool TokenQueue::activeRequestExist(const uint32_t& userType) const
if(req.mUserType == userType)
{
return true;
}
}
return false;
}
void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens) const
{
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
for(; lit != mRequests.end(); lit++)
@ -209,8 +193,6 @@ void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_
if(req.mUserType == userType)
tokens.push_back(req.mToken);
}
}
void TokenQueue::cancelActiveRequestTokens(const uint32_t& userType)
@ -242,7 +224,6 @@ bool TokenQueue::cancelRequest(const uint32_t token)
std::list<TokenRequest>::iterator it;
for(it = mRequests.begin(); it != mRequests.end(); it++)
{
if (it->mToken == token)
@ -252,13 +233,10 @@ bool TokenQueue::cancelRequest(const uint32_t token)
std::cerr << "TokenQueue::cancelRequest() Cleared Request: " << token;
std::cerr << std::endl;
return true;
}
}
std::cerr << "TokenQueue::cancelRequest() Failed to Find Request: " << token;
std::cerr << std::endl;

View File

@ -39,7 +39,6 @@
#define TOKENREQ_MSGINFO 2
#define TOKENREQ_MSGRELATEDINFO 3
class TokenQueue;
class TokenRequest