diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 2da84d2b4..1eb8752fd 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -34,7 +34,7 @@ bool operator<(const std::pair& p1,const std::pair& p2) { - return p1.second->priority <= p2.second->priority ; // <= so that new elements with same priority are inserted before + return p1.second->Options.mPriority <= p2.second->Options.mPriority ; // <= so that new elements with same priority are inserted before } @@ -47,9 +47,7 @@ RsGxsDataAccess::~RsGxsDataAccess() for(auto& it:mRequestQueue) delete it.second; } -bool RsGxsDataAccess::requestGroupInfo( - uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, - const std::list &groupIds ) +bool RsGxsDataAccess::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds ) { if(groupIds.empty()) { @@ -145,8 +143,7 @@ void RsGxsDataAccess::generateToken(uint32_t &token) } -bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType, - const RsTokReqOptions &opts, const GxsMsgReq &msgIds) +bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq &msgIds) { GxsRequest* req = NULL; @@ -207,8 +204,7 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType, return true; } -bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType, - const RsTokReqOptions &opts, const std::list& grpIds) +bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list& grpIds) { GxsRequest* req = NULL; uint32_t reqType = opts.mReqType; @@ -262,33 +258,40 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType, } -void RsGxsDataAccess::requestServiceStatistic(uint32_t& token) +void RsGxsDataAccess::requestServiceStatistic(uint32_t& token,const RsTokReqOptions& opts) { ServiceStatisticRequest* req = new ServiceStatisticRequest(); generateToken(token); - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS; + if(opts.mReqType != GXS_REQUEST_TYPE_SERVICE_STATS) + { + RsErr() << "Expected opts.mReqType to be GXS_REQUEST_TYPE_SERVICE_STATS requestServiceStatistic()" << std::endl; + return; + } + setReq(req, token, 0, opts); storeRequest(req); } -void RsGxsDataAccess::requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) +void RsGxsDataAccess::requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId,const RsTokReqOptions& opts) { GroupStatisticRequest* req = new GroupStatisticRequest(); req->mGrpId = grpId; + if(opts.mReqType != GXS_REQUEST_TYPE_GROUP_STATS) + { + RsErr() << "Expected opts.mReqType to be GXS_REQUEST_TYPE_SERVICE_STATS requestServiceStatistic()" << std::endl; + return; + } + generateToken(token); - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_STATS; - setReq(req, token, 0, opts); + setReq(req, token,0, opts); storeRequest(req); } -bool RsGxsDataAccess::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, - const std::vector &msgIds) +bool RsGxsDataAccess::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector &msgIds) { MsgRelatedInfoReq* req = new MsgRelatedInfoReq(); @@ -320,9 +323,9 @@ void RsGxsDataAccess::storeRequest(GxsRequest* req) mPublicToken[req->token] = PENDING; #ifdef DATA_DEBUG - std::cerr << "Stored request token=" << req->token << " priority = " << static_cast(req->priority) << " Current request Queue is:" ; + std::cerr << "Stored request token=" << req->token << " priority = " << static_cast(req->Options.mPriority) << " Current request Queue is:" ; for(auto it(mRequestQueue.begin());it!=mRequestQueue.end();++it) - std::cerr << it->first << " (p=" << static_cast(req->priority) << ") "; + std::cerr << it->first << " (p=" << static_cast(req->Options.mPriority) << ") "; std::cerr << std::endl; std::cerr << "Completed requests waiting for client: " << mCompletedRequests.size() << std::endl; #endif diff --git a/libretroshare/src/gxs/rsgxsdataaccess.h b/libretroshare/src/gxs/rsgxsdataaccess.h index 958d53b4f..538880a79 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.h +++ b/libretroshare/src/gxs/rsgxsdataaccess.h @@ -59,7 +59,7 @@ public: * @param groupIds group id to request info for * @return */ - bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds); + bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) override; /*! * Use this to request all group related info @@ -68,7 +68,7 @@ public: * @param opts Additional option that affect outcome of request. Please see specific services, for valid values * @return */ - bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts); + bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts) override; /*! * Use this to get msg information (id, meta, or data), store token value to poll for request completion @@ -78,7 +78,7 @@ public: * @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs * @return true if request successful false otherwise */ - bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq& msgIds); + bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq& msgIds) override; /*! * Use this to get message information (id, meta, or data), store token value to poll for request completion @@ -89,7 +89,7 @@ public: * all messages for all groups are retrieved * @return true if request successful false otherwise */ - bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list& grpIds); + bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list& grpIds) override; /*! * For requesting msgs related to a given msg id within a group @@ -99,7 +99,7 @@ public: * @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs * @return true if request successful false otherwise */ - bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector &msgIds); + bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector &msgIds) override; /*! * This request statistics on amount of data held @@ -110,16 +110,17 @@ public: * total size of messages * total size of groups * @param token + * @param opts Additional option that affect outcome of request. Please see specific services, for valid values */ - void requestServiceStatistic(uint32_t& token); + void requestServiceStatistic(uint32_t& token, const RsTokReqOptions &opts) override; /*! * To request statistic on a group * @param token set to value to be redeemed to get statistic * @param grpId the id of the group + * @param opts Additional option that affect outcome of request. Please see specific services, for valid values */ - void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId); - + void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId, const RsTokReqOptions &opts) override; /* Poll */ GxsRequestStatus requestStatus(const uint32_t token); diff --git a/libretroshare/src/gxs/rsgxsrequesttypes.cc b/libretroshare/src/gxs/rsgxsrequesttypes.cc index be810d020..6c3925974 100644 --- a/libretroshare/src/gxs/rsgxsrequesttypes.cc +++ b/libretroshare/src/gxs/rsgxsrequesttypes.cc @@ -31,10 +31,15 @@ std::ostream& operator<<(std::ostream& o,const GxsRequest& g) std::ostream& GroupMetaReq::print(std::ostream& o) const { - o << "[Request type=GroupMeta groupIds (size=" << mGroupIds.size() << "): " << *mGroupIds.begin() ; + o << "[Request type=GroupMeta groupIds (size=" << mGroupIds.size() << "): " ; - if(mGroupIds.size() > 1) - o << " ..." ; + if(!mGroupIds.empty()) + { + o << *mGroupIds.begin() ; + + if(mGroupIds.size() > 1) + o << " ..." ; + } o << "]" ; @@ -52,10 +57,15 @@ std::ostream& GroupSerializedDataReq::print(std::ostream& o) const std::ostream& GroupDataReq::print(std::ostream& o) const { - o << "[Request type=GroupDataReq groupIds (size=" << mGroupIds.size() << "): " << *mGroupIds.begin() ; + o << "[Request type=GroupDataReq groupIds (size=" << mGroupIds.size() << "): " ; - if(mGroupIds.size() > 1) - o << " ..." ; + if(!mGroupIds.empty()) + { + o << *mGroupIds.begin() ; + + if(mGroupIds.size() > 1) + o << " ..." ; + } o << "]" ; @@ -69,10 +79,15 @@ std::ostream& MsgIdReq::print(std::ostream& o) const std::ostream& MsgMetaReq::print(std::ostream& o) const { - o << "[Request type=MsgMetaReq groups (size=" << mMsgIds.size() << "): " << mMsgIds.begin()->first << " (" << mMsgIds.begin()->second.size() << " messages)"; + o << "[Request type=MsgMetaReq groups (size=" << mMsgIds.size() << "): " ; - if(mMsgIds.size() > 1) - o << " ..." ; + if(!mMsgIds.empty()) + { + o << mMsgIds.begin()->first << " (" << mMsgIds.begin()->second.size() << " messages)"; + + if(mMsgIds.size() > 1) + o << " ..." ; + } o << "]" ; @@ -81,10 +96,15 @@ std::ostream& MsgMetaReq::print(std::ostream& o) const std::ostream& MsgDataReq::print(std::ostream& o) const { - o << "[Request type=MsgDataReq groups (size=" << mMsgIds.size() << "): " << mMsgIds.begin()->first << " (" << mMsgIds.begin()->second.size() << " messages)"; + o << "[Request type=MsgDataReq groups (size=" << mMsgIds.size() << "): " ; - if(mMsgIds.size() > 1) - o << " ..." ; + if(!mMsgIds.empty()) + { + o << mMsgIds.begin()->first << " (" << mMsgIds.begin()->second.size() << " messages)"; + + if(mMsgIds.size() > 1) + o << " ..." ; + } o << "]" ; @@ -93,10 +113,15 @@ std::ostream& MsgDataReq::print(std::ostream& o) const std::ostream& MsgRelatedInfoReq::print(std::ostream& o) const { - o << "[Request type=MsgRelatedInfo msgIds (size=" << mMsgIds.size() << "): " << mMsgIds.begin()->first ; + o << "[Request type=MsgRelatedInfo msgIds (size=" << mMsgIds.size() << "): " ; - if(mMsgIds.size() > 1) - o << " ..." ; + if(!mMsgIds.empty()) + { + o << mMsgIds.begin()->first ; + + if(mMsgIds.size() > 1) + o << " ..." ; + } o << "]" ; @@ -105,7 +130,7 @@ std::ostream& MsgRelatedInfoReq::print(std::ostream& o) const std::ostream& GroupSetFlagReq::print(std::ostream& o) const { - return o << "[Request type=GroupFlagSet" << "]" ; + return o << "[Request type=GroupFlagSet grpId=" << grpId << "]" ; } @@ -117,7 +142,7 @@ std::ostream& ServiceStatisticRequest::print(std::ostream& o) const std::ostream& GroupStatisticRequest::print(std::ostream& o) const { - return o << "[Request type=GroupStatistics" << "]" ; + return o << "[Request type=GroupStatistics grpId=" << mGrpId << "]" ; } GroupMetaReq::~GroupMetaReq() diff --git a/libretroshare/src/gxs/rsgxsrequesttypes.h b/libretroshare/src/gxs/rsgxsrequesttypes.h index 1a02b07da..1fe6c7f9d 100644 --- a/libretroshare/src/gxs/rsgxsrequesttypes.h +++ b/libretroshare/src/gxs/rsgxsrequesttypes.h @@ -26,18 +26,10 @@ #include "gxs/rsgds.h" #include "util/rsdeprecate.h" -enum class GxsRequestPriority { - VERY_HIGH = 0x00, - HIGH = 0x01, - NORMAL = 0x02, - LOW = 0x03, - VERY_LOW = 0x04, -}; - struct GxsRequest { GxsRequest() : - token(0), reqTime(0), ansType(0), reqType(0),priority(GxsRequestPriority::NORMAL), + token(0), reqTime(0), ansType(0), reqType(0), status(RsTokenService::FAILED) {} virtual ~GxsRequest() {} @@ -46,7 +38,6 @@ struct GxsRequest RS_DEPRECATED uint32_t ansType; /// G10h4ck: This is of no use. csoler: it's made available to the clients. uint32_t reqType; - GxsRequestPriority priority; RsTokReqOptions Options; RsTokenService::GxsRequestStatus status; diff --git a/libretroshare/src/retroshare/rsgxsifacehelper.h b/libretroshare/src/retroshare/rsgxsifacehelper.h index 422261a02..2309f577d 100644 --- a/libretroshare/src/retroshare/rsgxsifacehelper.h +++ b/libretroshare/src/retroshare/rsgxsifacehelper.h @@ -360,7 +360,10 @@ public: /// @see RsTokenService::requestServiceStatistic void requestServiceStatistic(uint32_t& token) { - mTokenService.requestServiceStatistic(token); + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS; + + mTokenService.requestServiceStatistic(token,opts); RS_STACK_MUTEX(mMtx); mActiveTokens[token]=TokenRequestType::SERVICE_STATISTICS; @@ -371,7 +374,10 @@ public: /// @see RsTokenService::requestGroupStatistic bool requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) { - mTokenService.requestGroupStatistic(token, grpId); + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_STATS; + + mTokenService.requestGroupStatistic(token, grpId,opts); RS_STACK_MUTEX(mMtx); mActiveTokens[token]=TokenRequestType::GROUP_STATISTICS; diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 60111d0cc..5d3942d7f 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -45,6 +45,13 @@ struct RsMsgMetaData; typedef std::map > MsgMetaResult; +enum class GxsRequestPriority { + VERY_HIGH = 0x00, + HIGH = 0x01, + NORMAL = 0x02, + LOW = 0x03, + VERY_LOW = 0x04, +}; class RsGxsGrpMetaData; class RsGxsMsgMetaData; diff --git a/libretroshare/src/retroshare/rstokenservice.h b/libretroshare/src/retroshare/rstokenservice.h index 7f801927f..a0fbd7258 100644 --- a/libretroshare/src/retroshare/rstokenservice.h +++ b/libretroshare/src/retroshare/rstokenservice.h @@ -80,7 +80,7 @@ struct RsTokReqOptions { RsTokReqOptions() : mOptions(0), mStatusFilter(0), mStatusMask(0), mMsgFlagMask(0), mMsgFlagFilter(0), mReqType(0), mSubscribeFilter(0), - mSubscribeMask(0), mBefore(0), mAfter(0) {} + mSubscribeMask(0), mBefore(0), mAfter(0),mPriority(GxsRequestPriority::NORMAL) {} /** * Can be one or multiple RS_TOKREQOPT_* @@ -107,6 +107,8 @@ struct RsTokReqOptions // Time range... again applied after Options. rstime_t mBefore; rstime_t mAfter; + + GxsRequestPriority mPriority; }; /*! @@ -181,6 +183,25 @@ public: */ virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector& msgIds) = 0; + /*! + * This request statistics on amount of data held + * number of groups + * number of groups subscribed + * number of messages + * size of db store + * total size of messages + * total size of groups + * @param token + */ + virtual void requestServiceStatistic(uint32_t& token, const RsTokReqOptions &opts) = 0; + + /*! + * To request statistic on a group + * @param token set to value to be redeemed to get statistic + * @param grpId the id of the group + */ + virtual void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId, const RsTokReqOptions &opts) = 0; + /* Poll */ @@ -194,25 +215,6 @@ public: */ virtual GxsRequestStatus requestStatus(const uint32_t token) = 0; - /*! - * This request statistics on amount of data held - * number of groups - * number of groups subscribed - * number of messages - * size of db store - * total size of messages - * total size of groups - * @param token - */ - virtual void requestServiceStatistic(uint32_t& token) = 0; - - /*! - * To request statistic on a group - * @param token set to value to be redeemed to get statistic - * @param grpId the id of the group - */ - virtual void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) = 0; - /*! * @brief Cancel Request * If this function returns false, it may be that the request has completed diff --git a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp index bca319e9a..b0aad6662 100644 --- a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp +++ b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp @@ -56,7 +56,10 @@ void GxsUserNotify::startUpdate() mNewChildMessageCount = 0; uint32_t token; - mTokenService->requestServiceStatistic(token); + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS; + + mTokenService->requestServiceStatistic(token,opts); mTokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_STATISTICS); } diff --git a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp index cde8c74da..733865559 100644 --- a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp @@ -384,7 +384,10 @@ void GxsTransportStatistics::requestGroupMeta() void GxsTransportStatistics::requestGroupStat(const RsGxsGroupId &groupId) { uint32_t token; - rsGxsTrans->getTokenService()->requestGroupStatistic(token, groupId); + 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)