2012-08-03 02:39:50 -04:00
|
|
|
/*
|
|
|
|
* Token Queue.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie, Christopher Evi-Parker
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-08-06 17:00:38 -04:00
|
|
|
#ifndef MRK_TOKEN_QUEUE_V2_H
|
|
|
|
#define MRK_TOKEN_QUEUE_V2_H
|
2012-08-03 02:39:50 -04:00
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QTimer>
|
2012-12-05 17:45:44 -05:00
|
|
|
#include <QMutex>
|
2012-08-03 02:39:50 -04:00
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <gxs/rstokenservice.h>
|
|
|
|
|
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
#define COMPLETED_REQUEST 4
|
2012-08-03 02:39:50 -04:00
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
#define TOKENREQ_GROUPINFO 1
|
|
|
|
#define TOKENREQ_MSGINFO 2
|
2012-12-05 17:45:44 -05:00
|
|
|
#define TOKENREQ_MSGRELATEDINFO 3
|
2012-08-03 02:39:50 -04:00
|
|
|
|
2012-08-18 06:01:35 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
class TokenQueue;
|
2012-08-03 02:39:50 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
class TokenRequest
|
2012-08-03 02:39:50 -04:00
|
|
|
{
|
2012-11-25 18:44:51 -05:00
|
|
|
public:
|
2012-08-03 02:39:50 -04:00
|
|
|
uint32_t mToken;
|
|
|
|
uint32_t mType;
|
|
|
|
uint32_t mAnsType;
|
|
|
|
uint32_t mUserType;
|
|
|
|
struct timeval mRequestTs;
|
|
|
|
struct timeval mPollTs;
|
|
|
|
};
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
class TokenResponse
|
2012-08-03 02:39:50 -04:00
|
|
|
{
|
2012-11-25 18:44:51 -05:00
|
|
|
public:
|
2012-08-03 02:39:50 -04:00
|
|
|
//virtual ~TokenResponse() { return; }
|
|
|
|
// These Functions are overloaded to get results out.
|
2012-11-25 18:44:51 -05:00
|
|
|
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req) = 0;
|
2012-08-03 02:39:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-09-13 18:58:42 -04:00
|
|
|
/*!
|
2012-09-30 10:21:17 -04:00
|
|
|
* An important thing to note is that all requests are stacked (so FIFO)
|
|
|
|
* This is to prevent overlapped loads on GXS UIs
|
2012-09-13 18:58:42 -04:00
|
|
|
*/
|
2012-12-06 12:51:07 -05:00
|
|
|
class TokenQueue: public QObject
|
2012-08-03 02:39:50 -04:00
|
|
|
{
|
2012-11-25 18:44:51 -05:00
|
|
|
Q_OBJECT
|
2012-08-03 02:39:50 -04:00
|
|
|
|
|
|
|
public:
|
2012-11-25 18:44:51 -05:00
|
|
|
TokenQueue(RsTokenService *service, TokenResponse *resp);
|
2012-08-03 02:39:50 -04:00
|
|
|
|
|
|
|
/* generic handling of token / response update behaviour */
|
2012-09-13 18:58:42 -04:00
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @token the token to be redeem is assigned here
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
|
|
|
std::list<RsGxsGroupId>& ids, uint32_t usertype);
|
2012-09-13 18:58:42 -04:00
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
bool requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, uint32_t usertype);
|
2012-09-18 17:19:29 -04:00
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
bool requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
|
|
|
const std::list<RsGxsGroupId>& grpIds, uint32_t usertype);
|
2012-09-13 18:58:42 -04:00
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
bool requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
|
|
|
const GxsMsgReq& grpIds, uint32_t usertype);
|
2012-09-13 18:58:42 -04:00
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
bool requestMsgRelatedInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair>& msgId, uint32_t usertype);
|
2012-08-03 02:39:50 -04:00
|
|
|
|
|
|
|
bool cancelRequest(const uint32_t token);
|
|
|
|
|
|
|
|
void queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype);
|
|
|
|
bool checkForRequest(uint32_t token);
|
2012-11-25 18:44:51 -05:00
|
|
|
void loadRequest(const TokenRequest &req);
|
2012-08-03 02:39:50 -04:00
|
|
|
|
2012-12-06 12:51:07 -05:00
|
|
|
bool activeRequestExist(const uint32_t& userType);
|
|
|
|
void activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens);
|
|
|
|
|
2012-08-03 02:39:50 -04:00
|
|
|
protected:
|
|
|
|
void doPoll(float dt);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void pollRequests();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* Info for Data Requests */
|
2012-11-25 18:44:51 -05:00
|
|
|
std::list<TokenRequest> mRequests;
|
2012-08-03 02:39:50 -04:00
|
|
|
|
2012-11-25 18:44:51 -05:00
|
|
|
RsTokenService *mService;
|
|
|
|
TokenResponse *mResponder;
|
2012-12-06 12:51:07 -05:00
|
|
|
QMutex mTokenMtx;
|
2012-08-03 02:39:50 -04:00
|
|
|
|
|
|
|
QTimer *mTrigger;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|