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), mForumHandler(ifaces.mGxsForums),
mServiceControlHandler(ifaces.mServiceControl), mServiceControlHandler(ifaces.mServiceControl),
mFileSearchHandler(sts, ifaces.mNotify, ifaces.mTurtle, ifaces.mFiles), mFileSearchHandler(sts, ifaces.mNotify, ifaces.mTurtle, ifaces.mFiles),
mFileSharingHandler(sts, ifaces.mFiles), mFileSharingHandler(sts, ifaces.mFiles, ifaces.mNotify),
mTransfersHandler(sts, ifaces.mFiles, ifaces.mPeers), mTransfersHandler(sts, ifaces.mFiles, ifaces.mPeers, ifaces.mNotify),
mChatHandler(sts, ifaces.mNotify, ifaces.mMsgs, ifaces.mPeers, ifaces.mIdentity, &mPeersHandler), mChatHandler(sts, ifaces.mNotify, ifaces.mMsgs, ifaces.mPeers, ifaces.mIdentity, &mPeersHandler),
mApiPluginHandler(sts, ifaces), mApiPluginHandler(sts, ifaces),
mChannelsHandler(ifaces.mGxsChannels), mChannelsHandler(ifaces.mGxsChannels),

View File

@ -6,8 +6,9 @@
namespace resource_api namespace resource_api
{ {
TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers): TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeers *peers,
mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0) RsNotify* notify):
mStateTokenServer(sts), mFiles(files), mRsPeers(peers), mLastUpdateTS(0), mNotify(notify)
{ {
addResourceHandler("*", this, &TransfersHandler::handleWildcard); addResourceHandler("*", this, &TransfersHandler::handleWildcard);
addResourceHandler("downloads", this, &TransfersHandler::handleDownloads); addResourceHandler("downloads", this, &TransfersHandler::handleDownloads);
@ -15,11 +16,23 @@ TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeer
addResourceHandler("control_download", this, &TransfersHandler::handleControlDownload); addResourceHandler("control_download", this, &TransfersHandler::handleControlDownload);
mStateToken = mStateTokenServer->getNewToken(); mStateToken = mStateTokenServer->getNewToken();
mStateTokenServer->registerTickClient(this); mStateTokenServer->registerTickClient(this);
mNotify->registerNotifyClient(this);
} }
TransfersHandler::~TransfersHandler() TransfersHandler::~TransfersHandler()
{ {
mStateTokenServer->unregisterTickClient(this); 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; const int UPDATE_PERIOD_SECONDS = 5;

View File

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