mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
added auto delete active token feature to RsGxsIfaceHelper
This commit is contained in:
parent
70d0c7b1b3
commit
5408427ea8
@ -38,14 +38,25 @@
|
|||||||
* To properly fix the API design many changes with the implied chain reactions
|
* To properly fix the API design many changes with the implied chain reactions
|
||||||
* are necessary, so at this point this workaround seems acceptable.
|
* are necessary, so at this point this workaround seems acceptable.
|
||||||
*/
|
*/
|
||||||
struct RsGxsIfaceHelper
|
|
||||||
|
enum class TokenRequestType: uint8_t
|
||||||
{
|
{
|
||||||
|
GROUP_INFO = 0x01,
|
||||||
|
MSG_INFO = 0x02,
|
||||||
|
MSG_RELATED_INFO = 0x03,
|
||||||
|
GROUP_STATISTICS = 0x04,
|
||||||
|
SERVICE_STATISTICS = 0x05,
|
||||||
|
};
|
||||||
|
|
||||||
|
class RsGxsIfaceHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
/*!
|
/*!
|
||||||
* @param gxs handle to RsGenExchange instance of service (Usually the
|
* @param gxs handle to RsGenExchange instance of service (Usually the
|
||||||
* service class itself)
|
* service class itself)
|
||||||
*/
|
*/
|
||||||
RsGxsIfaceHelper(RsGxsIface& gxs) :
|
RsGxsIfaceHelper(RsGxsIface& gxs) :
|
||||||
mGxs(gxs), mTokenService(*gxs.getTokenService()) {}
|
mGxs(gxs), mTokenService(*gxs.getTokenService()),mMtx("GxsIfaceHelper") {}
|
||||||
|
|
||||||
~RsGxsIfaceHelper(){}
|
~RsGxsIfaceHelper(){}
|
||||||
|
|
||||||
@ -235,28 +246,80 @@ struct RsGxsIfaceHelper
|
|||||||
/// @see RsTokenService::requestGroupInfo
|
/// @see RsTokenService::requestGroupInfo
|
||||||
bool requestGroupInfo( uint32_t& token, const RsTokReqOptions& opts,
|
bool requestGroupInfo( uint32_t& token, const RsTokReqOptions& opts,
|
||||||
const std::list<RsGxsGroupId> &groupIds )
|
const std::list<RsGxsGroupId> &groupIds )
|
||||||
{ return mTokenService.requestGroupInfo(token, 0, opts, groupIds); }
|
{
|
||||||
|
cancelActiveRequestTokens(TokenRequestType::GROUP_INFO);
|
||||||
|
|
||||||
|
if( mTokenService.requestGroupInfo(token, 0, opts, groupIds))
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens[token]=TokenRequestType::GROUP_INFO;
|
||||||
|
locked_dumpTokens();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// @see RsTokenService::requestGroupInfo
|
/// @see RsTokenService::requestGroupInfo
|
||||||
bool requestGroupInfo(uint32_t& token, const RsTokReqOptions& opts)
|
bool requestGroupInfo(uint32_t& token, const RsTokReqOptions& opts)
|
||||||
{ return mTokenService.requestGroupInfo(token, 0, opts); }
|
{
|
||||||
|
cancelActiveRequestTokens(TokenRequestType::GROUP_INFO);
|
||||||
|
|
||||||
|
if( mTokenService.requestGroupInfo(token, 0, opts))
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens[token]=TokenRequestType::GROUP_INFO;
|
||||||
|
locked_dumpTokens();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// @see RsTokenService::requestMsgInfo
|
/// @see RsTokenService::requestMsgInfo
|
||||||
bool requestMsgInfo( uint32_t& token,
|
bool requestMsgInfo( uint32_t& token,
|
||||||
const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
|
const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
|
||||||
{ return mTokenService.requestMsgInfo(token, 0, opts, msgIds); }
|
{
|
||||||
|
if(mTokenService.requestMsgInfo(token, 0, opts, msgIds))
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens[token]=TokenRequestType::MSG_INFO;
|
||||||
|
locked_dumpTokens();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// @see RsTokenService::requestMsgInfo
|
/// @see RsTokenService::requestMsgInfo
|
||||||
bool requestMsgInfo(
|
bool requestMsgInfo( uint32_t& token, const RsTokReqOptions& opts, const std::list<RsGxsGroupId>& grpIds )
|
||||||
uint32_t& token, const RsTokReqOptions& opts,
|
{
|
||||||
const std::list<RsGxsGroupId>& grpIds )
|
if(mTokenService.requestMsgInfo(token, 0, opts, grpIds))
|
||||||
{ return mTokenService.requestMsgInfo(token, 0, opts, grpIds); }
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens[token]=TokenRequestType::MSG_INFO;
|
||||||
|
locked_dumpTokens();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// @see RsTokenService::requestMsgRelatedInfo
|
/// @see RsTokenService::requestMsgRelatedInfo
|
||||||
bool requestMsgRelatedInfo(
|
bool requestMsgRelatedInfo(
|
||||||
uint32_t& token, const RsTokReqOptions& opts,
|
uint32_t& token, const RsTokReqOptions& opts,
|
||||||
const std::vector<RsGxsGrpMsgIdPair>& msgIds )
|
const std::vector<RsGxsGrpMsgIdPair>& msgIds )
|
||||||
{ return mTokenService.requestMsgRelatedInfo(token, 0, opts, msgIds); }
|
{
|
||||||
|
if( mTokenService.requestMsgRelatedInfo(token, 0, opts, msgIds))
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens[token]=TokenRequestType::MSG_RELATED_INFO;
|
||||||
|
locked_dumpTokens();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @jsonapi{development}
|
* @jsonapi{development}
|
||||||
@ -267,14 +330,46 @@ struct RsGxsIfaceHelper
|
|||||||
|
|
||||||
/// @see RsTokenService::requestServiceStatistic
|
/// @see RsTokenService::requestServiceStatistic
|
||||||
void requestServiceStatistic(uint32_t& token)
|
void requestServiceStatistic(uint32_t& token)
|
||||||
{ mTokenService.requestServiceStatistic(token); }
|
{
|
||||||
|
mTokenService.requestServiceStatistic(token);
|
||||||
|
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens[token]=TokenRequestType::SERVICE_STATISTICS;
|
||||||
|
|
||||||
|
locked_dumpTokens();
|
||||||
|
}
|
||||||
|
|
||||||
/// @see RsTokenService::requestGroupStatistic
|
/// @see RsTokenService::requestGroupStatistic
|
||||||
void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId)
|
void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId)
|
||||||
{ mTokenService.requestGroupStatistic(token, grpId); }
|
{
|
||||||
|
mTokenService.requestGroupStatistic(token, grpId);
|
||||||
|
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens[token]=TokenRequestType::GROUP_STATISTICS;
|
||||||
|
locked_dumpTokens();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cancelActiveRequestTokens(TokenRequestType type)
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
for(auto it = mActiveTokens.begin();it!=mActiveTokens.end();)
|
||||||
|
if(it->second == type)
|
||||||
|
{
|
||||||
|
mTokenService.cancelRequest(it->first);
|
||||||
|
it = mActiveTokens.erase(it);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// @see RsTokenService::cancelRequest
|
/// @see RsTokenService::cancelRequest
|
||||||
bool cancelRequest(uint32_t token) { return mTokenService.cancelRequest(token); }
|
bool cancelRequest(uint32_t token)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens.erase(token);
|
||||||
|
}
|
||||||
|
return mTokenService.cancelRequest(token);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@ -294,7 +389,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
RsTokenService::GxsRequestStatus waitToken(
|
RsTokenService::GxsRequestStatus waitToken(
|
||||||
uint32_t token,
|
uint32_t token,
|
||||||
std::chrono::milliseconds maxWait = std::chrono::milliseconds(2000),
|
std::chrono::milliseconds maxWait = std::chrono::milliseconds(10000),
|
||||||
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20),
|
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20),
|
||||||
bool auto_delete_if_unsuccessful=true)
|
bool auto_delete_if_unsuccessful=true)
|
||||||
{
|
{
|
||||||
@ -302,6 +397,11 @@ protected:
|
|||||||
|
|
||||||
if(res != RsTokenService::COMPLETE && auto_delete_if_unsuccessful)
|
if(res != RsTokenService::COMPLETE && auto_delete_if_unsuccessful)
|
||||||
cancelRequest(token);
|
cancelRequest(token);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mMtx);
|
||||||
|
mActiveTokens.erase(token);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -309,4 +409,15 @@ protected:
|
|||||||
private:
|
private:
|
||||||
RsGxsIface& mGxs;
|
RsGxsIface& mGxs;
|
||||||
RsTokenService& mTokenService;
|
RsTokenService& mTokenService;
|
||||||
|
RsMutex mMtx;
|
||||||
|
|
||||||
|
std::map<uint32_t,TokenRequestType> mActiveTokens;
|
||||||
|
|
||||||
|
void locked_dumpTokens()
|
||||||
|
{
|
||||||
|
std::cerr << "Active tokens (this=" << (void*)this << "): " ;
|
||||||
|
for(auto it: mActiveTokens)
|
||||||
|
std::cerr << std::dec << it.first << " (" << static_cast<int>(it.second) << ") " ;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -383,8 +383,9 @@ struct RsIdentityDetails : RsSerializable
|
|||||||
|
|
||||||
|
|
||||||
/** The Main Interface Class for GXS people identities */
|
/** The Main Interface Class for GXS people identities */
|
||||||
struct RsIdentity : RsGxsIfaceHelper
|
class RsIdentity: public RsGxsIfaceHelper
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
explicit RsIdentity(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
explicit RsIdentity(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1444,7 +1444,7 @@ void GxsForumThreadWidget::async_msg_action(const MsgMethod &action)
|
|||||||
|
|
||||||
if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs))
|
if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs))
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << groupId() << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum message info for forum " << groupId() << " and thread " << mThreadId << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1719,7 +1719,7 @@ void GxsForumThreadWidget::updateGroupData()
|
|||||||
|
|
||||||
// 2 - sort the messages into a proper hierarchy
|
// 2 - sort the messages into a proper hierarchy
|
||||||
|
|
||||||
RsGxsForumGroup *group = new RsGxsForumGroup(groups[0]); // we use a pointer in order to avoid group deletion while we're in the thread.
|
RsGxsForumGroup group(groups[0]); // we use a copy to share the object in order to avoid group deletion while we're in the thread.
|
||||||
|
|
||||||
// 3 - update the model in the UI thread.
|
// 3 - update the model in the UI thread.
|
||||||
|
|
||||||
@ -1729,8 +1729,7 @@ void GxsForumThreadWidget::updateGroupData()
|
|||||||
* thread, for example to update the data model with new information
|
* thread, for example to update the data model with new information
|
||||||
* after a blocking call to RetroShare API complete */
|
* after a blocking call to RetroShare API complete */
|
||||||
|
|
||||||
mForumGroup = *group;
|
mForumGroup = group;
|
||||||
delete group;
|
|
||||||
|
|
||||||
ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
|
ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
|
||||||
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ;
|
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ;
|
||||||
@ -1759,7 +1758,7 @@ void GxsForumThreadWidget::updateMessageData(const RsGxsMessageId& msgId)
|
|||||||
|
|
||||||
if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs))
|
if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs))
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << groupId() << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message info for forum " << groupId() << " and MsgId " << msgId << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1778,7 +1777,7 @@ void GxsForumThreadWidget::updateMessageData(const RsGxsMessageId& msgId)
|
|||||||
|
|
||||||
// 2 - sort the messages into a proper hierarchy
|
// 2 - sort the messages into a proper hierarchy
|
||||||
|
|
||||||
RsGxsForumMsg *msg = new RsGxsForumMsg(msgs[0]);
|
RsGxsForumMsg msg(msgs[0]);
|
||||||
|
|
||||||
// 3 - update the model in the UI thread.
|
// 3 - update the model in the UI thread.
|
||||||
|
|
||||||
@ -1788,9 +1787,8 @@ void GxsForumThreadWidget::updateMessageData(const RsGxsMessageId& msgId)
|
|||||||
* thread, for example to update the data model with new information
|
* thread, for example to update the data model with new information
|
||||||
* after a blocking call to RetroShare API complete */
|
* after a blocking call to RetroShare API complete */
|
||||||
|
|
||||||
insertMessageData(*msg);
|
insertMessageData(msg);
|
||||||
|
|
||||||
delete msg;
|
|
||||||
ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
|
ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
|
||||||
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ;
|
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mForumGroup.mMeta.mSubscribeFlags)) ;
|
||||||
}, this );
|
}, this );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user