working on more efficient Linux usb detection

This commit is contained in:
Chris Danford
2003-12-16 05:10:27 +00:00
parent 7ac5c5c27c
commit 1f5e97f975
+40 -16
View File
@@ -56,7 +56,7 @@ struct UsbStorageDevice
vector<UsbStorageDevice> g_StorageDevices; vector<UsbStorageDevice> g_StorageDevices;
bool UpdateAttachedUsbStorageDevices() void UpdateAttachedUsbStorageDevices()
{ {
vector<UsbStorageDevice> &vDevicesOut = g_StorageDevices; vector<UsbStorageDevice> &vDevicesOut = g_StorageDevices;
@@ -92,7 +92,7 @@ bool UpdateAttachedUsbStorageDevices()
if( !f.is_open() ) if( !f.is_open() )
{ {
LOG->Warn( "can't open '%s'", fn.c_str() ); LOG->Warn( "can't open '%s'", fn.c_str() );
return false; return;
} }
UsbStorageDevice usbd; UsbStorageDevice usbd;
@@ -155,7 +155,7 @@ bool UpdateAttachedUsbStorageDevices()
if( !f.is_open() ) if( !f.is_open() )
{ {
LOG->Warn( "can't open '%s'", fn.c_str() ); LOG->Warn( "can't open '%s'", fn.c_str() );
return false; return;
} }
CString sLine; CString sLine;
@@ -186,7 +186,7 @@ bool UpdateAttachedUsbStorageDevices()
if( !f.is_open() ) if( !f.is_open() )
{ {
LOG->Warn( "can't open '%s'", fn.c_str() ); LOG->Warn( "can't open '%s'", fn.c_str() );
return false; return;
} }
CString sLine; CString sLine;
@@ -216,11 +216,11 @@ bool UpdateAttachedUsbStorageDevices()
} }
} }
} }
return true; return;
#elif defined(_WINDOWS) #elif defined(_WINDOWS)
return false;
#else #else
return false;
#endif #endif
} }
@@ -235,16 +235,40 @@ MemoryCardManager::~MemoryCardManager()
} }
bool UsbChanged()
{
#if defined(LINUX)
// UGLY: if the system log changed, then a USB device was connected or
// disconnected. Use this as a trivial check.
static const CString VAR_LOG_MESSAGES = "/var/log/messages";
static bool bFirstTime = false;
static _stat old_stat;
if( bFirstTime )
{
_fstat(VAR_LOG_MESSAGES, &old_stat);
bFirstTime = false;
return true;
}
else
{
_stat new_stat;
_fstat(VAR_LOG_MESSAGES, &new_stat);
bool bChanged = old_stat != new_stat;
old_stat = new_stat;
return bChanged;
}
#elif defined(_WINDOWS)
return false;
#else
return false;
#endif
}
void MemoryCardManager::Update( float fDelta ) void MemoryCardManager::Update( float fDelta )
{ {
/* if( UsbChanged() )
static count = 0; {
count++; vector<UsbStorageDevice> vOld = g_StorageDevices; // make a copy
if( count != 20 )
return;
count = 0;
vector<UsbStorageDevice> vOld = g_StorageDevices;
UpdateAttachedUsbStorageDevices(); UpdateAttachedUsbStorageDevices();
vector<UsbStorageDevice> &vNew = g_StorageDevices; vector<UsbStorageDevice> &vNew = g_StorageDevices;
@@ -265,5 +289,5 @@ void MemoryCardManager::Update( float fDelta )
if( find(vOld.begin(),vOld.end(),newd) == vOld.end() ) if( find(vOld.begin(),vOld.end(),newd) == vOld.end() )
SCREENMAN->SystemMessage( ssprintf("Connected bus %d port %d device %d", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus) ); SCREENMAN->SystemMessage( ssprintf("Connected bus %d port %d device %d", newd.iBus, newd.iPortOnHub, newd.iDeviceOnBus) );
} }
*/ }
} }