mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
Switched base class of TokenQueue from QWidget to QObject.
Fixed unlock of the mutex in TokenQueue. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5949 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
de757cfcae
commit
0c49fba4d8
@ -32,7 +32,7 @@
|
||||
|
||||
/** Constructor */
|
||||
TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *resp)
|
||||
: QWidget(NULL), mService(service), mResponder(resp)
|
||||
: QObject(NULL), mService(service), mResponder(resp)
|
||||
{
|
||||
}
|
||||
|
||||
@ -98,9 +98,9 @@ void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t ansty
|
||||
gettimeofday(&req.mRequestTs, NULL);
|
||||
req.mPollTs = req.mRequestTs;
|
||||
|
||||
mTokenMtx.lock();
|
||||
mTokenMtx.lock();
|
||||
mRequests.push_back(req);
|
||||
mTokenMtx.unlock();
|
||||
mTokenMtx.unlock();
|
||||
|
||||
if (mRequests.size() == 1)
|
||||
{
|
||||
@ -126,10 +126,10 @@ void TokenQueue::pollRequests()
|
||||
|
||||
TokenRequest req;
|
||||
|
||||
mTokenMtx.lock();
|
||||
mTokenMtx.lock();
|
||||
req = mRequests.front();
|
||||
mRequests.pop_front();
|
||||
mTokenMtx.unlock();
|
||||
mTokenMtx.unlock();
|
||||
|
||||
if (checkForRequest(req.mToken))
|
||||
{
|
||||
@ -144,9 +144,9 @@ void TokenQueue::pollRequests()
|
||||
/* drop old requests too */
|
||||
if (time(NULL) - req.mRequestTs.tv_sec < MAX_REQUEST_AGE)
|
||||
{
|
||||
mTokenMtx.lock();
|
||||
mTokenMtx.lock();
|
||||
mRequests.push_back(req);
|
||||
mTokenMtx.unlock();
|
||||
mTokenMtx.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -172,36 +172,41 @@ bool TokenQueue::checkForRequest(uint32_t token)
|
||||
|
||||
bool TokenQueue::activeRequestExist(const uint32_t& userType)
|
||||
{
|
||||
mTokenMtx.lock();
|
||||
mTokenMtx.lock();
|
||||
|
||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||
|
||||
for(; lit != mRequests.end(); lit++)
|
||||
{
|
||||
const TokenRequest& req = *lit;
|
||||
for(; lit != mRequests.end(); lit++)
|
||||
{
|
||||
const TokenRequest& req = *lit;
|
||||
|
||||
if(req.mUserType == userType)
|
||||
return true;
|
||||
}
|
||||
if(req.mUserType == userType)
|
||||
{
|
||||
mTokenMtx.unlock();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
mTokenMtx.unlock();
|
||||
mTokenMtx.unlock();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens)
|
||||
{
|
||||
mTokenMtx.lock();
|
||||
mTokenMtx.lock();
|
||||
|
||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||
|
||||
for(; lit != mRequests.end(); lit++)
|
||||
{
|
||||
const TokenRequest& req = *lit;
|
||||
for(; lit != mRequests.end(); lit++)
|
||||
{
|
||||
const TokenRequest& req = *lit;
|
||||
|
||||
if(req.mUserType == userType)
|
||||
tokens.push_back(req.mToken);
|
||||
}
|
||||
if(req.mUserType == userType)
|
||||
tokens.push_back(req.mToken);
|
||||
}
|
||||
|
||||
mTokenMtx.unlock();
|
||||
mTokenMtx.unlock();
|
||||
}
|
||||
|
||||
void TokenQueue::loadRequest(const TokenRequest &req)
|
||||
@ -221,7 +226,7 @@ bool TokenQueue::cancelRequest(const uint32_t token)
|
||||
|
||||
std::list<TokenRequest>::iterator it;
|
||||
|
||||
mTokenMtx.lock();
|
||||
mTokenMtx.lock();
|
||||
for(it = mRequests.begin(); it != mRequests.end(); it++)
|
||||
{
|
||||
if (it->mToken == token)
|
||||
@ -231,10 +236,12 @@ bool TokenQueue::cancelRequest(const uint32_t token)
|
||||
std::cerr << "TokenQueue::cancelRequest() Cleared Request: " << token;
|
||||
std::cerr << std::endl;
|
||||
|
||||
mTokenMtx.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
mTokenMtx.unlock();
|
||||
mTokenMtx.unlock();
|
||||
|
||||
std::cerr << "TokenQueue::cancelRequest() Failed to Find Request: " << token;
|
||||
std::cerr << std::endl;
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
* An important thing to note is that all requests are stacked (so FIFO)
|
||||
* This is to prevent overlapped loads on GXS UIs
|
||||
*/
|
||||
class TokenQueue: public QWidget
|
||||
class TokenQueue: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -100,8 +100,9 @@ public:
|
||||
bool checkForRequest(uint32_t token);
|
||||
void loadRequest(const TokenRequest &req);
|
||||
|
||||
bool activeRequestExist(const uint32_t& userType);
|
||||
void activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens);
|
||||
bool activeRequestExist(const uint32_t& userType);
|
||||
void activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens);
|
||||
|
||||
protected:
|
||||
void doPoll(float dt);
|
||||
|
||||
@ -114,7 +115,7 @@ private:
|
||||
|
||||
RsTokenService *mService;
|
||||
TokenResponse *mResponder;
|
||||
QMutex mTokenMtx;
|
||||
QMutex mTokenMtx;
|
||||
|
||||
QTimer *mTrigger;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user