Added in Libresapi: StateToken refreshing to TransferHandler

This commit is contained in:
Konrad 2017-12-27 22:37:14 +01:00
parent 53118e5bde
commit 2db25d40cb
3 changed files with 22 additions and 6 deletions

View File

@ -236,8 +236,8 @@ public:
mForumHandler(ifaces.mGxsForums),
mServiceControlHandler(ifaces.mServiceControl),
mFileSearchHandler(sts, ifaces.mNotify, ifaces.mTurtle, ifaces.mFiles),
mFileSharingHandler(sts, ifaces.mFiles),
mTransfersHandler(sts, ifaces.mFiles, ifaces.mPeers),
mFileSharingHandler(sts, ifaces.mFiles, ifaces.mNotify),
mTransfersHandler(sts, ifaces.mFiles, ifaces.mPeers, ifaces.mNotify),
mChatHandler(sts, ifaces.mNotify, ifaces.mMsgs, ifaces.mPeers, ifaces.mIdentity, &mPeersHandler),
mApiPluginHandler(sts, ifaces),
mChannelsHandler(ifaces.mGxsChannels),

View File

@ -6,8 +6,9 @@
namespace resource_api
{
TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers):
mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0)
TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers,
RsNotify* notify):
mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0), mNotify(notify)
{
addResourceHandler("*", this, &TransfersHandler::handleWildcard);
addResourceHandler("downloads", this, &TransfersHandler::handleDownloads);
@ -15,11 +16,23 @@ TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeer
addResourceHandler("control_download", this, &TransfersHandler::handleControlDownload);
mStateToken = mStateTokenServer->getNewToken();
mStateTokenServer->registerTickClient(this);
mNotify->registerNotifyClient(this);
}
TransfersHandler::~TransfersHandler()
{
mStateTokenServer->unregisterTickClient(this);
mNotify->unregisterNotifyClient(this);
}
void TransfersHandler::notifyListChange(int list, int /* type */)
{
//RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
if(list == NOTIFY_LIST_TRANSFERLIST)
{
mStateTokenServer->discardToken(mStateToken);
mStateToken = mStateTokenServer->getNewToken();
}
}
const int UPDATE_PERIOD_SECONDS = 5;

View File

@ -5,16 +5,18 @@
#include <retroshare/rsfiles.h>
#include <retroshare/rspeers.h>
#include <retroshare/rsnotify.h>
namespace resource_api
{
class TransfersHandler: public ResourceRouter, Tickable
class TransfersHandler: public ResourceRouter, Tickable, NotifyClient
{
public:
TransfersHandler(StateTokenServer* sts, RsFiles* files, RsPeers *peers);
TransfersHandler(StateTokenServer* sts, RsFiles* files, RsPeers *peers, RsNotify* notify);
virtual ~TransfersHandler();
virtual void notifyListChange(int list, int type);
// from Tickable
virtual void tick();
private:
@ -26,6 +28,7 @@ private:
StateTokenServer* mStateTokenServer;
RsFiles* mFiles;
RsPeers* mRsPeers;
RsNotify* mNotify;
StateToken mStateToken;
time_t mLastUpdateTS;