diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index a25d18ca4..88c7701d2 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -551,14 +551,13 @@ void RsGxsNetService::syncWithPeers() #ifndef GXS_DISABLE_SYNC_MSGS - typedef RsGxsMetaDataTemporaryMap GrpMetaMap; - GrpMetaMap grpMeta; + RsGxsGrpMetaTemporaryMap 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; @@ -596,7 +595,7 @@ void RsGxsNetService::syncWithPeers() GXSNETDEBUG_P_(peerId) << " syncing messages with peer " << peerId << std::endl; #endif - GrpMetaMap::const_iterator mmit = toRequest.begin(); + RsGxsGrpMetaTemporaryMap::const_iterator mmit = toRequest.begin(); for(; mmit != toRequest.end(); ++mmit) { const RsGxsGrpMetaData* meta = mmit->second; @@ -678,7 +677,7 @@ void RsGxsNetService::syncGrpStatistics() #ifdef NXS_NET_DEBUG_6 GXSNETDEBUG___<< "Sync-ing group statistics." << std::endl; #endif - RsGxsMetaDataTemporaryMap grpMeta; + RsGxsGrpMetaTemporaryMap grpMeta; mDataStore->retrieveGxsGrpMetaData(grpMeta); @@ -751,7 +750,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs) #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; #endif - RsGxsMetaDataTemporaryMap grpMetas; + RsGxsGrpMetaTemporaryMap grpMetas; grpMetas[grs->grpId] = NULL; mDataStore->retrieveGxsGrpMetaData(grpMetas); @@ -1905,7 +1904,7 @@ void RsGxsNetService::updateClientSyncTS() void RsGxsNetService::updateServerSyncTS() { - RsGxsMetaDataTemporaryMap gxsMap; + RsGxsGrpMetaTemporaryMap gxsMap; #ifdef NXS_NET_DEBUG_0 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) << " retrieving grp mesta data..." << std::endl; #endif - RsGxsMetaDataTemporaryMap grpMetaMap; + RsGxsGrpMetaTemporaryMap grpMetaMap; grpMetaMap[grpId] = NULL; mDataStore->retrieveGxsGrpMetaData(grpMetaMap); @@ -2977,7 +2976,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr) #endif std::list grpItemL; - RsGxsMetaDataTemporaryMap grpMetaMap; + RsGxsGrpMetaTemporaryMap grpMetaMap; for(std::list::iterator lit = tr->mItems.begin(); lit != tr->mItems.end(); ++lit) { @@ -3086,7 +3085,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr) std::list::iterator lit = tr->mItems.begin(); - RsGxsMetaDataTemporaryMap grps ; + t_RsGxsGenericDataTemporaryMap grps ; for(;lit != tr->mItems.end(); ++lit) { @@ -3803,7 +3802,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item) return; } - RsGxsMetaDataTemporaryMap grp; + RsGxsGrpMetaTemporaryMap grp; mDataStore->retrieveGxsGrpMetaData(grp); #ifdef NXS_NET_DEBUG_0 @@ -4089,7 +4088,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_ return; } - RsGxsMetaDataTemporaryMap grpMetas; + RsGxsGrpMetaTemporaryMap grpMetas; grpMetas[item->grpId] = NULL; mDataStore->retrieveGxsGrpMetaData(grpMetas); @@ -4628,7 +4627,7 @@ void RsGxsNetService::sharePublishKeysPending() // Get the meta data for this group Id // - RsGxsMetaDataTemporaryMap grpMetaMap; + RsGxsGrpMetaTemporaryMap grpMetaMap; grpMetaMap[mit->first] = NULL; mDataStore->retrieveGxsGrpMetaData(grpMetaMap); @@ -4712,7 +4711,7 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item) // Get the meta data for this group Id // - RsGxsMetaDataTemporaryMap grpMetaMap; + RsGxsGrpMetaTemporaryMap grpMetaMap; grpMetaMap[item->grpId] = NULL; mDataStore->retrieveGxsGrpMetaData(grpMetaMap); diff --git a/libretroshare/src/gxs/rsgxsutil.h b/libretroshare/src/gxs/rsgxsutil.h index ea94fedcb..f55c7c147 100644 --- a/libretroshare/src/gxs/rsgxsutil.h +++ b/libretroshare/src/gxs/rsgxsutil.h @@ -51,37 +51,37 @@ void freeAndClearContainerResource(Container container) // temporary holds a map of pointers to class T, and destroys all pointers on delete. -template -class RsGxsMetaDataTemporaryMap: public std::map +template +class t_RsGxsGenericDataTemporaryMap: public std::map { public: - virtual ~RsGxsMetaDataTemporaryMap() + virtual ~t_RsGxsGenericDataTemporaryMap() { clear() ; } virtual void clear() { - for(typename RsGxsMetaDataTemporaryMap::iterator it = this->begin();it!=this->end();++it) + for(typename t_RsGxsGenericDataTemporaryMap::iterator it = this->begin();it!=this->end();++it) if(it->second != NULL) delete it->second ; - std::map::clear() ; + std::map::clear() ; } }; template -class RsGxsMetaDataTemporaryMapVector: public std::map > +class t_RsGxsGenericDataTemporaryMapVector: public std::map > { public: - virtual ~RsGxsMetaDataTemporaryMapVector() + virtual ~t_RsGxsGenericDataTemporaryMapVector() { clear() ; } virtual void clear() { - for(typename RsGxsMetaDataTemporaryMapVector::iterator it = this->begin();it!=this->end();++it) + for(typename t_RsGxsGenericDataTemporaryMapVector::iterator it = this->begin();it!=this->end();++it) { for(uint32_t i=0;isecond.size();++i) delete it->second[i] ; @@ -92,6 +92,13 @@ public: std::map >::clear() ; } }; + +typedef t_RsGxsGenericDataTemporaryMap RsGxsGrpMetaTemporaryMap; +typedef t_RsGxsGenericDataTemporaryMap RsNxsGrpDataTemporaryMap; + +typedef t_RsGxsGenericDataTemporaryMapVector RsGxsMsgMetaTemporaryMap ; +typedef t_RsGxsGenericDataTemporaryMapVector RsNxsMsgDataTemporaryMap ; + #ifdef UNUSED template class RsGxsMetaDataTemporaryMapVector: public std::vector diff --git a/libretroshare/src/rsitems/rsmsgitems.h b/libretroshare/src/rsitems/rsmsgitems.h index 527c43fdf..b35d9ea9f 100644 --- a/libretroshare/src/rsitems/rsmsgitems.h +++ b/libretroshare/src/rsitems/rsmsgitems.h @@ -238,7 +238,7 @@ class RsMsgParentId : public RsMessageItem class RsMsgSerialiser: public RsServiceSerializer { public: - RsMsgSerialiser(SerializationFlags flags) + RsMsgSerialiser(SerializationFlags flags = RsServiceSerializer::SERIALIZATION_FLAG_NONE) :RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){} virtual ~RsMsgSerialiser() {} diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 2e2796747..5e27e378d 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -2047,7 +2047,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token) #ifdef DEBUG_CIRCLES std::cerr << "Processing circle membership requests." << std::endl; #endif - RsGxsMetaDataTemporaryMapVector msgItems; + t_RsGxsGenericDataTemporaryMapVector msgItems; if(!RsGenExchange::getMsgData(token, msgItems)) { diff --git a/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc b/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc index 5874c303f..b12063a27 100644 --- a/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc +++ b/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc @@ -39,8 +39,10 @@ void test_groupStoreAndRetrieve(){ std::map grps, grps_copy; RsNxsGrp* grp; RsGxsGrpMetaData* grpMeta; - for(int i = 0; i < nGrp; i++){ - std::pair p; + + for(int i = 0; i < nGrp; i++) + { + std::pair p; grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); grpMeta = new RsGxsGrpMetaData(); p.first = grp; @@ -64,8 +66,9 @@ void test_groupStoreAndRetrieve(){ grps.clear(); grps = grps_copy; - std::map gR; - std::map grpMetaR; + RsNxsGrpDataTemporaryMap gR; + RsGxsGrpMetaTemporaryMap grpMetaR; + dStore->retrieveNxsGrps(gR, false, false); dStore->retrieveGxsGrpMetaData(grpMetaR); @@ -119,12 +122,6 @@ void test_groupStoreAndRetrieve(){ break; } - /* release resources */ - delete l_Meta; - delete r_Meta; - delete l; - delete r; - remove(grpId.toStdString().c_str()); } @@ -158,8 +155,8 @@ void test_messageStoresAndRetrieve() int nMsgs = rand()%120; GxsMsgReq req; - std::map VergrpId0, VergrpId1; - std::map VerMetagrpId0, VerMetagrpId1; + t_RsGxsGenericDataTemporaryMap VergrpId0, VergrpId1; + t_RsGxsGenericDataTemporaryMap VerMetagrpId0, VerMetagrpId1; for(int i=0; i msgResult ; //GxsMsgResult msgResult;. The temporary version cleans up itself. + t_RsGxsGenericDataTemporaryMapVector msgMetaResult ; - RsGxsMetaDataTemporaryMapVector msgMetaResult ; dStore->retrieveNxsMsgs(req, msgResult, false); - dStore->retrieveGxsMsgMetaData(req, msgMetaResult); // now look at result for grpId 1