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:
Gioacchino Mazzurco 2018-06-24 23:24:52 +02:00
parent b4d2ce82c1
commit 2f4b9b3e20
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
7 changed files with 63 additions and 74 deletions

View File

@ -2414,7 +2414,7 @@ void RsGenExchange::processRoutingClues()
void RsGenExchange::processGroupDelete()
{
RS_STACK_MUTEX(mGenMtx) ;
RS_STACK_MUTEX(mGenMtx);
// get keys for group delete publish
typedef std::pair<bool, RsGxsGroupId> GrpNote;
@ -2435,7 +2435,8 @@ void RsGenExchange::processGroupDelete()
for(; mit != toNotify.end(); ++mit)
{
GrpNote& note = mit->second;
uint8_t status = note.first ? RsTokenService::COMPLETE
RsTokenService::GxsRequestStatus status =
note.first ? RsTokenService::COMPLETE
: RsTokenService::FAILED;
mGrpNotify.insert(std::make_pair(mit->first, note.second));
@ -2744,7 +2745,8 @@ void RsGenExchange::publishGrps()
for(; mit != toNotify.end(); ++mit)
{
GrpNote& note = mit->second;
uint8_t status = note.first ? RsTokenService::COMPLETE
RsTokenService::GxsRequestStatus status =
note.first ? RsTokenService::COMPLETE
: RsTokenService::FAILED;
mGrpNotify.insert(std::make_pair(mit->first, note.second));
@ -2781,7 +2783,8 @@ uint32_t RsGenExchange::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);
}

View File

@ -468,7 +468,8 @@ public:
* @param status
* @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

View File

@ -315,15 +315,15 @@ void RsGxsDataAccess::storeRequest(GxsRequest* req)
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 anstype;
time_t ts;
{
RsStackMutex stack(mDataMutex);
RS_STACK_MUTEX(mDataMutex);
// first check public tokens
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,
uint32_t& status, uint32_t& reqtype, uint32_t& anstype, time_t& ts)
bool RsGxsDataAccess::checkRequestStatus(
uint32_t token, GxsRequestStatus& status, uint32_t& reqtype,
uint32_t& anstype, time_t& ts )
{
RsStackMutex stack(mDataMutex);
RS_STACK_MUTEX(mDataMutex);
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,
const uint32_t& status)
bool RsGxsDataAccess::locked_updateRequestStatus(
uint32_t token, RsTokenService::GxsRequestStatus status )
{
GxsRequest* req = locked_retrieveRequest(token);
if(req)
req->status = status;
else
return false;
if(req) req->status = status;
else return false;
return true;
}
uint32_t RsGxsDataAccess::generatePublicToken()
{
uint32_t token;
generateToken(token);
{
RsStackMutex stack(mDataMutex);
RS_STACK_MUTEX(mDataMutex);
mPublicToken[token] = RsTokenService::PENDING;
}
@ -1852,40 +1848,26 @@ uint32_t RsGxsDataAccess::generatePublicToken()
bool RsGxsDataAccess::updatePublicRequestStatus(const uint32_t& token,
const uint32_t& status)
bool RsGxsDataAccess::updatePublicRequestStatus(
uint32_t token, RsTokenService::GxsRequestStatus status )
{
RsStackMutex stack(mDataMutex);
std::map<uint32_t, uint32_t>::iterator mit = mPublicToken.find(token);
if(mit != mPublicToken.end())
{
mit->second = status;
}
else
{
return false;
}
RS_STACK_MUTEX(mDataMutex);
std::map<uint32_t, RsTokenService::GxsRequestStatus>::iterator mit =
mPublicToken.find(token);
if(mit != mPublicToken.end()) mit->second = status;
else return false;
return true;
}
bool RsGxsDataAccess::disposeOfPublicToken(const uint32_t& token)
bool RsGxsDataAccess::disposeOfPublicToken(uint32_t token)
{
RsStackMutex stack(mDataMutex);
std::map<uint32_t, uint32_t>::iterator mit = mPublicToken.find(token);
if(mit != mPublicToken.end())
{
mPublicToken.erase(mit);
}
else
{
return false;
}
RS_STACK_MUTEX(mDataMutex);
std::map<uint32_t, RsTokenService::GxsRequestStatus>::iterator mit =
mPublicToken.find(token);
if(mit != mPublicToken.end()) mPublicToken.erase(mit);
else return false;
return true;
}

View File

@ -48,6 +48,8 @@ public:
* deprecated and should be removed as soon as possible as it is cause of
* many confusions, instead use const RsTokReqOptions::mReqType &opts to
* 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 */
uint32_t requestStatus(const uint32_t token);
GxsRequestStatus requestStatus(const uint32_t token);
/* Cancel Request */
bool cancelRequest(const uint32_t &token);
@ -296,7 +298,7 @@ private:
* @param status the status to set
* @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
@ -307,7 +309,8 @@ private:
* @param ts time stamp
* @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)
/*!
@ -337,14 +340,14 @@ public:
* @param status
* @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
* @param token
* @return false if token could not found, true if token disposed of
*/
bool disposeOfPublicToken(const uint32_t &token);
bool disposeOfPublicToken(uint32_t token);
private:
@ -484,7 +487,7 @@ private:
RsMutex mDataMutex; /* protecting below */
uint32_t mNextToken;
std::map<uint32_t, uint32_t> mPublicToken;
std::map<uint32_t, GxsRequestStatus> mPublicToken;
std::map<uint32_t, GxsRequest*> mRequests;

View File

@ -32,7 +32,9 @@
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() {}
uint32_t token;
@ -42,7 +44,7 @@ struct GxsRequest
uint32_t reqType;
RsTokReqOptions Options;
uint32_t status;
RsTokenService::GxsRequestStatus status;
};
class GroupMetaReq : public GxsRequest

