From c30318f0c0bc5ab56f2765e39bac12dcbe5d12e0 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Wed, 16 Jul 2014 21:40:57 +0000 Subject: [PATCH] Added initial implementation of get statistic functions git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7455 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/gxs/rsgxsdataaccess.cc | 79 ++++++++++++++++++- libretroshare/src/gxs/rsgxsdataaccess.h | 21 ++++- libretroshare/src/gxs/rsgxsrequesttypes.h | 13 +++ libretroshare/src/retroshare/rstokenservice.h | 4 +- 4 files changed, 110 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index f3434b8f0..550dc723c 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -287,14 +287,25 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType, } -void RsGxsDataAccess::requestServiceStatistic(const uint32_t& token) +void RsGxsDataAccess::requestServiceStatistic(uint32_t& token) { + ServiceStatisticRequest* req = new ServiceStatisticRequest(); + generateToken(token); + + setReq(req, token, 0, RsTokReqOptions()); + storeRequest(req); } -void RsGxsDataAccess::requestGroupStatistic(const uint32_t& token, const RsGxsGroupId& grpId) +void RsGxsDataAccess::requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) { + GroupStatisticRequest* req = new GroupStatisticRequest(); + req->mGrpId = grpId; + generateToken(token); + + setReq(req, token, 0, RsTokReqOptions()); + storeRequest(req); } bool RsGxsDataAccess::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, @@ -797,7 +808,69 @@ void RsGxsDataAccess::processRequests() clearRequest(*cit); } - return; + return; +} + +bool RsGxsDataAccess::getGroupStatistic(const uint32_t &token, GxsGroupStatistic &grpStatistic) +{ + RsStackMutex stack(mDataMutex); + + GxsRequest* req = locked_retrieveRequest(token); + + if(req == NULL){ + + std::cerr << "RsGxsDataAccess::getGroupStatistic() Unable to retrieve grp stats" << std::endl; + return false; + }else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){ + + GroupStatisticRequest* gsreq = dynamic_cast(req); + + if(gsreq) + { + grpStatistic = gsreq->mGroupStatistic; + locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); + } + else{ + std::cerr << "RsGxsDataAccess::getGroupStatistic() Req found, failed caste" << std::endl; + return false; + } + }else{ + std::cerr << "RsGxsDataAccess::getGroupStatistic() Req not ready" << std::endl; + return false; + } + + return true; +} + +bool RsGxsDataAccess::getServiceStatistic(const uint32_t &token, GxsServiceStatistic &servStatistic) +{ + RsStackMutex stack(mDataMutex); + + GxsRequest* req = locked_retrieveRequest(token); + + if(req == NULL){ + + std::cerr << "RsGxsDataAccess::getServiceStatistic() Unable to retrieve grp stats" << std::endl; + return false; + }else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){ + + ServiceStatisticRequest* ssreq = dynamic_cast(req); + + if(ssreq) + { + servStatistic = ssreq->mServiceStatistic; + locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); + } + else{ + std::cerr << "RsGxsDataAccess::getServiceStatistic() Req found, failed caste" << std::endl; + return false; + } + }else{ + std::cerr << "RsGxsDataAccess::getServiceStatistic() Req not ready" << std::endl; + return false; + } + + return true; } diff --git a/libretroshare/src/gxs/rsgxsdataaccess.h b/libretroshare/src/gxs/rsgxsdataaccess.h index a78c1e3e4..7efa19516 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.h +++ b/libretroshare/src/gxs/rsgxsdataaccess.h @@ -104,14 +104,14 @@ public: * total size of groups * @param token */ - void requestServiceStatistic(const uint32_t& token); + void requestServiceStatistic(uint32_t& token); /*! * To request statistic on a group * @param token set to value to be redeemed to get statistic * @param grpId the id of the group */ - void requestGroupStatistic(const uint32_t& token, const RsGxsGroupId& grpId); + void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId); /* Poll */ @@ -152,11 +152,28 @@ public: public: + + /*! * This must be called periodically to progress requests */ void processRequests(); + /*! + * @param token + * @param grpStatistic + * @return false if token cannot be redeemed + */ + bool getGroupStatistic(const uint32_t &token, GxsGroupStatistic& grpStatistic); + + /*! + * @param token + * @param servStatistic + * @return false if token cannot be redeemed + */ + bool getServiceStatistic(const uint32_t &token, GxsServiceStatistic& servStatistic); + + /*! * Retrieve group list for a given token * @param token request token to be redeemed diff --git a/libretroshare/src/gxs/rsgxsrequesttypes.h b/libretroshare/src/gxs/rsgxsrequesttypes.h index 55a7f24f4..1c743fe61 100644 --- a/libretroshare/src/gxs/rsgxsrequesttypes.h +++ b/libretroshare/src/gxs/rsgxsrequesttypes.h @@ -97,6 +97,19 @@ public: NxsMsgDataResult mMsgData; }; +class ServiceStatisticRequest: public GxsRequest +{ +public: + GxsServiceStatistic mServiceStatistic; +}; + +struct GroupStatisticRequest: public GxsRequest +{ +public: + RsGxsGroupId mGrpId; + GxsGroupStatistic mGroupStatistic; +}; + class MsgRelatedInfoReq : public GxsRequest { diff --git a/libretroshare/src/retroshare/rstokenservice.h b/libretroshare/src/retroshare/rstokenservice.h index aea823dc9..1f22d6ffc 100644 --- a/libretroshare/src/retroshare/rstokenservice.h +++ b/libretroshare/src/retroshare/rstokenservice.h @@ -199,14 +199,14 @@ public: * total size of groups * @param token */ - virtual void requestServiceStatistic(const uint32_t& token) = 0; + 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(const uint32_t& token, const RsGxsGroupId& grpId) = 0; + virtual void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) = 0; /* Cancel Request */