mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-11-29 11:56:37 -05:00
fresh recompile needed!
TokenQueueV2 added, first change to photoshare to deal with gxs backend needed to redirect meta types to mine in order to get compilation working and definition fixes to rsgenexchange. Next step is to get GxsRunner going git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5377 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
09b5d7a8c6
commit
d220e14c4a
21 changed files with 490 additions and 156 deletions
|
|
@ -29,10 +29,9 @@
|
|||
#include <list>
|
||||
#include <string>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
||||
|
||||
#define COMPLETED_REQUEST 4
|
||||
|
||||
#define TOKENREQ_GROUPINFO 1
|
||||
|
|
|
|||
173
retroshare-gui/src/util/TokenQueueV2.cpp
Normal file
173
retroshare-gui/src/util/TokenQueueV2.cpp
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* Token Queue.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "util/TokenQueueV2.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
/******
|
||||
* #define ID_DEBUG 1
|
||||
*****/
|
||||
|
||||
/** Constructor */
|
||||
TokenQueueV2::TokenQueueV2(RsTokenServiceV2 *service, TokenResponseV2 *resp)
|
||||
:QWidget(NULL), mService(service), mResponder(resp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool TokenQueueV2::requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, std::list<RsGxsGroupId>& ids, uint32_t usertype)
|
||||
{
|
||||
uint32_t basictype = TOKENREQ_GROUPINFO;
|
||||
mService->requestGroupInfo(token, anstype, opts, ids);
|
||||
queueRequest(token, basictype, anstype, usertype);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool TokenQueueV2::requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts, const GxsMsgReq& ids, uint32_t usertype)
|
||||
{
|
||||
uint32_t basictype = TOKENREQ_MSGINFO;
|
||||
mService->requestMsgInfo(token, anstype, opts, ids);
|
||||
queueRequest(token, basictype, anstype, usertype);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TokenQueueV2::queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype)
|
||||
{
|
||||
std::cerr << "TokenQueueV2::queueRequest() Token: " << token << " Type: " << basictype;
|
||||
std::cerr << " AnsType: " << anstype << " UserType: " << usertype;
|
||||
std::cerr << std::endl;
|
||||
|
||||
TokenRequestV2 req;
|
||||
req.mToken = token;
|
||||
req.mType = basictype;
|
||||
req.mAnsType = anstype;
|
||||
req.mUserType = usertype;
|
||||
|
||||
gettimeofday(&req.mRequestTs, NULL);
|
||||
req.mPollTs = req.mRequestTs;
|
||||
|
||||
mRequests.push_back(req);
|
||||
|
||||
if (mRequests.size() == 1)
|
||||
{
|
||||
/* start the timer */
|
||||
doPoll(0.1);
|
||||
}
|
||||
}
|
||||
|
||||
void TokenQueueV2::doPoll(float dt)
|
||||
{
|
||||
/* single shot poll */
|
||||
//mTrigger->singlesshot(dt * 1000);
|
||||
QTimer::singleShot((int) (dt * 1000.0), this, SLOT(pollRequests()));
|
||||
}
|
||||
|
||||
|
||||
void TokenQueueV2::pollRequests()
|
||||
{
|
||||
std::list<TokenRequestV2>::iterator it;
|
||||
|
||||
double pollPeriod = 1.0; // max poll period.
|
||||
for(it = mRequests.begin(); it != mRequests.end();)
|
||||
{
|
||||
if (checkForRequest(it->mToken))
|
||||
{
|
||||
/* clean it up and handle */
|
||||
loadRequest(*it);
|
||||
it = mRequests.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* calculate desired poll period */
|
||||
|
||||
/* if less then current poll period, adjust */
|
||||
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
if (mRequests.size() > 0)
|
||||
{
|
||||
doPoll(pollPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool TokenQueueV2::checkForRequest(uint32_t token)
|
||||
{
|
||||
/* check token */
|
||||
return (COMPLETED_REQUEST == mService->requestStatus(token));
|
||||
}
|
||||
|
||||
|
||||
void TokenQueueV2::loadRequest(const TokenRequestV2 &req)
|
||||
{
|
||||
std::cerr << "TokenQueueV2::loadRequest(): ";
|
||||
std::cerr << "Token: " << req.mToken << " Type: " << req.mType;
|
||||
std::cerr << " AnsType: " << req.mAnsType << " UserType: " << req.mUserType;
|
||||
std::cerr << std::endl;
|
||||
|
||||
mResponder->loadRequest(this, req);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool TokenQueueV2::cancelRequest(const uint32_t token)
|
||||
{
|
||||
/* cancel at lower level first */
|
||||
mService->cancelRequest(token);
|
||||
|
||||
std::list<TokenRequestV2>::iterator it;
|
||||
|
||||
for(it = mRequests.begin(); it != mRequests.end(); it++)
|
||||
{
|
||||
if (it->mToken == token)
|
||||
{
|
||||
mRequests.erase(it);
|
||||
|
||||
std::cerr << "TokenQueueV2::cancelRequest() Cleared Request: " << token;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "TokenQueueV2::cancelRequest() Failed to Find Request: " << token;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
102
retroshare-gui/src/util/TokenQueueV2.h
Normal file
102
retroshare-gui/src/util/TokenQueueV2.h
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MRK_TOKEN_QUEUE_H
|
||||
#define MRK_TOKEN_QUEUE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <gxs/rstokenservice.h>
|
||||
|
||||
|
||||
|
||||
#define COMPLETED_REQUEST 4
|
||||
|
||||
#define TOKENREQ_GROUPINFO 1
|
||||
#define TOKENREQ_MSGINFO 2
|
||||
#define TOKENREQ_MSGRELATEDINFO 3
|
||||
|
||||
class TokenQueueV2;
|
||||
|
||||
class TokenRequestV2
|
||||
{
|
||||
public:
|
||||
uint32_t mToken;
|
||||
uint32_t mType;
|
||||
uint32_t mAnsType;
|
||||
uint32_t mUserType;
|
||||
struct timeval mRequestTs;
|
||||
struct timeval mPollTs;
|
||||
};
|
||||
|
||||
class TokenResponseV2
|
||||
{
|
||||
public:
|
||||
//virtual ~TokenResponse() { return; }
|
||||
// These Functions are overloaded to get results out.
|
||||
virtual void loadRequest(const TokenQueueV2 *queue, const TokenRequestV2 &req) = 0;
|
||||
};
|
||||
|
||||
|
||||
class TokenQueueV2: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TokenQueueV2(RsTokenServiceV2 *service, TokenResponseV2 *resp);
|
||||
|
||||
/* generic handling of token / response update behaviour */
|
||||
bool requestGroupInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
||||
std::list<RsGxsGroupId>& ids, uint32_t usertype);
|
||||
bool requestMsgInfo(uint32_t &token, uint32_t anstype, const RsTokReqOptions &opts,
|
||||
const GxsMsgReq& ids, uint32_t usertype);
|
||||
|
||||
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);
|
||||
void loadRequest(const TokenRequestV2 &req);
|
||||
|
||||
protected:
|
||||
void doPoll(float dt);
|
||||
|
||||
private slots:
|
||||
void pollRequests();
|
||||
|
||||
private:
|
||||
/* Info for Data Requests */
|
||||
std::list<TokenRequestV2> mRequests;
|
||||
|
||||
RsTokenServiceV2 *mService;
|
||||
TokenResponseV2 *mResponder;
|
||||
|
||||
QTimer *mTrigger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue