diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 44ecccbd1..92af56f08 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -43,7 +43,7 @@ p3GxsTrans::~p3GxsTrans() } } -bool p3GxsTrans::getStatistics(GxsTransStatistics& stats) +bool p3GxsTrans::getDataStatistics(GxsTransStatistics& stats) { { RS_STACK_MUTEX(mDataMutex); @@ -1335,4 +1335,53 @@ bool p3GxsTrans::acceptNewMessage(const RsGxsMsgMetaData *msgMeta,uint32_t msg_s } +bool p3GxsTrans::getGroupStatistics(std::map& stats) +{ + uint32_t token1; + + RsTokReqOptions opts1; + opts1.mReqType = GXS_REQUEST_TYPE_GROUP_META; + if( !requestGroupInfo(token1, opts1) || waitToken(token1) != RsTokenService::COMPLETE ) + return false; + + std::list group_metas; + getGroupSummary(token1,group_metas); + + for(auto& group_meta:group_metas) + { + RsGxsTransGroupStatistics& stat(stats[group_meta.mGroupId]); + + uint32_t token2; + if(!RsGxsIfaceHelper::requestGroupStatistic(token2,group_meta.mGroupId) || waitToken(token2) != RsTokenService::COMPLETE) + continue; + + RsGenExchange::getGroupStatistic(token2,stat); + + stat.popularity = group_meta.mPop ; + stat.subscribed = IS_GROUP_SUBSCRIBED(group_meta.mSubscribeFlags) ; + stat.mGrpId = group_meta.mGroupId ; + + std::vector metas; + + uint32_t token3; + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_MSG_META; + + std::list groupIds; + groupIds.push_back(group_meta.mGroupId); + + if( !requestMsgInfo(token3, opts, groupIds) || waitToken(token3, std::chrono::seconds(5)) != RsTokenService::COMPLETE ) + continue; + + GxsMsgMetaMap metaMap; + if(!RsGenExchange::getMsgMeta(token3, metaMap) || metaMap.size() != 1) + continue; + + for(auto& meta: metaMap.begin()->second) + stat.addMessageMeta(group_meta.mGroupId,meta) ; + } + + return true; +} + diff --git a/libretroshare/src/gxstrans/p3gxstrans.h b/libretroshare/src/gxstrans/p3gxstrans.h index fd2b92ee8..307492281 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.h +++ b/libretroshare/src/gxstrans/p3gxstrans.h @@ -113,13 +113,21 @@ public: /*! * \brief getStatistics - * Gathers all sorts of statistics about the internals of p3GxsTrans, in order to display info about the running status, - * message transport, etc. + * Gathers all sorts of statistics about the data transported by p3GxsTrans, in order to display info about the running status, + * message transport, etc. This is a blocking call. Use it in a thread. * \param stats This structure contains all statistics information. * \return true is the call succeeds. */ - virtual bool getStatistics(GxsTransStatistics& stats); + virtual bool getDataStatistics(GxsTransStatistics& stats) override; + + /*! + * \brief getGroupStatistics + * Gathers statistics about GXS groups and messages used by GxsTrans to transport data. This is a blocking call. Use it in a thread. + * \param stats + * \return true if the data collection succeeds. + */ + virtual bool getGroupStatistics(std::map& stats) override; /** * Send an email to recipient, in the process author of the email is diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 418afc670..83f21a5e9 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -409,6 +409,14 @@ public: virtual bool subscribeToChannel( const RsGxsGroupId& channelId, bool subscribe ) = 0; + /** + * \brief Retrieve statistics about the channel service + * @jsonapi{development} + * \param[out] stat Statistics structure + * \return + */ + virtual bool getChannelServiceStatistics(GxsServiceStatistic& stat) =0; + /** * \brief Retrieve statistics about the given channel * @jsonapi{development} @@ -418,6 +426,7 @@ public: */ virtual bool getChannelStatistics(const RsGxsGroupId& channelId,GxsGroupStatistic& stat) =0; + /** * @brief Request remote channels search * @jsonapi{development} diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 4e368792e..5bff8e267 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -219,6 +219,14 @@ public: */ virtual bool getForumsSummaries(std::list& forums) = 0; + /** + * @brief returns statistics for the forum service + * @jsonapi{development} + * @param[out] stat statistics struct + * @return false if the call fails + */ + virtual bool getForumServiceStatistics(GxsServiceStatistic& stat) =0; + /** * @brief returns statistics about a particular forum * @jsonapi{development} @@ -228,6 +236,7 @@ public: */ virtual bool getForumStatistics(const RsGxsGroupId& forumId,GxsGroupStatistic& stat)=0; + /** * @brief Get forums information (description, thumbnail...). * Blocking API. diff --git a/libretroshare/src/retroshare/rsgxsifacehelper.h b/libretroshare/src/retroshare/rsgxsifacehelper.h index 2309f577d..d6610cc25 100644 --- a/libretroshare/src/retroshare/rsgxsifacehelper.h +++ b/libretroshare/src/retroshare/rsgxsifacehelper.h @@ -85,8 +85,7 @@ public: * @param groupIds the ids return for given request token * @return false if request token is invalid, check token status for error report */ - bool getGroupList(const uint32_t &token, - std::list &groupIds) + bool getGroupList(const uint32_t &token, std::list &groupIds) { return mGxs.getGroupList(token, groupIds); } @@ -119,8 +118,7 @@ public: * @param groupInfo the ids returned for given request token * @return false if request token is invalid, check token status for error report */ - bool getGroupSummary(const uint32_t &token, - std::list &groupInfo) + bool getGroupSummary(const uint32_t &token, std::list &groupInfo) { return mGxs.getGroupMeta(token, groupInfo); } @@ -130,8 +128,7 @@ public: * @param msgInfo the message metadata returned for given request token * @return false if request token is invalid, check token status for error report */ - bool getMsgSummary(const uint32_t &token, - GxsMsgMetaMap &msgInfo) + bool getMsgSummary(const uint32_t &token, GxsMsgMetaMap &msgInfo) { return mGxs.getMsgMeta(token, msgInfo); } @@ -358,7 +355,7 @@ public: { return mTokenService.requestStatus(token); } /// @see RsTokenService::requestServiceStatistic - void requestServiceStatistic(uint32_t& token) + bool requestServiceStatistic(uint32_t& token) { RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS; @@ -369,6 +366,7 @@ public: mActiveTokens[token]=TokenRequestType::SERVICE_STATISTICS; locked_dumpTokens(); + return true; } /// @see RsTokenService::requestGroupStatistic diff --git a/libretroshare/src/retroshare/rsgxstrans.h b/libretroshare/src/retroshare/rsgxstrans.h index e1b8d4d8f..8cbb514a6 100644 --- a/libretroshare/src/retroshare/rsgxstrans.h +++ b/libretroshare/src/retroshare/rsgxstrans.h @@ -70,10 +70,8 @@ enum class GxsTransSendStatus : uint8_t typedef uint64_t RsGxsTransId; -class RsGxsTransGroup +class RsGxsTransGroup: public RsGxsGenericGroupData { - public: - RsGroupMetaData mMeta; }; class RsGxsTransMsg @@ -103,7 +101,34 @@ struct RsGxsTransOutgoingRecord RsGxsGroupId group_id ; }; +class RsGxsTransGroupStatistics: public GxsGroupStatistic +{ +public: + RsGxsTransGroupStatistics() + { + last_publish_TS = 0; + popularity = 0; + subscribed = false; + } + + void addMessageMeta(const RsGxsGroupId& grp,const RsMsgMetaData& meta) + { + messages_metas[meta.mMsgId] = meta ; + last_publish_TS = std::max(last_publish_TS,meta.mPublishTs) ; + mGrpId = grp ; + } + + bool subscribed ; + int popularity ; + + rstime_t last_publish_TS; + + std::map messages_metas ; +}; + + /// RetroShare GxsTrans asyncronous redundant small mail trasport on top of GXS +/// class RsGxsTrans: public RsGxsIfaceHelper { public: @@ -120,10 +145,8 @@ public: virtual ~RsGxsTrans() {} - virtual bool getStatistics(GxsTransStatistics& stats)=0; - -// virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; -// virtual bool getPostData(const uint32_t &token, std::vector &posts) = 0; + virtual bool getDataStatistics(GxsTransStatistics& stats)=0; + virtual bool getGroupStatistics(std::map& stats) =0; }; extern RsGxsTrans *rsGxsTrans ; diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 347419082..066232d5b 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -167,6 +167,8 @@ public: virtual bool getBoardStatistics(const RsGxsGroupId& boardId,GxsGroupStatistic& stat) =0; + virtual bool getBoardsServiceStatistics(GxsServiceStatistic& stat) =0; + enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType }; RS_DEPRECATED_FOR(getBoardsInfo) diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 931098059..1e7538c57 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -1062,6 +1062,15 @@ bool p3GxsChannels::getChannelStatistics(const RsGxsGroupId& channelId,GxsGroupS return RsGenExchange::getGroupStatistic(token,stat); } +bool p3GxsChannels::getChannelServiceStatistics(GxsServiceStatistic& stat) +{ + uint32_t token; + if(!RsGxsIfaceHelper::requestServiceStatistic(token) || waitToken(token) != RsTokenService::COMPLETE) + return false; + + return RsGenExchange::getServiceStatistic(token,stat); +} + bool p3GxsChannels::getContentSummaries( const RsGxsGroupId& channelId, std::vector& summaries ) { diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index e529c227b..843023fb8 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -204,6 +204,9 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); /// Implementation of @see RsGxsChannels::getChannelStatistics bool getChannelStatistics(const RsGxsGroupId& channelId,GxsGroupStatistic& stat) override; + /// Iplementation of @see RsGxsChannels::getChannelServiceStatistics + bool getChannelServiceStatistics(GxsServiceStatistic& stat) override; + /// Implementation of @see RsGxsChannels::createChannelV2 bool createChannelV2( const std::string& name, const std::string& description, diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index c7f3fddcf..a37a62098 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -819,6 +819,15 @@ bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group) return true; } +bool p3GxsForums::getForumServiceStatistics(GxsServiceStatistic& stat) +{ + uint32_t token; + if(!RsGxsIfaceHelper::requestServiceStatistic(token) || waitToken(token) != RsTokenService::COMPLETE) + return false; + + return RsGenExchange::getServiceStatistic(token,stat); +} + bool p3GxsForums::getForumStatistics(const RsGxsGroupId& ForumId,GxsGroupStatistic& stat) { uint32_t token; diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index c95acf447..347714acb 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -97,6 +97,9 @@ public: /// Implementation of @see RsGxsForums::getForumStatistics bool getForumStatistics(const RsGxsGroupId& ForumId,GxsGroupStatistic& stat) override; + /// Implementation of @see RsGxsForums::getForumServiceStatistics + bool getForumServiceStatistics(GxsServiceStatistic& stat) override; + /// @see RsGxsForums::getForumMsgMetaData virtual bool getForumMsgMetaData(const RsGxsGroupId& forumId, std::vector& msg_metas) ; diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 299a990b1..db1de62ca 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -364,6 +364,16 @@ bool p3Posted::getBoardsSummaries(std::list& boards ) return getGroupSummary(token, boards); } +bool p3Posted::getBoardsServiceStatistics(GxsServiceStatistic& stat) +{ + uint32_t token; + if(!RsGxsIfaceHelper::requestServiceStatistic(token) || waitToken(token) != RsTokenService::COMPLETE) + return false; + + return RsGenExchange::getServiceStatistic(token,stat); +} + + bool p3Posted::getBoardStatistics(const RsGxsGroupId& boardId,GxsGroupStatistic& stat) { uint32_t token; diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index 3cc016ee7..b6f3ccee5 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -74,6 +74,8 @@ virtual void receiveHelperChanges(std::vector& changes) bool getBoardStatistics(const RsGxsGroupId& boardId,GxsGroupStatistic& stat) override; + bool getBoardsServiceStatistics(GxsServiceStatistic& stat) override; + bool editBoard(RsPostedGroup& board) override; bool createBoard(RsPostedGroup& board) override; diff --git a/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp b/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp index ef0cfa31d..5e7d75040 100644 --- a/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp +++ b/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp @@ -18,6 +18,7 @@ * * *******************************************************************************/ +#include "retroshare/rsposted.h" #include "PostedUserNotify.h" #include "gui/MainWindow.h" @@ -33,6 +34,10 @@ bool PostedUserNotify::hasSetting(QString *name, QString *group) return true; } +bool PostedUserNotify::getServiceStatistics(GxsServiceStatistic& stat) +{ + return rsPosted->getBoardsServiceStatistics(stat); +} QIcon PostedUserNotify::getIcon() { diff --git a/retroshare-gui/src/gui/Posted/PostedUserNotify.h b/retroshare-gui/src/gui/Posted/PostedUserNotify.h index 11552669a..8fd4ccdf9 100644 --- a/retroshare-gui/src/gui/Posted/PostedUserNotify.h +++ b/retroshare-gui/src/gui/Posted/PostedUserNotify.h @@ -31,6 +31,7 @@ public: PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); virtual bool hasSetting(QString *name, QString *group); + virtual bool getServiceStatistics(GxsServiceStatistic& stat) override; private: virtual QIcon getIcon(); diff --git a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp index b0aad6662..b6ebc89af 100644 --- a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp +++ b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp @@ -22,63 +22,50 @@ //#include "gui/gxs/RsGxsUpdateBroadcastBase.h" #include "retroshare/rsgxsifacehelper.h" +#include "util/qtthreadsutils.h" #define TOKEN_TYPE_STATISTICS 1 -GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) : - UserNotify(parent), TokenResponse() +GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) : UserNotify(parent) { mNewThreadMessageCount = 0; mNewChildMessageCount = 0; mCountChildMsgs = false; - - mInterface = ifaceImpl; - mTokenService = mInterface->getTokenService(); - mTokenQueue = new TokenQueue(mInterface->getTokenService(), this); - - //mBase = new RsGxsUpdateBroadcastBase(ifaceImpl); - //connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(updateIcon())); } -GxsUserNotify::~GxsUserNotify() -{ - if (mTokenQueue) { - delete(mTokenQueue); - } - //if (mBase) { - //delete(mBase); - //} -} +GxsUserNotify::~GxsUserNotify() {} void GxsUserNotify::startUpdate() { mNewThreadMessageCount = 0; mNewChildMessageCount = 0; - uint32_t token; - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS; + RsThread::async([this]() + { + // 1 - get message data from p3GxsForums - mTokenService->requestServiceStatistic(token,opts); - mTokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_STATISTICS); -} +#ifdef DEBUG_FORUMS + std::cerr << "Retrieving post data for post " << mThreadId << std::endl; +#endif -void GxsUserNotify::loadRequest(const TokenQueue *queue, const TokenRequest &req) -{ - if (queue == mTokenQueue) { - /* now switch on req */ - switch(req.mUserType) { - case TOKEN_TYPE_STATISTICS: - { - GxsServiceStatistic stats; - mInterface->getServiceStatistic(req.mToken, stats); + GxsServiceStatistic stats; + + if(!getServiceStatistics(stats)) + return; + + RsQThreadUtils::postToObject( [stats,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ mNewThreadMessageCount = stats.mNumThreadMsgsNew; mNewChildMessageCount = stats.mNumChildMsgsNew; update(); - } - break; - } - } + + }, this ); + + }); } + diff --git a/retroshare-gui/src/gui/gxs/GxsUserNotify.h b/retroshare-gui/src/gui/gxs/GxsUserNotify.h index c4dca9995..cc1cd3809 100644 --- a/retroshare-gui/src/gui/gxs/GxsUserNotify.h +++ b/retroshare-gui/src/gui/gxs/GxsUserNotify.h @@ -28,7 +28,7 @@ struct RsGxsIfaceHelper; class RsGxsUpdateBroadcastBase; -class GxsUserNotify : public UserNotify, public TokenResponse +class GxsUserNotify : public UserNotify { Q_OBJECT @@ -36,11 +36,9 @@ public: GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); virtual ~GxsUserNotify(); - /* TokenResponse */ - virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); - protected: virtual void startUpdate(); + virtual bool getServiceStatistics(GxsServiceStatistic& stat)=0; private: virtual unsigned int getNewCount() { return mCountChildMsgs ? (mNewThreadMessageCount + mNewChildMessageCount) : mNewThreadMessageCount; } @@ -49,9 +47,6 @@ protected: bool mCountChildMsgs; // Count new child messages? private: - RsGxsIfaceHelper *mInterface; - RsTokenService *mTokenService; - TokenQueue *mTokenQueue; RsGxsUpdateBroadcastBase *mBase; unsigned int mNewThreadMessageCount; unsigned int mNewChildMessageCount; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp index aa82953ed..3e5212476 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp @@ -18,6 +18,7 @@ * * *******************************************************************************/ +#include "retroshare/rsgxschannels.h" #include "GxsChannelUserNotify.h" #include "gui/MainWindow.h" @@ -34,6 +35,11 @@ bool GxsChannelUserNotify::hasSetting(QString *name, QString *group) return true; } +bool GxsChannelUserNotify::getServiceStatistics(GxsServiceStatistic& stat) +{ + return rsGxsChannels->getChannelServiceStatistics(stat); +} + QIcon GxsChannelUserNotify::getIcon() { return QIcon(":/icons/png/channel.png"); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h index d36b92bd7..d69848aba 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h @@ -31,6 +31,7 @@ public: GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); virtual bool hasSetting(QString *name, QString *group); + virtual bool getServiceStatistics(GxsServiceStatistic& stat) override; private: virtual QIcon getIcon(); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp index 8a910659a..8c07e2099 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp @@ -18,6 +18,7 @@ * * *******************************************************************************/ +#include "retroshare/rsgxsforums.h" #include "GxsForumUserNotify.h" #include "gui/MainWindow.h" @@ -34,6 +35,10 @@ bool GxsForumUserNotify::hasSetting(QString *name, QString *group) return true; } +bool GxsForumUserNotify::getServiceStatistics(GxsServiceStatistic& stat) +{ + return rsGxsForums->getForumServiceStatistics(stat); +} QIcon GxsForumUserNotify::getIcon() { diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h index 190f177e7..bc97550de 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h @@ -29,6 +29,7 @@ class GxsForumUserNotify : public GxsUserNotify public: GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); + virtual bool getServiceStatistics(GxsServiceStatistic& stat) override; virtual bool hasSetting(QString *name, QString *group); diff --git a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp index 733865559..10663a735 100644 --- a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp @@ -45,6 +45,7 @@ #include "util/QtVersion.h" #include "gui/common/UIStateHelper.h" #include "util/misc.h" +#include "util/qtthreadsutils.h" #include "gui/gxs/GxsIdLabel.h" #include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdTreeWidgetItem.h" @@ -85,8 +86,6 @@ GxsTransportStatistics::GxsTransportStatistics(QWidget *parent) mStateHelper = new UIStateHelper(this); mStateHelper->addWidget(GXSTRANS_GROUP_META, treeWidget); - mTransQueue = new TokenQueue(rsGxsTrans->getTokenService(), this); - m_bProcessSettings = false; mLastGroupReqTS = 0 ; @@ -154,7 +153,8 @@ void GxsTransportStatistics::updateDisplay(bool) std::cerr << "GxsTransportStatistics::updateDisplay()" << std::endl; #endif - requestGroupMeta(); + loadGroups(); + mLastGroupReqTS = now ; } @@ -201,7 +201,7 @@ void GxsTransportStatistics::updateContent() { RsGxsTrans::GxsTransStatistics transinfo ; - rsGxsTrans->getStatistics(transinfo) ; + rsGxsTrans->getDataStatistics(transinfo) ; // clear @@ -333,95 +333,8 @@ void GxsTransportStatistics::personDetails() dialog->show(); } -void GxsTransportStatistics::loadRequest(const TokenQueue *queue, const TokenRequest &req) -{ -#ifdef DEBUG_GXSTRANS_STATS - std::cerr << "GxsTransportStatistics::loadRequest() UserType: " << req.mUserType << std::endl; -#endif - - if (queue != mTransQueue) - { - std::cerr << "Wrong queue!" << std::endl; - return ; - } - - /* now switch on req */ - switch(req.mUserType) - { - case GXSTRANS_GROUP_META: loadGroupMeta(req.mToken); - break; - - case GXSTRANS_GROUP_STAT: loadGroupStat(req.mToken); - break; - - case GXSTRANS_MSG_META: loadMsgMeta(req.mToken); - break; - - default: - std::cerr << "GxsTransportStatistics::loadRequest() ERROR: INVALID TYPE"; - std::cerr << std::endl; - break; - } - - updateContent(); -} - -void GxsTransportStatistics::requestGroupMeta() -{ - mStateHelper->setLoading(GXSTRANS_GROUP_META, true); - -#ifdef DEBUG_GXSTRANS_STATS - std::cerr << "GxsTransportStatisticsWidget::requestGroupMeta()"; - std::cerr << std::endl; -#endif - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; - - uint32_t token; - mTransQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, GXSTRANS_GROUP_META); -} -void GxsTransportStatistics::requestGroupStat(const RsGxsGroupId &groupId) -{ - uint32_t token; - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_STATS; - - rsGxsTrans->getTokenService()->requestGroupStatistic(token, groupId,opts); - mTransQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, GXSTRANS_GROUP_STAT); -} -void GxsTransportStatistics::requestMsgMeta(const RsGxsGroupId& grpId) -{ - mStateHelper->setLoading(GXSTRANS_MSG_META, true); - -#ifdef DEBUG_GXSTRANS_STATS - std::cerr << "GxsTransportStatisticsWidget::requestGroupMeta()"; - std::cerr << std::endl; -#endif - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_MSG_META; - - std::list grouplist ; - grouplist.push_back(grpId) ; - - uint32_t token; - rsGxsTrans->getTokenService()->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grouplist); - mTransQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, GXSTRANS_MSG_META); -} - -void GxsTransportStatistics::loadGroupStat(const uint32_t &token) -{ - GxsGroupStatistic stats; - rsGxsTrans->getGroupStatistic(token, stats); - -#ifdef DEBUG_GXSTRANS_STATS - std::cerr << "Loading group stats: " << stats.mGrpId << ", num msgs=" << stats.mNumMsgs << ", total size=" << stats.mTotalSizeOfMsgs << std::endl; -#endif - dynamic_cast(mGroupStats[stats.mGrpId]) = stats ; -} - -void GxsTransportStatistics::loadGroupMeta(const uint32_t& token) +#ifdef TO_REMOVE +void GxsTransportStatistics::loadGroupMeta(const std::vector& groupInfo) { mStateHelper->setLoading(GXSTRANS_GROUP_META, false); @@ -430,22 +343,11 @@ void GxsTransportStatistics::loadGroupMeta(const uint32_t& token) std::cerr << std::endl; #endif - std::list groupInfo; - std::list::iterator vit; - - if (!rsGxsTrans->getGroupSummary(token,groupInfo)) - { - std::cerr << "GxsTransportStatistics::loadGroupMeta() Error getting GroupMeta"; - std::cerr << std::endl; - mStateHelper->setActive(GXSTRANS_GROUP_META, false); - return; - } - mStateHelper->setActive(GXSTRANS_GROUP_META, true); std::set existing_groups ; - for(vit = groupInfo.begin(); vit != groupInfo.end(); ++vit) + for(auto vit = groupInfo.begin(); vit != groupInfo.end(); ++vit) { existing_groups.insert(vit->mGroupId) ; @@ -454,8 +356,8 @@ void GxsTransportStatistics::loadGroupMeta(const uint32_t& token) std::cerr << "GxsTransportStatisticsWidget::loadGroupMeta() GroupId: " << vit->mGroupId << " Group: " << vit->mGroupName << std::endl; #endif - requestGroupStat(vit->mGroupId) ; - requestMsgMeta(vit->mGroupId) ; + loadGroupStats(vit->mGroupId) ; + loadMsgMetas(vit->mGroupId) ; RsGxsTransGroupStatistics& s(mGroupStats[vit->mGroupId]); s.popularity = vit->mPop ; @@ -472,17 +374,74 @@ void GxsTransportStatistics::loadGroupMeta(const uint32_t& token) ++it; } -void GxsTransportStatistics::loadMsgMeta(const uint32_t& token) +void GxsTransportStatistics::loadGroupStats(const RsGxsGroupId& groupId) { - mStateHelper->setLoading(GXSTRANS_MSG_META, false); +#ifdef DEBUG_GXSTRANS_STATS + std::cerr << "Loading group stats: " << stats.mGrpId << ", num msgs=" << stats.mNumMsgs << ", total size=" << stats.mTotalSizeOfMsgs << std::endl; +#endif - GxsMsgMetaMap m ; + RsThread::async([this]() + { + // 1 - get message data from p3GxsForums - if (!rsGxsTrans->getMsgSummary(token,m)) - return ; +#ifdef DEBUG_FORUMS + std::cerr << "Retrieving post data for post " << mThreadId << std::endl; +#endif + GxsGroupStatistic stats; + rsGxsTrans->getGroupStatistic(groupId,stats); - for(GxsMsgMetaMap::const_iterator it(m.begin());it!=m.end();++it) - for(uint32_t i=0;isecond.size();++i) - mGroupStats[it->first].addMessageMeta(it->first,it->second[i]) ; + RsQThreadUtils::postToObject( [stats,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ + + dynamic_cast(mGroupStats[stats.mGrpId]) = stats ; + + mStateHelper->setLoading(GXSTRANS_GROUP_STAT, false); + + }, this ); + + }); + +} +#endif + + +void GxsTransportStatistics::loadGroups() +{ + mStateHelper->setLoading(GXSTRANS_GROUP_META, true); + + RsThread::async([this]() + { + // 1 - get message data from p3GxsForums + +#ifdef DEBUG_FORUMS + std::cerr << "Retrieving post data for post " << mThreadId << std::endl; +#endif + std::map stats; + + if(!rsGxsTrans->getGroupStatistics(stats)) + { + RsErr() << "Cannot retrieve group statistics in GxsTransportStatistics" << std::endl; + return; + } + + RsQThreadUtils::postToObject( [stats,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ + + mGroupStats = stats; + + updateContent(); + + mStateHelper->setLoading(GXSTRANS_GROUP_META, false); + + }, this ); + + }); } + diff --git a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h index 2cf8c78b4..01a31e776 100644 --- a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h +++ b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h @@ -25,8 +25,8 @@ #include #include #include +#include -#include "util/TokenQueue.h" #include "RsAutoUpdatePage.h" #include "ui_GxsTransportStatistics.h" #include "gui/gxs/RsGxsUpdateBroadcastPage.h" @@ -35,32 +35,7 @@ class GxsTransportStatisticsWidget ; class UIStateHelper; -class RsGxsTransGroupStatistics: public GxsGroupStatistic -{ -public: - RsGxsTransGroupStatistics() - { - last_publish_TS = 0; - popularity = 0; - subscribed = false; - } - - void addMessageMeta(const RsGxsGroupId& grp,const RsMsgMetaData& meta) - { - messages_metas[meta.mMsgId] = meta ; - last_publish_TS = std::max(last_publish_TS,meta.mPublishTs) ; - mGrpId = grp ; - } - - bool subscribed ; - int popularity ; - - rstime_t last_publish_TS; - - std::map messages_metas ; -}; - -class GxsTransportStatistics: public MainPage, public TokenResponse, public Ui::GxsTransportStatistics +class GxsTransportStatistics: public MainPage, public Ui::GxsTransportStatistics { Q_OBJECT @@ -71,8 +46,6 @@ public: // Cache for peer names. static QString getPeerName(const RsPeerId& peer_id) ; - virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req) ; - void updateContent() ; private slots: @@ -82,19 +55,12 @@ private slots: private: void updateDisplay(bool complete) ; - void loadGroupMeta(const uint32_t& token); - void loadGroupStat(const uint32_t& token); - void loadMsgMeta(const uint32_t& token); - - void requestGroupMeta(); - void requestMsgMeta(const RsGxsGroupId& groupId); - void requestGroupStat(const RsGxsGroupId &groupId); + void loadGroups(); void processSettings(bool bLoad); bool m_bProcessSettings; GxsTransportStatisticsWidget *_tst_CW ; - TokenQueue *mTransQueue ; UIStateHelper *mStateHelper; uint32_t mLastGroupReqTS ;