improved template class naming for temporary Gxs grp data structures

This commit is contained in:
csoler 2017-07-24 14:29:30 +02:00
parent df691bd2d7
commit bcaafc241d
5 changed files with 42 additions and 40 deletions

View File

@ -551,14 +551,13 @@ void RsGxsNetService::syncWithPeers()
#ifndef GXS_DISABLE_SYNC_MSGS #ifndef GXS_DISABLE_SYNC_MSGS
typedef RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> GrpMetaMap; RsGxsGrpMetaTemporaryMap grpMeta;
GrpMetaMap grpMeta;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
GrpMetaMap toRequest; RsGxsGrpMetaTemporaryMap toRequest;
for(GrpMetaMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit) for(RsGxsGrpMetaTemporaryMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
{ {
RsGxsGrpMetaData* meta = mit->second; RsGxsGrpMetaData* meta = mit->second;
@ -596,7 +595,7 @@ void RsGxsNetService::syncWithPeers()
GXSNETDEBUG_P_(peerId) << " syncing messages with peer " << peerId << std::endl; GXSNETDEBUG_P_(peerId) << " syncing messages with peer " << peerId << std::endl;
#endif #endif
GrpMetaMap::const_iterator mmit = toRequest.begin(); RsGxsGrpMetaTemporaryMap::const_iterator mmit = toRequest.begin();
for(; mmit != toRequest.end(); ++mmit) for(; mmit != toRequest.end(); ++mmit)
{ {
const RsGxsGrpMetaData* meta = mmit->second; const RsGxsGrpMetaData* meta = mmit->second;
@ -678,7 +677,7 @@ void RsGxsNetService::syncGrpStatistics()
#ifdef NXS_NET_DEBUG_6 #ifdef NXS_NET_DEBUG_6
GXSNETDEBUG___<< "Sync-ing group statistics." << std::endl; GXSNETDEBUG___<< "Sync-ing group statistics." << std::endl;
#endif #endif
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMeta; RsGxsGrpMetaTemporaryMap grpMeta;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
@ -751,7 +750,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
#ifdef NXS_NET_DEBUG_6 #ifdef NXS_NET_DEBUG_6
GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << "Received Grp update stats Request for group " << grs->grpId << " from friend " << grs->PeerId() << std::endl; GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << "Received Grp update stats Request for group " << grs->grpId << " from friend " << grs->PeerId() << std::endl;
#endif #endif
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetas; RsGxsGrpMetaTemporaryMap grpMetas;
grpMetas[grs->grpId] = NULL; grpMetas[grs->grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetas); mDataStore->retrieveGxsGrpMetaData(grpMetas);
@ -1905,7 +1904,7 @@ void RsGxsNetService::updateClientSyncTS()
void RsGxsNetService::updateServerSyncTS() void RsGxsNetService::updateServerSyncTS()
{ {
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> gxsMap; RsGxsGrpMetaTemporaryMap gxsMap;
#ifdef NXS_NET_DEBUG_0 #ifdef NXS_NET_DEBUG_0
GXSNETDEBUG___<< "updateServerSyncTS(): updating last modification time stamp of local data." << std::endl; GXSNETDEBUG___<< "updateServerSyncTS(): updating last modification time stamp of local data." << std::endl;
@ -2719,7 +2718,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
GXSNETDEBUG_PG(item->PeerId(),grpId) << " grpId = " << grpId << std::endl; GXSNETDEBUG_PG(item->PeerId(),grpId) << " grpId = " << grpId << std::endl;
GXSNETDEBUG_PG(item->PeerId(),grpId) << " retrieving grp mesta data..." << std::endl; GXSNETDEBUG_PG(item->PeerId(),grpId) << " retrieving grp mesta data..." << std::endl;
#endif #endif
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap; RsGxsGrpMetaTemporaryMap grpMetaMap;
grpMetaMap[grpId] = NULL; grpMetaMap[grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetaMap); mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
@ -2977,7 +2976,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
#endif #endif
std::list<RsNxsSyncGrpItem*> grpItemL; std::list<RsNxsSyncGrpItem*> grpItemL;
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap; RsGxsGrpMetaTemporaryMap grpMetaMap;
for(std::list<RsNxsItem*>::iterator lit = tr->mItems.begin(); lit != tr->mItems.end(); ++lit) for(std::list<RsNxsItem*>::iterator lit = tr->mItems.begin(); lit != tr->mItems.end(); ++lit)
{ {
@ -3086,7 +3085,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
std::list<RsNxsItem*>::iterator lit = tr->mItems.begin(); std::list<RsNxsItem*>::iterator lit = tr->mItems.begin();
RsGxsMetaDataTemporaryMap<RsNxsGrp> grps ; t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> grps ;
for(;lit != tr->mItems.end(); ++lit) for(;lit != tr->mItems.end(); ++lit)
{ {
@ -3803,7 +3802,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item)
return; return;
} }
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grp; RsGxsGrpMetaTemporaryMap grp;
mDataStore->retrieveGxsGrpMetaData(grp); mDataStore->retrieveGxsGrpMetaData(grp);
#ifdef NXS_NET_DEBUG_0 #ifdef NXS_NET_DEBUG_0
@ -4089,7 +4088,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_
return; return;
} }
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetas; RsGxsGrpMetaTemporaryMap grpMetas;
grpMetas[item->grpId] = NULL; grpMetas[item->grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetas); mDataStore->retrieveGxsGrpMetaData(grpMetas);
@ -4628,7 +4627,7 @@ void RsGxsNetService::sharePublishKeysPending()
// Get the meta data for this group Id // Get the meta data for this group Id
// //
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap; RsGxsGrpMetaTemporaryMap grpMetaMap;
grpMetaMap[mit->first] = NULL; grpMetaMap[mit->first] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetaMap); mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
@ -4712,7 +4711,7 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
// Get the meta data for this group Id // Get the meta data for this group Id
// //
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap; RsGxsGrpMetaTemporaryMap grpMetaMap;
grpMetaMap[item->grpId] = NULL; grpMetaMap[item->grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetaMap); mDataStore->retrieveGxsGrpMetaData(grpMetaMap);

View File

@ -51,37 +51,37 @@ void freeAndClearContainerResource(Container container)
// temporary holds a map of pointers to class T, and destroys all pointers on delete. // temporary holds a map of pointers to class T, and destroys all pointers on delete.
template<class T> template<class IdClass,class IdData>
class RsGxsMetaDataTemporaryMap: public std::map<RsGxsGroupId,T*> class t_RsGxsGenericDataTemporaryMap: public std::map<IdClass,IdData *>
{ {
public: public:
virtual ~RsGxsMetaDataTemporaryMap() virtual ~t_RsGxsGenericDataTemporaryMap()
{ {
clear() ; clear() ;
} }
virtual void clear() virtual void clear()
{ {
for(typename RsGxsMetaDataTemporaryMap<T>::iterator it = this->begin();it!=this->end();++it) for(typename t_RsGxsGenericDataTemporaryMap<IdClass,IdData>::iterator it = this->begin();it!=this->end();++it)
if(it->second != NULL) if(it->second != NULL)
delete it->second ; delete it->second ;
std::map<RsGxsGroupId,T*>::clear() ; std::map<IdClass,IdData*>::clear() ;
} }
}; };
template<class T> template<class T>
class RsGxsMetaDataTemporaryMapVector: public std::map<RsGxsGroupId,std::vector<T*> > class t_RsGxsGenericDataTemporaryMapVector: public std::map<RsGxsGroupId,std::vector<T*> >
{ {
public: public:
virtual ~RsGxsMetaDataTemporaryMapVector() virtual ~t_RsGxsGenericDataTemporaryMapVector()
{ {
clear() ; clear() ;
} }
virtual void clear() virtual void clear()
{ {
for(typename RsGxsMetaDataTemporaryMapVector<T>::iterator it = this->begin();it!=this->end();++it) for(typename t_RsGxsGenericDataTemporaryMapVector<T>::iterator it = this->begin();it!=this->end();++it)
{ {
for(uint32_t i=0;i<it->second.size();++i) for(uint32_t i=0;i<it->second.size();++i)
delete it->second[i] ; delete it->second[i] ;
@ -92,6 +92,13 @@ public:
std::map<RsGxsGroupId,std::vector<T*> >::clear() ; std::map<RsGxsGroupId,std::vector<T*> >::clear() ;
} }
}; };
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsGxsGrpMetaData> RsGxsGrpMetaTemporaryMap;
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> RsNxsGrpDataTemporaryMap;
typedef t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> RsGxsMsgMetaTemporaryMap ;
typedef t_RsGxsGenericDataTemporaryMapVector<RsNxsMsg> RsNxsMsgDataTemporaryMap ;
#ifdef UNUSED #ifdef UNUSED
template<class T> template<class T>
class RsGxsMetaDataTemporaryMapVector: public std::vector<T*> class RsGxsMetaDataTemporaryMapVector: public std::vector<T*>

View File

@ -238,7 +238,7 @@ class RsMsgParentId : public RsMessageItem
class RsMsgSerialiser: public RsServiceSerializer class RsMsgSerialiser: public RsServiceSerializer
{ {
public: public:
RsMsgSerialiser(SerializationFlags flags) RsMsgSerialiser(SerializationFlags flags = RsServiceSerializer::SERIALIZATION_FLAG_NONE)
:RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){} :RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){}
virtual ~RsMsgSerialiser() {} virtual ~RsMsgSerialiser() {}

View File

@ -2047,7 +2047,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
#ifdef DEBUG_CIRCLES #ifdef DEBUG_CIRCLES
std::cerr << "Processing circle membership requests." << std::endl; std::cerr << "Processing circle membership requests." << std::endl;
#endif #endif
RsGxsMetaDataTemporaryMapVector<RsGxsMsgItem> msgItems; t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgItem> msgItems;
if(!RsGenExchange::getMsgData(token, msgItems)) if(!RsGenExchange::getMsgData(token, msgItems))
{ {

View File

@ -39,8 +39,10 @@ void test_groupStoreAndRetrieve(){
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps, grps_copy; std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps, grps_copy;
RsNxsGrp* grp; RsNxsGrp* grp;
RsGxsGrpMetaData* grpMeta; RsGxsGrpMetaData* grpMeta;
for(int i = 0; i < nGrp; i++){
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p; for(int i = 0; i < nGrp; i++)
{
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
grpMeta = new RsGxsGrpMetaData(); grpMeta = new RsGxsGrpMetaData();
p.first = grp; p.first = grp;
@ -64,8 +66,9 @@ void test_groupStoreAndRetrieve(){
grps.clear(); grps.clear();
grps = grps_copy; grps = grps_copy;
std::map<RsGxsGroupId, RsNxsGrp*> gR; RsNxsGrpDataTemporaryMap gR;
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetaR; RsGxsGrpMetaTemporaryMap grpMetaR;
dStore->retrieveNxsGrps(gR, false, false); dStore->retrieveNxsGrps(gR, false, false);
dStore->retrieveGxsGrpMetaData(grpMetaR); dStore->retrieveGxsGrpMetaData(grpMetaR);
@ -119,12 +122,6 @@ void test_groupStoreAndRetrieve(){
break; break;
} }
/* release resources */
delete l_Meta;
delete r_Meta;
delete l;
delete r;
remove(grpId.toStdString().c_str()); remove(grpId.toStdString().c_str());
} }
@ -158,8 +155,8 @@ void test_messageStoresAndRetrieve()
int nMsgs = rand()%120; int nMsgs = rand()%120;
GxsMsgReq req; GxsMsgReq req;
std::map<RsGxsMessageId, RsNxsMsg*> VergrpId0, VergrpId1; t_RsGxsGenericDataTemporaryMap<RsGxsMessageId,RsNxsMsg> VergrpId0, VergrpId1;
std::map<RsGxsMessageId, RsGxsMsgMetaData*> VerMetagrpId0, VerMetagrpId1; t_RsGxsGenericDataTemporaryMap<RsGxsMessageId, RsGxsMsgMetaData> VerMetagrpId0, VerMetagrpId1;
for(int i=0; i<nMsgs; i++) for(int i=0; i<nMsgs; i++)
{ {
@ -221,11 +218,10 @@ void test_messageStoresAndRetrieve()
// now retrieve msgs for comparison // now retrieve msgs for comparison
// first selective retrieval // first selective retrieval
GxsMsgResult msgResult; t_RsGxsGenericDataTemporaryMapVector<RsNxsMsg> msgResult ; //GxsMsgResult msgResult;. The temporary version cleans up itself.
t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> msgMetaResult ;
RsGxsMetaDataTemporaryMapVector<RsGxsMsgMetaData> msgMetaResult ;
dStore->retrieveNxsMsgs(req, msgResult, false); dStore->retrieveNxsMsgs(req, msgResult, false);
dStore->retrieveGxsMsgMetaData(req, msgMetaResult); dStore->retrieveGxsMsgMetaData(req, msgMetaResult);
// now look at result for grpId 1 // now look at result for grpId 1