static void CountSSMLeave(const address &group, const address &source) { address source_addr; char tmp[64], tmp2[64]; GroupMap::iterator g = groupMap.find(group); assert(g != groupMap.end()); source_addr.set_family(source.family()); source_addr.copy_address(source); source_addr.set_port(0); SourceMap::iterator s = g->second.find(source_addr); assert(s != g->second.end()); SourceSet::iterator ss = s->second.find(source); if (ss == s->second.end()) { return; } if (verbose) info("Removing beacon %s from (%s, %s)", source.to_string(tmp, sizeof(tmp)), source_addr.to_string(tmp2, sizeof(tmp2)), group.to_string(tmp2, sizeof(tmp2))); s->second.erase(ss); if (s->second.empty()) { if (verbose) info("No more beacons for (%s, %s), leaving group", source_addr.to_string(tmp, sizeof(tmp)), group.to_string(tmp2, sizeof(tmp2))); SSMLeave(ssmMcastSock,group, source_addr); g->second.erase(s); } if (g->second.empty()) { if (verbose) info("No more sources, unregistering group %s, ", group.to_string(tmp, sizeof(tmp))); groupMap.erase(g); } }
void ModelGrouper::group( GroupMap & grouped ) { QList<QPersistentModelIndex> persistentGroupIndexes; // If we are already grouped, we need to insert items into existing groups before creating new ones if( mIsGrouped ) { // Get persistent indexes for each group item, because regular ones may be invalidated by // the move call in the loop for( ModelIter it(model()); it.isValid(); ++it ) if( model()->translator(*it) == groupedItemTranslator() ) persistentGroupIndexes.append( *it ); foreach( QPersistentModelIndex idx, persistentGroupIndexes ) { bool isEmptyGroup = model()->rowCount(idx) == 0; QString groupVal = idx.sibling( idx.row(), mGroupColumn ).data( Qt::DisplayRole ).toString(); GroupMap::Iterator mapIt = grouped.find( groupVal ); if( mapIt != grouped.end() ) { QModelIndexList toMove(fromPersist(mapIt.value())); //LOG_5( QString("Moving indexes %1 to existing group item at index %2").arg(indexListToStr(toMove)).arg(indexToStr(idx)) ); model()->move( toMove, idx ); if( isEmptyGroup ) emit groupPopulated( idx ); if( mUpdateScheduled ) { if( !mGroupItemsToUpdate.contains( idx ) ) mGroupItemsToUpdate.append(idx); } else // Tell the group item to update itself based on the added children model()->setData( idx, QVariant(), GroupingUpdate ); grouped.erase( mapIt ); } } // Deal with any now-empty groups for( QList<QPersistentModelIndex>::Iterator it = persistentGroupIndexes.begin(); it != persistentGroupIndexes.end(); ) if( model()->translator(*it) == groupedItemTranslator() && model()->rowCount(*it) == 0 ) { emit groupEmptied(*it); ++it; } else it = persistentGroupIndexes.erase( it ); if( emptyGroupPolicy() == RemoveEmptyGroups ) model()->remove( fromPersist( persistentGroupIndexes ) ); }
void removeSubGroup(const std::string& name) { GroupMap::iterator it = groups.find(name); if(it != groups.end()) groups.erase(it); }