mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Source code maintenance
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5897 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
8cef4da896
commit
6fba395054
@ -26,16 +26,14 @@
|
|||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
/******
|
/******
|
||||||
* #define ID_DEBUG 1
|
* #define ID_DEBUG 1
|
||||||
*****/
|
*****/
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *resp)
|
TokenQueue::TokenQueue(RsTokenService *service, TokenResponse *resp)
|
||||||
:QWidget(NULL), mService(service), mResponder(resp)
|
: QWidget(NULL), mService(service), mResponder(resp)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@ -47,14 +45,13 @@ bool TokenQueue::requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTok
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TokenQueue::requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, uint32_t usertype)
|
bool TokenQueue::requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, uint32_t usertype)
|
||||||
{
|
{
|
||||||
uint32_t basictype = TOKENREQ_GROUPINFO;
|
uint32_t basictype = TOKENREQ_GROUPINFO;
|
||||||
mService->requestGroupInfo(token, anstype, opts);
|
mService->requestGroupInfo(token, anstype, opts);
|
||||||
queueRequest(token, basictype, anstype, usertype);
|
queueRequest(token, basictype, anstype, usertype);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const GxsMsgReq& ids, uint32_t usertype)
|
bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const GxsMsgReq& ids, uint32_t usertype)
|
||||||
@ -66,35 +63,33 @@ bool TokenQueue::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokRe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TokenQueue::requestMsgRelatedInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair> &msgId, uint32_t usertype)
|
bool TokenQueue::requestMsgRelatedInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair> &msgId, uint32_t usertype)
|
||||||
{
|
{
|
||||||
uint32_t basictype = TOKENREQ_MSGINFO;
|
uint32_t basictype = TOKENREQ_MSGINFO;
|
||||||
mService->requestMsgRelatedInfo(token, anstype, opts, msgId);
|
mService->requestMsgRelatedInfo(token, anstype, opts, msgId);
|
||||||
queueRequest(token, basictype, anstype, usertype);
|
queueRequest(token, basictype, anstype, usertype);
|
||||||
|
|
||||||
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);
|
||||||
queueRequest(token, basictype, anstype, usertype);
|
queueRequest(token, basictype, anstype, usertype);
|
||||||
|
|
||||||
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;
|
||||||
std::cerr << " AnsType: " << anstype << " UserType: " << usertype;
|
std::cerr << " AnsType: " << anstype << " UserType: " << usertype;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
TokenRequest req;
|
TokenRequest req;
|
||||||
req.mToken = token;
|
req.mToken = token;
|
||||||
req.mType = basictype;
|
req.mType = basictype;
|
||||||
req.mAnsType = anstype;
|
req.mAnsType = anstype;
|
||||||
@ -103,7 +98,7 @@ 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)
|
||||||
{
|
{
|
||||||
@ -119,26 +114,23 @@ void TokenQueue::doPoll(float dt)
|
|||||||
QTimer::singleShot((int) (dt * 1000.0), this, SLOT(pollRequests()));
|
QTimer::singleShot((int) (dt * 1000.0), this, SLOT(pollRequests()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TokenQueue::pollRequests()
|
void TokenQueue::pollRequests()
|
||||||
{
|
{
|
||||||
double pollPeriod = 1.0; // max poll period.
|
double pollPeriod = 1.0; // max poll period.
|
||||||
|
|
||||||
|
if (mRequests.empty()) {
|
||||||
if (mRequests.empty())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 */
|
||||||
loadRequest(req);
|
loadRequest(req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -147,15 +139,14 @@ 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
|
||||||
{
|
{
|
||||||
std::cerr << "TokenQueue::loadRequest(): ";
|
std::cerr << "TokenQueue::loadRequest(): ";
|
||||||
std::cerr << "Dropping old Token: " << req.mToken << " Type: " << req.mType;
|
std::cerr << "Dropping old Token: " << req.mToken << " Type: " << req.mType;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mRequests.size() > 0)
|
if (mRequests.size() > 0)
|
||||||
@ -164,35 +155,31 @@ void TokenQueue::pollRequests()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TokenQueue::checkForRequest(uint32_t token)
|
bool TokenQueue::checkForRequest(uint32_t token)
|
||||||
{
|
{
|
||||||
/* check token */
|
/* check token */
|
||||||
uint32_t status = mService->requestStatus(token);
|
uint32_t status = mService->requestStatus(token);
|
||||||
return ( (RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == status) ||
|
return ( (RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == status) ||
|
||||||
(RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == status) );
|
(RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == status) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TokenQueue::loadRequest(const TokenRequest &req)
|
void TokenQueue::loadRequest(const TokenRequest &req)
|
||||||
{
|
{
|
||||||
std::cerr << "TokenQueue::loadRequest(): ";
|
std::cerr << "TokenQueue::loadRequest(): ";
|
||||||
std::cerr << "Token: " << req.mToken << " Type: " << req.mType;
|
std::cerr << "Token: " << req.mToken << " Type: " << req.mType;
|
||||||
std::cerr << " AnsType: " << req.mAnsType << " UserType: " << req.mUserType;
|
std::cerr << " AnsType: " << req.mAnsType << " UserType: " << req.mUserType;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
mResponder->loadRequest(this, req);
|
mResponder->loadRequest(this, req);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TokenQueue::cancelRequest(const uint32_t token)
|
bool TokenQueue::cancelRequest(const uint32_t token)
|
||||||
{
|
{
|
||||||
/* cancel at lower level first */
|
/* cancel at lower level first */
|
||||||
mService->cancelRequest(token);
|
mService->cancelRequest(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++)
|
||||||
{
|
{
|
||||||
@ -200,21 +187,15 @@ bool TokenQueue::cancelRequest(const uint32_t token)
|
|||||||
{
|
{
|
||||||
mRequests.erase(it);
|
mRequests.erase(it);
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,11 +33,10 @@
|
|||||||
#include <gxs/rstokenservice.h>
|
#include <gxs/rstokenservice.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define COMPLETED_REQUEST 4
|
||||||
|
|
||||||
#define COMPLETED_REQUEST 4
|
#define TOKENREQ_GROUPINFO 1
|
||||||
|
#define TOKENREQ_MSGINFO 2
|
||||||
#define TOKENREQ_GROUPINFO 1
|
|
||||||
#define TOKENREQ_MSGINFO 2
|
|
||||||
#define TOKENREQ_MSGRELATEDINFO 3
|
#define TOKENREQ_MSGRELATEDINFO 3
|
||||||
|
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ class TokenQueue;
|
|||||||
|
|
||||||
class TokenRequest
|
class TokenRequest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint32_t mToken;
|
uint32_t mToken;
|
||||||
uint32_t mType;
|
uint32_t mType;
|
||||||
uint32_t mAnsType;
|
uint32_t mAnsType;
|
||||||
@ -56,10 +55,10 @@ class TokenRequest
|
|||||||
|
|
||||||
class TokenResponse
|
class TokenResponse
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//virtual ~TokenResponse() { return; }
|
//virtual ~TokenResponse() { return; }
|
||||||
// These Functions are overloaded to get results out.
|
// These Functions are overloaded to get results out.
|
||||||
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req) = 0;
|
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -69,37 +68,36 @@ class TokenResponse
|
|||||||
*/
|
*/
|
||||||
class TokenQueue: public QWidget
|
class TokenQueue: public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TokenQueue(RsTokenService *service, TokenResponse *resp);
|
TokenQueue(RsTokenService *service, TokenResponse *resp);
|
||||||
|
|
||||||
/* generic handling of token / response update behaviour */
|
/* generic handling of token / response update behaviour */
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* @token the token to be redeem is assigned here
|
* @token the token to be redeem is assigned here
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
bool requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
||||||
std::list<RsGxsGroupId>& ids, uint32_t usertype);
|
std::list<RsGxsGroupId>& ids, uint32_t usertype);
|
||||||
|
|
||||||
|
bool requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, uint32_t usertype);
|
||||||
|
|
||||||
bool requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, uint32_t usertype);
|
bool requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
||||||
|
const std::list<RsGxsGroupId>& grpIds, uint32_t usertype);
|
||||||
|
|
||||||
bool requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
bool requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
||||||
const std::list<RsGxsGroupId>& grpIds, uint32_t usertype);
|
const GxsMsgReq& grpIds, uint32_t usertype);
|
||||||
|
|
||||||
bool requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
bool requestMsgRelatedInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair>& msgId, uint32_t usertype);
|
||||||
const GxsMsgReq& grpIds, uint32_t usertype);
|
|
||||||
|
|
||||||
bool requestMsgRelatedInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair>& msgId, uint32_t usertype);
|
|
||||||
|
|
||||||
bool cancelRequest(const uint32_t token);
|
bool cancelRequest(const uint32_t token);
|
||||||
|
|
||||||
void queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype);
|
void queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype);
|
||||||
bool checkForRequest(uint32_t token);
|
bool checkForRequest(uint32_t token);
|
||||||
void loadRequest(const TokenRequest &req);
|
void loadRequest(const TokenRequest &req);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void doPoll(float dt);
|
void doPoll(float dt);
|
||||||
@ -109,14 +107,12 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/* Info for Data Requests */
|
/* Info for Data Requests */
|
||||||
std::list<TokenRequest> mRequests;
|
std::list<TokenRequest> mRequests;
|
||||||
|
|
||||||
RsTokenService *mService;
|
RsTokenService *mService;
|
||||||
TokenResponse *mResponder;
|
TokenResponse *mResponder;
|
||||||
|
|
||||||
QTimer *mTrigger;
|
QTimer *mTrigger;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user