IOFWAsyncStreamCommand.cpp [plain text]
#include <IOKit/firewire/IOFWCommand.h>
#include <IOKit/firewire/IOFireWireController.h>
#include <IOKit/firewire/IOFireWireNub.h>
#include <IOKit/firewire/IOLocalConfigDirectory.h>
#include <IOKit/assert.h>
#include <IOKit/IOSyncer.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOCommand.h>
#pragma mark -
OSDefineMetaClassAndStructors(IOFWAsyncStreamCommand, IOFWCommand)
OSMetaClassDefineReservedUnused(IOFWAsyncStreamCommand, 0);
OSMetaClassDefineReservedUnused(IOFWAsyncStreamCommand, 1);
OSMetaClassDefineReservedUnused(IOFWAsyncStreamCommand, 2);
OSMetaClassDefineReservedUnused(IOFWAsyncStreamCommand, 3);
#pragma mark -
bool IOFWAsyncStreamCommand::initAll(
IOFireWireController * control,
UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon)
{
bool success = true;
success = IOFWCommand::initWithController(control);
if( success )
{
fMaxRetries = kFWCmdDefaultRetries;
fCurRetries = fMaxRetries;
fMemDesc = hostMem;
fComplete = completion;
fSync = completion == NULL;
fRefCon = refcon;
fTimeout = 1000*125; if(hostMem)
fSize = hostMem->getLength();
fGeneration = generation;
fChannel = channel;
fSyncBits = sync;
fTag = tag;
fSpeed = speed;
fSize = size;
fFailOnReset = false;
}
return success;
}
void IOFWAsyncStreamCommand::free()
{
IOFWCommand::free();
}
IOReturn IOFWAsyncStreamCommand::reinit(
UInt32 generation,
UInt32 channel,
UInt32 sync,
UInt32 tag,
IOMemoryDescriptor * hostMem,
UInt32 size,
int speed,
FWAsyncStreamCallback completion,
void * refcon)
{
if(fStatus == kIOReturnBusy || fStatus == kIOFireWirePending)
return fStatus;
fComplete = completion;
fRefCon = refcon;
fMemDesc=hostMem;
if(fMemDesc)
fSize=fMemDesc->getLength();
fSync = completion == NULL;
fCurRetries = fMaxRetries;
fGeneration = generation;
fChannel = channel;
fSyncBits = sync;
fTag = tag;
fSpeed = speed;
fSize = size;
return fStatus = kIOReturnSuccess;
}
IOReturn IOFWAsyncStreamCommand::complete(IOReturn status)
{
IOFWCommand::fMembers->fCompletionStatus = status;
if( fStatus == kIOFireWireCompleting )
{
return kIOReturnSuccess;
}
fStatus = kIOFireWireCompleting;
fControl->handleAsyncCompletion( this, status );
IOReturn completion_status = IOFWCommand::fMembers->fCompletionStatus;
removeFromQ();
if( (completion_status == kIOFireWireBusReset) && !fFailOnReset)
{
if(fControl->scanningBus())
{
setHead(fControl->getAfterResetHandledQ());
return fStatus = kIOFireWirePending; }
}
fStatus = completion_status;
if(fSync)
fSyncWakeup->signal(completion_status);
else if(fComplete)
(*fComplete)(fRefCon, completion_status, fControl, this);
return completion_status;
}
void IOFWAsyncStreamCommand::gotAck(int ackCode)
{
if (ackCode == kFWAckComplete )
complete( kIOReturnSuccess );
else
complete( kIOReturnTimeout );
}
IOReturn IOFWAsyncStreamCommand::execute()
{
IOReturn result;
fStatus = kIOReturnBusy;
result = fControl->asyncStreamWrite(fGeneration,
fSpeed, fTag, fSyncBits, fChannel,fMemDesc,0,fSize, this);
IOReturn status = fStatus;
if(result != kIOReturnSuccess)
{
retain();
complete(result);
status = fStatus;
release();
}
return status;
}