This commit is contained in:
Chris Danford
2004-08-17 06:35:42 +00:00
parent 925c349d26
commit bac085dc6d
4 changed files with 52 additions and 112 deletions
+34 -54
View File
@@ -47,16 +47,8 @@ void MemoryCardManager::Update( float fDelta )
// check for disconnects // check for disconnects
FOREACH( UsbStorageDevice, vOld, old ) FOREACH( UsbStorageDevice, vOld, old )
{ {
bool bFoundMatch = false; vector<UsbStorageDevice>::iterator iter = find( vNew.begin(), vNew.end(), *old );
FOREACH( UsbStorageDevice, vNew, newd ) if( iter == vNew.end() ) // card no longer present
{
if( old->IdsMatch(*newd) )
{
bFoundMatch = true;
break;
}
}
if( !bFoundMatch )
{ {
LOG->Trace( "Disconnected bus %d port %d device %d path %s", old->iBus, old->iPort, old->iLevel, old->sOsMountDir.c_str() ); LOG->Trace( "Disconnected bus %d port %d device %d path %s", old->iBus, old->iPort, old->iLevel, old->sOsMountDir.c_str() );
vDisconnects.push_back( *old ); vDisconnects.push_back( *old );
@@ -66,16 +58,8 @@ void MemoryCardManager::Update( float fDelta )
// check for connects // check for connects
FOREACH( UsbStorageDevice, vNew, newd ) FOREACH( UsbStorageDevice, vNew, newd )
{ {
bool bFoundMatch = false; vector<UsbStorageDevice>::iterator iter = find( vOld.begin(), vOld.end(), *newd );
FOREACH( UsbStorageDevice, vOld, old ) if( iter == vOld.end() ) // card wasn't present last update
{
if( old->IdsMatch(*newd) )
{
bFoundMatch = true;
break;
}
}
if( !bFoundMatch )
{ {
LOG->Trace( "Connected bus %d port %d device %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() ); LOG->Trace( "Connected bus %d port %d device %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() );
vDisconnects.push_back( *newd ); vDisconnects.push_back( *newd );
@@ -89,9 +73,8 @@ void MemoryCardManager::Update( float fDelta )
if( assigned_device.IsBlank() ) // not assigned a card if( assigned_device.IsBlank() ) // not assigned a card
continue; continue;
FOREACH( UsbStorageDevice, vDisconnects, disconnect ) vector<UsbStorageDevice>::iterator iter = find( vDisconnects.begin(), vDisconnects.end(), assigned_device );
{ if( iter != vDisconnects.end() )
if( disconnect->IdsMatch(assigned_device) )
{ {
m_pDriver->Unmount(&assigned_device, MEM_CARD_MOUNT_POINT[p]); m_pDriver->Unmount(&assigned_device, MEM_CARD_MOUNT_POINT[p]);
@@ -102,7 +85,6 @@ void MemoryCardManager::Update( float fDelta )
PROFILEMAN->UnloadProfile( p ); PROFILEMAN->UnloadProfile( p );
} }
} }
}
// Update the status of already-assigned cards. It may contain updated info // Update the status of already-assigned cards. It may contain updated info
// like WriteTest results and a new sName. // like WriteTest results and a new sName.
@@ -112,15 +94,13 @@ void MemoryCardManager::Update( float fDelta )
if( assigned_device.IsBlank() ) // no card assigned to this player if( assigned_device.IsBlank() ) // no card assigned to this player
continue; continue;
FOREACH( UsbStorageDevice, m_vStorageDevices, d ) vector<UsbStorageDevice>::iterator iter = find( m_vStorageDevices.begin(), m_vStorageDevices.end(), assigned_device );
{ if( iter != m_vStorageDevices.end() )
if( d->IdsMatch(assigned_device) )
{ {
// play write test error sound if write test failed since we last checked // play write test error sound if write test failed since we last checked
if( assigned_device.bNeedsWriteTest && !d->bNeedsWriteTest && !d->bWriteTestSucceeded ) if( assigned_device.bNeedsWriteTest && !iter->bNeedsWriteTest && !iter->bWriteTestSucceeded )
m_soundError.Play(); m_soundError.Play();
assigned_device = *d; assigned_device = *iter;
}
} }
} }
@@ -136,7 +116,7 @@ void MemoryCardManager::Update( float fDelta )
FOREACH( UsbStorageDevice, vUnassignedDevices, d ) FOREACH( UsbStorageDevice, vUnassignedDevices, d )
{ {
if( d->IdsMatch(assigned_device) ) if( *d == assigned_device )
{ {
vUnassignedDevices.erase( d ); vUnassignedDevices.erase( d );
break; break;
@@ -297,26 +277,26 @@ bool IsAnyPlayerUsingMemoryCard()
LuaFunction_NoArgs( IsAnyPlayerUsingMemoryCard, IsAnyPlayerUsingMemoryCard() ) LuaFunction_NoArgs( IsAnyPlayerUsingMemoryCard, IsAnyPlayerUsingMemoryCard() )
/* /*
* (c) 2003-2004 Chris Danford * (c) 2003-2004 Chris Danford
* All rights reserved. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the * copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to * distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above * whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of * copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this * the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation. * permission notice appear in supporting documentation.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE. * PERFORMANCE OF THIS SOFTWARE.
*/ */
@@ -4,7 +4,7 @@
#include "arch/arch_platform.h" #include "arch/arch_platform.h"
bool UsbStorageDevice::IdsMatch(const UsbStorageDevice& other) const bool UsbStorageDevice::operator==(const UsbStorageDevice& other) const
{ {
// LOG->Trace( "Comparing %d %d %d %s %s to %d %d %d %s %s", // LOG->Trace( "Comparing %d %d %d %s %s to %d %d %d %s %s",
// iBus, iPort, iLevel, sName.c_str(), sOsMountDir.c_str(), // iBus, iPort, iLevel, sName.c_str(), sOsMountDir.c_str(),
@@ -32,24 +32,7 @@ struct UsbStorageDevice
bool IsBlank() { return sOsMountDir.empty(); } bool IsBlank() { return sOsMountDir.empty(); }
bool operator==(const UsbStorageDevice& other) const bool operator==(const UsbStorageDevice& other) const;
{
#define COMPARE(x) if( x != other.x ) return false;
COMPARE( iBus );
COMPARE( iPort );
COMPARE( iLevel );
COMPARE( sSerial );
COMPARE( iScsiIndex );
COMPARE( sScsiDevice );
COMPARE( sOsMountDir );
COMPARE( sName );
COMPARE( bNeedsWriteTest );
COMPARE( bWriteTestSucceeded );
COMPARE( sOsMountDir );
#undef COMPARE
return true;
}
bool IdsMatch(const UsbStorageDevice& other) const;
}; };
class MemoryCardDriver class MemoryCardDriver
@@ -223,29 +223,15 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
vector<UsbStorageDevice> vDisconnects; vector<UsbStorageDevice> vDisconnects;
FOREACH( UsbStorageDevice, vOld, old ) FOREACH( UsbStorageDevice, vOld, old )
{ {
bool bMatch = false; vector<UsbStorageDevice>::iterator iter = find( vNew.begin(), vNew.end(), *old );
FOREACH( UsbStorageDevice, vNew, newd ) if( iter == vNew.end() ) // didn't find
{
if( old->IdsMatch(*newd) )
{
bMatch = true;
break;
}
}
if( !bMatch ) // didn't find
{ {
LOG->Trace( "Disconnected bus %d port %d level %d path %s", old->iBus, old->iPort, old->iLevel, old->sOsMountDir.c_str() ); LOG->Trace( "Disconnected bus %d port %d level %d path %s", old->iBus, old->iPort, old->iLevel, old->sOsMountDir.c_str() );
vDisconnects.push_back( *old ); vDisconnects.push_back( *old );
FOREACH( UsbStorageDevice, m_vDevicesLastSeen, d ) vector<UsbStorageDevice>::iterator iter = find( m_vDevicesLastSeen.begin(), m_vDevicesLastSeen.end(), *old );
{ ASSERT( iter != m_vDevicesLastSeen.end() );
if( old->IdsMatch(*d) ) m_vDevicesLastSeen.erase( iter );
{
m_vDevicesLastSeen.erase( d );
break;
}
}
} }
} }
@@ -254,17 +240,8 @@ void MemoryCardDriverThreaded_Linux::MountThreadDoOneUpdate()
vector<UsbStorageDevice> vConnects; vector<UsbStorageDevice> vConnects;
FOREACH( UsbStorageDevice, vNew, newd ) FOREACH( UsbStorageDevice, vNew, newd )
{ {
bool bMatch = false; vector<UsbStorageDevice>::iterator iter = find( vOld.begin(), vOld.end(), *newd );
FOREACH( UsbStorageDevice, vOld, old ) if( iter == vOld.end() ) // didn't find
{
if( old->IdsMatch(*newd) )
{
bMatch = true;
break;
}
}
if( !bMatch ) // didn't find
{ {
LOG->Trace( "Connected bus %d port %d level %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() ); LOG->Trace( "Connected bus %d port %d level %d path %s", newd->iBus, newd->iPort, newd->iLevel, newd->sOsMountDir.c_str() );
vConnects.push_back( *newd ); vConnects.push_back( *newd );