From 2db25d40cbfb073da0d744873129d97237182b86 Mon Sep 17 00:00:00 2001 From: Konrad Date: Wed, 27 Dec 2017 22:37:14 +0100 Subject: [PATCH] Added in Libresapi: StateToken refreshing to TransferHandler --- libresapi/src/api/ApiServer.cpp | 4 ++-- libresapi/src/api/TransfersHandler.cpp | 17 +++++++++++++++-- libresapi/src/api/TransfersHandler.h | 7 +++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libresapi/src/api/ApiServer.cpp b/libresapi/src/api/ApiServer.cpp index db642c020..d2f672e40 100644 --- a/libresapi/src/api/ApiServer.cpp +++ b/libresapi/src/api/ApiServer.cpp @@ -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), diff --git a/libresapi/src/api/TransfersHandler.cpp b/libresapi/src/api/TransfersHandler.cpp index 5b6f43789..ccc6310b2 100644 --- a/libresapi/src/api/TransfersHandler.cpp +++ b/libresapi/src/api/TransfersHandler.cpp @@ -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; diff --git a/libresapi/src/api/TransfersHandler.h b/libresapi/src/api/TransfersHandler.h index 0c53f2cd7..0caf6acc6 100644 --- a/libresapi/src/api/TransfersHandler.h +++ b/libresapi/src/api/TransfersHandler.h @@ -5,16 +5,18 @@ #include #include +#include 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;