remove MemoryCardDriverThreaded

This commit is contained in:
Glenn Maynard
2005-02-05 19:18:49 +00:00
parent 153f542193
commit 9c55974c63
2 changed files with 0 additions and 233 deletions
@@ -1,163 +0,0 @@
#include "global.h"
#include "MemoryCardDriverThreaded.h"
#include "RageLog.h"
#include "RageUtil.h"
#include "RageFileManager.h"
template<class T>
bool VectorsAreEqual( const T &a, const T &b )
{
if( a.size() != b.size() )
return false;
for( unsigned i=0; i<a.size(); i++ )
{
if( a[i] != b[i] )
return false;
}
return true;
}
MemoryCardDriverThreaded::MemoryCardDriverThreaded() :
m_mutexPause("Pause"),
m_mutexStorageDevices("StorageDevices")
{
m_bShutdownNextUpdate = false;
m_bStorageDevicesChanged = false;
m_MountThreadState = detect_and_mount;
}
void MemoryCardDriverThreaded::StartThread()
{
m_threadMemoryCardMount.SetName("MemoryCardMount");
m_threadMemoryCardMount.Create( MountThread_Start, this );
}
void MemoryCardDriverThreaded::StopThread()
{
m_bShutdownNextUpdate = true;
LOG->Trace( "Shutting down Mount thread..." );
m_threadMemoryCardMount.Wait();
LOG->Trace( "Mount thread shut down." );
}
MemoryCardDriverThreaded::~MemoryCardDriverThreaded()
{
/* Must call StopThread from the derived destructor. Otherwise, we can
* call MountThreadDoOneUpdate from the thread after the derived dtor,
* which means that function is now virtual, and we'll crash with "pure
* virtual method called". */
ASSERT( !m_threadMemoryCardMount.IsCreated() );
}
void MemoryCardDriverThreaded::SetMountThreadState( MountThreadState mts )
{
CHECKPOINT;
MountThreadState old = m_MountThreadState;
if( old != paused && mts == paused )
m_mutexPause.Lock();
if( old == paused && mts != paused )
m_mutexPause.Unlock();
m_MountThreadState = mts;
}
int MemoryCardDriverThreaded::MountThread_Start( void *p )
{
((MemoryCardDriverThreaded*)p)->MountThreadMain();
return 0;
}
void MemoryCardDriverThreaded::MountThreadMain()
{
CHECKPOINT;
while( !m_bShutdownNextUpdate )
{
if( !this->MountThreadWaitForUpdate() )
continue;
LockMut( m_mutexPause ); // wait until we're unpaused
this->MountThreadDoOneUpdate();
}
}
bool MemoryCardDriverThreaded::MountThreadWaitForUpdate()
{
usleep( 100000 );
return true;
}
bool MemoryCardDriverThreaded::StorageDevicesChanged()
{
CHECKPOINT;
LockMut( m_mutexStorageDevices );
if( m_bStorageDevicesChanged )
{
m_bStorageDevicesChanged = false;
return true;
}
else
{
return false;
}
}
void MemoryCardDriverThreaded::GetStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
{
CHECKPOINT;
LockMut( m_mutexStorageDevices );
vDevicesOut.clear();
for( unsigned i=0; i<m_vStorageDevices.size(); i++ )
vDevicesOut.push_back( m_vStorageDevices[i] );
}
bool MemoryCardDriverThreaded::MountAndTestWrite( UsbStorageDevice* pDevice )
{
LockMut( m_mutexStorageDevices );
vector<UsbStorageDevice>::const_iterator iter = find( m_vStorageDevices.begin(), m_vStorageDevices.end(), *pDevice );
if( iter == m_vStorageDevices.end() )
{
LOG->Warn( "Trying to mount a memory card that is no longer connected. bus %d port %d device %d path %s", pDevice->iBus, pDevice->iPort, pDevice->iLevel, pDevice->sOsMountDir.c_str() );
return false;
}
if( !iter->bWriteTestSucceeded )
return false;
this->Mount( pDevice );
return pDevice->bWriteTestSucceeded;
}
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* 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
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* 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
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* 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
* PERFORMANCE OF THIS SOFTWARE.
*/
@@ -1,70 +0,0 @@
#ifndef MemoryCardDriverThreaded_H
#define MemoryCardDriverThreaded_H 1
#include "MemoryCardDriver.h"
#include "RageThreads.h"
class MemoryCardDriverThreaded : public MemoryCardDriver
{
public:
MemoryCardDriverThreaded();
~MemoryCardDriverThreaded();
virtual bool StorageDevicesChanged();
virtual void GetStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
virtual bool MountAndTestWrite( UsbStorageDevice* pDevice );
virtual void SetMountThreadState( MountThreadState mts );
private:
static int MountThread_Start( void *p );
void MountThreadMain();
RageThread m_threadMemoryCardMount;
bool m_bShutdownNextUpdate;
// Aquire this before detecting devices or reading/writing devices.
// Calling Pause() and Unpause will lock/unlock this so that the mounting thread
// will temporarily halt.
RageMutex m_mutexPause;
MountThreadState m_MountThreadState;
protected:
void StartThread(); // call this in the derived constructor to start the mounting thread
void StopThread(); // call this in the derived desstructor to stop the mounting thread
virtual void MountThreadDoOneUpdate() = 0; // this will get called as fast as possible
virtual bool MountThreadWaitForUpdate();
virtual void Mount( UsbStorageDevice* pDevice ) = 0;
bool ShouldDoOsMount() { return m_MountThreadState==detect_and_mount; }
vector<UsbStorageDevice> m_vStorageDevices;
bool m_bStorageDevicesChanged;
RageMutex m_mutexStorageDevices; // protects the above two
};
#endif
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* 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
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* 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
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* 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
* PERFORMANCE OF THIS SOFTWARE.
*/