#include "IOSCSIParallelDevice.h"
#include "IOSCSIParallelCommand.h"
void IOSCSIParallelDevice::addCommand( queue_head_t *list, IOSCSIParallelCommand *scsiCmd )
{
scsiCmd->list = list;
queue_enter( list, scsiCmd, IOSCSIParallelCommand *, nextCommand );
}
void IOSCSIParallelDevice::deleteCommand( queue_head_t *list, IOSCSIParallelCommand *scsiCmd, IOReturn rc )
{
scsiCmd->list = 0;
if ( rc != kIOReturnSuccess )
{
if ( scsiCmd->results.returnCode == kIOReturnSuccess )
{
scsiCmd->results.returnCode = (IOReturn) rc;
}
}
queue_remove( list, scsiCmd, IOSCSIParallelCommand *, nextCommand );
}
IOSCSIParallelCommand *IOSCSIParallelDevice::checkCommand( queue_head_t *list )
{
if ( queue_empty( list ) == true )
{
return 0;
}
return (IOSCSIParallelCommand *)queue_first( list );
}
IOSCSIParallelCommand *IOSCSIParallelDevice::getCommand( queue_head_t *list )
{
IOSCSIParallelCommand *scsiCmd = 0;
if ( queue_empty( list ) == false )
{
queue_remove_first( list, scsiCmd, IOSCSIParallelCommand *, nextCommand );
scsiCmd->list = 0;
}
return scsiCmd;
}
void IOSCSIParallelDevice::stackCommand( queue_head_t *list, IOSCSIParallelCommand *scsiCmd )
{
scsiCmd->list = list;
queue_enter_first( list, scsiCmd, IOSCSIParallelCommand *, nextCommand );
}
void IOSCSIParallelDevice::moveCommand( queue_head_t *fromList, queue_head_t *toList, IOSCSIParallelCommand *scsiCmd, IOReturn rc )
{
if ( rc != kIOReturnSuccess )
{
if ( scsiCmd->results.returnCode == kIOReturnSuccess )
{
scsiCmd->results.returnCode = (IOReturn) rc;
}
}
scsiCmd->list = toList;
queue_remove( fromList, scsiCmd, IOSCSIParallelCommand *, nextCommand );
queue_enter( toList, scsiCmd, IOSCSIParallelCommand *, nextCommand );
}
void IOSCSIParallelDevice::moveAllCommands( queue_head_t *fromList, queue_head_t *toList, IOReturn rc )
{
IOSCSIParallelCommand *scsiCmd;
if ( queue_empty( fromList ) == true ) return;
do
{
scsiCmd = (IOSCSIParallelCommand *)queue_first( fromList );
if ( rc != kIOReturnSuccess )
{
if ( scsiCmd->results.returnCode == kIOReturnSuccess )
{
scsiCmd->results.returnCode = (IOReturn) rc;
}
}
scsiCmd->list = toList;
queue_remove( fromList, scsiCmd, IOSCSIParallelCommand *, nextCommand );
queue_enter( toList, scsiCmd, IOSCSIParallelCommand *, nextCommand );
} while( queue_empty( fromList ) == false );
}
bool IOSCSIParallelDevice::findCommand( queue_head_t *list, IOSCSIParallelCommand *findSCSICmd )
{
IOSCSIParallelCommand *scsiCmd;
queue_iterate( list, scsiCmd, IOSCSIParallelCommand *, nextCommand )
{
if ( scsiCmd == findSCSICmd )
{
return true;
}
}
return false;
}
void IOSCSIParallelDevice::purgeAllCommands( queue_head_t *list, IOReturn rc )
{
IOSCSIParallelCommand *scsiCmd;
if ( queue_empty( list ) == true ) return;
do
{
scsiCmd = (IOSCSIParallelCommand *)queue_first( list );
deleteCommand( list, scsiCmd, rc );
finishCommand( scsiCmd );
} while( queue_empty( list ) == false );
}