mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-02 11:26:31 -05:00
Convert to RsTokenService::GxsRequestStatus
Indicate GxsRequest status with an enum instead of uint_* that make the code less readable and more prone to errors
This commit is contained in:
parent
b4d2ce82c1
commit
2f4b9b3e20
@ -2414,7 +2414,7 @@ void RsGenExchange::processRoutingClues()
|
|||||||
|
|
||||||
void RsGenExchange::processGroupDelete()
|
void RsGenExchange::processGroupDelete()
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGenMtx) ;
|
RS_STACK_MUTEX(mGenMtx);
|
||||||
|
|
||||||
// get keys for group delete publish
|
// get keys for group delete publish
|
||||||
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
||||||
@ -2435,7 +2435,8 @@ void RsGenExchange::processGroupDelete()
|
|||||||
for(; mit != toNotify.end(); ++mit)
|
for(; mit != toNotify.end(); ++mit)
|
||||||
{
|
{
|
||||||
GrpNote& note = mit->second;
|
GrpNote& note = mit->second;
|
||||||
uint8_t status = note.first ? RsTokenService::COMPLETE
|
RsTokenService::GxsRequestStatus status =
|
||||||
|
note.first ? RsTokenService::COMPLETE
|
||||||
: RsTokenService::FAILED;
|
: RsTokenService::FAILED;
|
||||||
|
|
||||||
mGrpNotify.insert(std::make_pair(mit->first, note.second));
|
mGrpNotify.insert(std::make_pair(mit->first, note.second));
|
||||||
@ -2744,7 +2745,8 @@ void RsGenExchange::publishGrps()
|
|||||||
for(; mit != toNotify.end(); ++mit)
|
for(; mit != toNotify.end(); ++mit)
|
||||||
{
|
{
|
||||||
GrpNote& note = mit->second;
|
GrpNote& note = mit->second;
|
||||||
uint8_t status = note.first ? RsTokenService::COMPLETE
|
RsTokenService::GxsRequestStatus status =
|
||||||
|
note.first ? RsTokenService::COMPLETE
|
||||||
: RsTokenService::FAILED;
|
: RsTokenService::FAILED;
|
||||||
|
|
||||||
mGrpNotify.insert(std::make_pair(mit->first, note.second));
|
mGrpNotify.insert(std::make_pair(mit->first, note.second));
|
||||||
@ -2781,7 +2783,8 @@ uint32_t RsGenExchange::generatePublicToken()
|
|||||||
return mDataAccess->generatePublicToken();
|
return mDataAccess->generatePublicToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGenExchange::updatePublicRequestStatus(const uint32_t &token, const uint32_t &status)
|
bool RsGenExchange::updatePublicRequestStatus(
|
||||||
|
uint32_t token, RsTokenService::GxsRequestStatus status )
|
||||||
{
|
{
|
||||||
return mDataAccess->updatePublicRequestStatus(token, status);
|
return mDataAccess->updatePublicRequestStatus(token, status);
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,8 @@ public:
|
|||||||
* @param status
|
* @param status
|
||||||
* @return false if token could not be found, true if token disposed of
|
* @return false if token could not be found, true if token disposed of
|
||||||
*/
|
*/
|
||||||
bool updatePublicRequestStatus(const uint32_t &token, const uint32_t &status);
|
bool updatePublicRequestStatus(
|
||||||
|
uint32_t token, RsTokenService::GxsRequestStatus status);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This gets rid of a publicly issued token
|
* This gets rid of a publicly issued token
|
||||||
|
@ -315,15 +315,15 @@ void RsGxsDataAccess::storeRequest(GxsRequest* req)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RsGxsDataAccess::requestStatus(uint32_t token)
|
RsTokenService::GxsRequestStatus RsGxsDataAccess::requestStatus(uint32_t token)
|
||||||
{
|
{
|
||||||
uint32_t status;
|
RsTokenService::GxsRequestStatus status;
|
||||||
uint32_t reqtype;
|
uint32_t reqtype;
|
||||||
uint32_t anstype;
|
uint32_t anstype;
|
||||||
time_t ts;
|
time_t ts;
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDataMutex);
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
|
|
||||||
// first check public tokens
|
// first check public tokens
|
||||||
if(mPublicToken.find(token) != mPublicToken.end())
|
if(mPublicToken.find(token) != mPublicToken.end())
|
||||||
@ -1761,11 +1761,11 @@ void RsGxsDataAccess::filterGrpList(std::list<RsGxsGroupId> &grpIds, const RsTok
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RsGxsDataAccess::checkRequestStatus(const uint32_t& token,
|
bool RsGxsDataAccess::checkRequestStatus(
|
||||||
uint32_t& status, uint32_t& reqtype, uint32_t& anstype, time_t& ts)
|
uint32_t token, GxsRequestStatus& status, uint32_t& reqtype,
|
||||||
|
uint32_t& anstype, time_t& ts )
|
||||||
{
|
{
|
||||||
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
RsStackMutex stack(mDataMutex);
|
|
||||||
|
|
||||||
GxsRequest* req = locked_retrieveRequest(token);
|
GxsRequest* req = locked_retrieveRequest(token);
|
||||||
|
|
||||||
@ -1822,28 +1822,24 @@ void RsGxsDataAccess::tokenList(std::list<uint32_t>& tokens)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGxsDataAccess::locked_updateRequestStatus(const uint32_t& token,
|
bool RsGxsDataAccess::locked_updateRequestStatus(
|
||||||
const uint32_t& status)
|
uint32_t token, RsTokenService::GxsRequestStatus status )
|
||||||
{
|
{
|
||||||
|
|
||||||
GxsRequest* req = locked_retrieveRequest(token);
|
GxsRequest* req = locked_retrieveRequest(token);
|
||||||
|
|
||||||
if(req)
|
if(req) req->status = status;
|
||||||
req->status = status;
|
else return false;
|
||||||
else
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RsGxsDataAccess::generatePublicToken()
|
uint32_t RsGxsDataAccess::generatePublicToken()
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
generateToken(token);
|
generateToken(token);
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDataMutex);
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
mPublicToken[token] = RsTokenService::PENDING;
|
mPublicToken[token] = RsTokenService::PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1852,40 +1848,26 @@ uint32_t RsGxsDataAccess::generatePublicToken()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool RsGxsDataAccess::updatePublicRequestStatus(const uint32_t& token,
|
bool RsGxsDataAccess::updatePublicRequestStatus(
|
||||||
const uint32_t& status)
|
uint32_t token, RsTokenService::GxsRequestStatus status )
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDataMutex);
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
std::map<uint32_t, uint32_t>::iterator mit = mPublicToken.find(token);
|
std::map<uint32_t, RsTokenService::GxsRequestStatus>::iterator mit =
|
||||||
|
mPublicToken.find(token);
|
||||||
if(mit != mPublicToken.end())
|
if(mit != mPublicToken.end()) mit->second = status;
|
||||||
{
|
else return false;
|
||||||
mit->second = status;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool RsGxsDataAccess::disposeOfPublicToken(const uint32_t& token)
|
bool RsGxsDataAccess::disposeOfPublicToken(uint32_t token)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDataMutex);
|
RS_STACK_MUTEX(mDataMutex);
|
||||||
std::map<uint32_t, uint32_t>::iterator mit = mPublicToken.find(token);
|
std::map<uint32_t, RsTokenService::GxsRequestStatus>::iterator mit =
|
||||||
|
mPublicToken.find(token);
|
||||||
if(mit != mPublicToken.end())
|
if(mit != mPublicToken.end()) mPublicToken.erase(mit);
|
||||||
{
|
else return false;
|
||||||
mPublicToken.erase(mit);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ public:
|
|||||||
* deprecated and should be removed as soon as possible as it is cause of
|
* deprecated and should be removed as soon as possible as it is cause of
|
||||||
* many confusions, instead use const RsTokReqOptions::mReqType &opts to
|
* many confusions, instead use const RsTokReqOptions::mReqType &opts to
|
||||||
* specify the kind of data you are interested in.
|
* specify the kind of data you are interested in.
|
||||||
|
* Most of the methods use const uint32_t &token as param type change it to
|
||||||
|
* uint32_t
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -121,7 +123,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/* Poll */
|
/* Poll */
|
||||||
uint32_t requestStatus(const uint32_t token);
|
GxsRequestStatus requestStatus(const uint32_t token);
|
||||||
|
|
||||||
/* Cancel Request */
|
/* Cancel Request */
|
||||||
bool cancelRequest(const uint32_t &token);
|
bool cancelRequest(const uint32_t &token);
|
||||||
@ -296,7 +298,7 @@ private:
|
|||||||
* @param status the status to set
|
* @param status the status to set
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool locked_updateRequestStatus(const uint32_t &token, const uint32_t &status);
|
bool locked_updateRequestStatus(uint32_t token, GxsRequestStatus status);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Use to query the status and other values of a given token
|
* Use to query the status and other values of a given token
|
||||||
@ -307,7 +309,8 @@ private:
|
|||||||
* @param ts time stamp
|
* @param ts time stamp
|
||||||
* @return false if token does not exist, true otherwise
|
* @return false if token does not exist, true otherwise
|
||||||
*/
|
*/
|
||||||
bool checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &reqtype, uint32_t &anstype, time_t &ts);
|
bool checkRequestStatus( uint32_t token, GxsRequestStatus &status,
|
||||||
|
uint32_t &reqtype, uint32_t &anstype, time_t &ts);
|
||||||
|
|
||||||
// special ones for testing (not in final design)
|
// special ones for testing (not in final design)
|
||||||
/*!
|
/*!
|
||||||
@ -337,14 +340,14 @@ public:
|
|||||||
* @param status
|
* @param status
|
||||||
* @return false if token could not be found, true if token disposed of
|
* @return false if token could not be found, true if token disposed of
|
||||||
*/
|
*/
|
||||||
bool updatePublicRequestStatus(const uint32_t &token, const uint32_t &status);
|
bool updatePublicRequestStatus(uint32_t token, GxsRequestStatus status);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This gets rid of a publicly issued token
|
* This gets rid of a publicly issued token
|
||||||
* @param token
|
* @param token
|
||||||
* @return false if token could not found, true if token disposed of
|
* @return false if token could not found, true if token disposed of
|
||||||
*/
|
*/
|
||||||
bool disposeOfPublicToken(const uint32_t &token);
|
bool disposeOfPublicToken(uint32_t token);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -484,7 +487,7 @@ private:
|
|||||||
RsMutex mDataMutex; /* protecting below */
|
RsMutex mDataMutex; /* protecting below */
|
||||||
|
|
||||||
uint32_t mNextToken;
|
uint32_t mNextToken;
|
||||||
std::map<uint32_t, uint32_t> mPublicToken;
|
std::map<uint32_t, GxsRequestStatus> mPublicToken;
|
||||||
std::map<uint32_t, GxsRequest*> mRequests;
|
std::map<uint32_t, GxsRequest*> mRequests;
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,9 @@
|
|||||||
|
|
||||||
struct GxsRequest
|
struct GxsRequest
|
||||||
{
|
{
|
||||||
GxsRequest() : token(0), reqTime(0), ansType(0), reqType(0), status(0) {}
|
GxsRequest() :
|
||||||
|
token(0), reqTime(0), ansType(0), reqType(0),
|
||||||
|
status(RsTokenService::FAILED) {}
|
||||||
virtual ~GxsRequest() {}
|
virtual ~GxsRequest() {}
|
||||||
|
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
@ -42,7 +44,7 @@ struct GxsRequest
|
|||||||
uint32_t reqType;
|
uint32_t reqType;
|
||||||
RsTokReqOptions Options;
|
RsTokReqOptions Options;
|
||||||
|
|
||||||
uint32_t status;
|
RsTokenService::GxsRequestStatus status;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GroupMetaReq : public GxsRequest
|
class GroupMetaReq : public GxsRequest
|
||||||
|
@ -199,7 +199,7 @@ public:
|
|||||||
* @param token value of token to check status for
|
* @param token value of token to check status for
|
||||||
* @return the current status of request
|
* @return the current status of request
|
||||||
*/
|
*/
|
||||||
virtual uint32_t requestStatus(const uint32_t token) = 0;
|
virtual GxsRequestStatus requestStatus(const uint32_t token) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This request statistics on amount of data held
|
* This request statistics on amount of data held
|
||||||
|
@ -556,24 +556,22 @@ void p3GxsCommentService::load_PendingVoteParent(const uint32_t &token)
|
|||||||
pit = mPendingVotes.find(parentId);
|
pit = mPendingVotes.find(parentId);
|
||||||
if (pit == mPendingVotes.end())
|
if (pit == mPendingVotes.end())
|
||||||
{
|
{
|
||||||
std::cerr << "p3GxsCommentService::load_PendingVoteParent() ERROR Finding Pending Vote";
|
std::cerr << __PRETTY_FUNCTION__
|
||||||
std::cerr << std::endl;
|
<< " ERROR Finding Pending Vote" << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGxsVote vote = pit->second.mVote;
|
RsGxsVote vote = pit->second.mVote;
|
||||||
if (meta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
if (meta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
||||||
{
|
{
|
||||||
std::cerr << "p3GxsCommentService::load_PendingVoteParent() ERROR Already Voted";
|
std::cerr << __PRETTY_FUNCTION__ << " ERROR Already Voted"
|
||||||
std::cerr << std::endl;
|
<< std::endl
|
||||||
std::cerr << "mGroupId: " << meta.mGroupId;
|
<< "mGroupId: " << meta.mGroupId << std::endl
|
||||||
std::cerr << std::endl;
|
<< "mMsgId: " << meta.mMsgId << std::endl;
|
||||||
std::cerr << "mMsgId: " << meta.mMsgId;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
pit->second.mStatus = VoteHolder::VOTE_ERROR;
|
pit->second.mStatus = VoteHolder::VOTE_ERROR;
|
||||||
uint32_t status = RsTokenService::FAILED;
|
mExchange->updatePublicRequestStatus(
|
||||||
mExchange->updatePublicRequestStatus(pit->second.mReqToken, status);
|
pit->second.mReqToken, RsTokenService::FAILED );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,8 +615,8 @@ void p3GxsCommentService::completeInternalVote(uint32_t &token)
|
|||||||
{
|
{
|
||||||
if (it->second.mVoteToken == token)
|
if (it->second.mVoteToken == token)
|
||||||
{
|
{
|
||||||
|
RsTokenService::GxsRequestStatus status =
|
||||||
uint32_t status = mExchange->getTokenService()->requestStatus(token);
|
mExchange->getTokenService()->requestStatus(token);
|
||||||
mExchange->updatePublicRequestStatus(it->second.mReqToken, status);
|
mExchange->updatePublicRequestStatus(it->second.mReqToken, status);
|
||||||
|
|
||||||
#ifdef DEBUG_GXSCOMMON
|
#ifdef DEBUG_GXSCOMMON
|
||||||
|
Loading…
Reference in New Issue
Block a user