View File

@ -199,7 +199,7 @@ public:
* @param token value of token to check status for
* @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

View File

@ -556,24 +556,22 @@ void p3GxsCommentService::load_PendingVoteParent(const uint32_t &token)
pit = mPendingVotes.find(parentId);
if (pit == mPendingVotes.end())
{
std::cerr << "p3GxsCommentService::load_PendingVoteParent() ERROR Finding Pending Vote";
std::cerr << std::endl;
std::cerr << __PRETTY_FUNCTION__
<< " ERROR Finding Pending Vote" << std::endl;
continue;
}
RsGxsVote vote = pit->second.mVote;
if (meta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
{
std::cerr << "p3GxsCommentService::load_PendingVoteParent() ERROR Already Voted";
std::cerr << std::endl;
std::cerr << "mGroupId: " << meta.mGroupId;
std::cerr << std::endl;
std::cerr << "mMsgId: " << meta.mMsgId;
std::cerr << std::endl;
std::cerr << __PRETTY_FUNCTION__ << " ERROR Already Voted"
<< std::endl
<< "mGroupId: " << meta.mGroupId << std::endl
<< "mMsgId: " << meta.mMsgId << std::endl;
pit->second.mStatus = VoteHolder::VOTE_ERROR;
uint32_t status = RsTokenService::FAILED;
mExchange->updatePublicRequestStatus(pit->second.mReqToken, status);
mExchange->updatePublicRequestStatus(
pit->second.mReqToken, RsTokenService::FAILED );
continue;
}
@ -617,8 +615,8 @@ void p3GxsCommentService::completeInternalVote(uint32_t &token)
{
if (it->second.mVoteToken == token)
{
uint32_t status = mExchange->getTokenService()->requestStatus(token);
RsTokenService::GxsRequestStatus status =
mExchange->getTokenService()->requestStatus(token);
mExchange->updatePublicRequestStatus(it->second.mReqToken, status);
#ifdef DEBUG_GXSCOMMON