add ability to forget multiple devices

This commit is contained in:
Eric House 2013-08-31 08:26:44 -07:00
parent f6a91464ac
commit 07c9722433
2 changed files with 18 additions and 8 deletions

View file

@ -102,16 +102,26 @@ DevMgr::get( DevIDRelay devid )
return result; return result;
} }
bool int
DevMgr::forgetDevice( DevIDRelay devid ) DevMgr::forgetDevices( vector<DevIDRelay>& devids )
{ {
int count = 0;
MutexLock ml( &m_mapLock ); MutexLock ml( &m_mapLock );
map<DevIDRelay,UDPAddrRec>::iterator iter = m_devAddrMap.find( devid ); if ( 0 == devids.size() ) {
bool found = m_devAddrMap.end() != iter; count = m_devAddrMap.size();
if ( found ) { m_devAddrMap.clear();
m_devAddrMap.erase( iter ); } else {
vector<DevIDRelay>::const_iterator devidIter;
for ( devidIter = devids.begin(); devids.end() != devidIter; ++devidIter ) {
map<DevIDRelay,UDPAddrRec>::iterator iter =
m_devAddrMap.find( *devidIter );
if ( m_devAddrMap.end() != iter ) {
++count;
m_devAddrMap.erase( iter );
}
}
} }
return found; return count;
} }
void void

View file

@ -36,7 +36,7 @@ class DevMgr {
/* Called from ctrl port */ /* Called from ctrl port */
void printDevices( string& str, vector<DevIDRelay> devids /* empty means all */ ); void printDevices( string& str, vector<DevIDRelay> devids /* empty means all */ );
bool forgetDevice( DevIDRelay devid ); int forgetDevices( vector<DevIDRelay>& devids );
void getKnownDevices( vector<DevIDRelay>& devids ); void getKnownDevices( vector<DevIDRelay>& devids );
private: private: