Ejemplo n.º 1
0
void memStream::Ctor_InFromOut()
{
    wxMemoryOutputStream *pMemOutStream = DoCreateOutStream();
    pMemOutStream->Write(GetDataBuffer(), DATABUFFER_SIZE);
    wxMemoryInputStream *pMemInStream = new wxMemoryInputStream(*pMemOutStream);
    CPPUNIT_ASSERT(pMemInStream->IsOk());
    CPPUNIT_ASSERT(pMemInStream->GetLength() == pMemOutStream->GetLength());
    int len = pMemInStream->GetLength();
    wxStreamBuffer *in = pMemInStream->GetInputStreamBuffer();
    wxStreamBuffer *out = pMemOutStream->GetOutputStreamBuffer();
    void *pIn = in->GetBufferStart();
    void *pOut = out->GetBufferStart();
    CPPUNIT_ASSERT(pIn != pOut);
    CPPUNIT_ASSERT(memcmp(pIn, pOut, len) == 0);
}
int main(void)
{
    UINT8   buf[1024];

    UARTConfigure(UART_MODULE_ID, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART_MODULE_ID, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART_MODULE_ID, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART_MODULE_ID, GetPeripheralClock(), 9600);
    UARTEnable(UART_MODULE_ID, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));


    //Receive and echo back mode only
    while(1)
    {
        UINT32 rx_size;
        rx_size = GetDataBuffer(buf, 1024);

        SendDataBuffer(buf, rx_size);
    }

    return -1;
}
Ejemplo n.º 3
0
wxMemoryInputStream *memStream::DoCreateInStream()
{
    wxMemoryInputStream *pMemInStream = new wxMemoryInputStream(GetDataBuffer(), DATABUFFER_SIZE);
    CPPUNIT_ASSERT(pMemInStream->IsOk());
    return pMemInStream;
}
Ejemplo n.º 4
0
PyObject* GetData(Cursor* cur, Py_ssize_t iCol)
{
    // Returns an object representing the value in the row/field.  If 0 is returned, an exception has already been set.
    //
    // The data is assumed to be the default C type for the column's SQL type.

    ColumnInfo* pinfo = &cur->colinfos[iCol];

    // First see if there is a user-defined conversion.

    int conv_index = GetUserConvIndex(cur, pinfo->sql_type);
    if (conv_index != -1)
        return GetDataUser(cur, iCol, conv_index);

    switch (pinfo->sql_type)
    {
    case SQL_WCHAR:
    case SQL_WVARCHAR:
    case SQL_WLONGVARCHAR:
    case SQL_CHAR:
    case SQL_VARCHAR:
    case SQL_LONGVARCHAR:
    case SQL_GUID:
    case SQL_SS_XML:
#if PY_VERSION_HEX >= 0x02060000
    case SQL_BINARY:
    case SQL_VARBINARY:
    case SQL_LONGVARBINARY:
#endif
        return GetDataString(cur, iCol);

#if PY_VERSION_HEX < 0x02060000
    case SQL_BINARY:
    case SQL_VARBINARY:
    case SQL_LONGVARBINARY:
        return GetDataBuffer(cur, iCol);
#endif

    case SQL_DECIMAL:
    case SQL_NUMERIC:
    {
        if (decimal_type == 0)
            break;

        return GetDataDecimal(cur, iCol);
    }

    case SQL_BIT:
        return GetDataBit(cur, iCol);

    case SQL_TINYINT:
    case SQL_SMALLINT:
    case SQL_INTEGER:
        return GetDataLong(cur, iCol);

    case SQL_BIGINT:
        return GetDataLongLong(cur, iCol);

    case SQL_REAL:
    case SQL_FLOAT:
    case SQL_DOUBLE:
        return GetDataDouble(cur, iCol);


    case SQL_TYPE_DATE:
    case SQL_TYPE_TIME:
    case SQL_TYPE_TIMESTAMP:
        return GetDataTimestamp(cur, iCol);

    case SQL_SS_TIME2:
        return GetSqlServerTime(cur, iCol);
    }

    return RaiseErrorV("HY106", ProgrammingError, "ODBC SQL type %d is not yet supported.  column-index=%zd  type=%d",
                       (int)pinfo->sql_type, iCol, (int)pinfo->sql_type);
}
Ejemplo n.º 5
0
bool 
com_ximeta_driver_NDASProtocolTransport::SendSCSICommand (
														  SCSITaskIdentifier 	request,
														  SCSIServiceResponse * serviceResponse,
														  SCSITaskStatus * 		taskStatus 
														  )
{	
	UInt8							commandLength		= 0;
	bool							commandProcessed	= true;
	com_ximeta_driver_NDASSCSICommand	*NDCmd_ptr			= NULL;
	SCSICommand						scsiCommand;
	
	DbgIOLog(DEBUG_MASK_DISK_TRACE, ("Entered. Request %p\n", request));
	
	*serviceResponse	= kSCSIServiceResponse_Request_In_Process;
	*taskStatus			= kSCSITaskStatus_No_Status;
	
	commandLength = GetCommandDescriptorBlockSize ( request );
	
#if 0
	SCSICommandDescriptorBlock		cdb					= { 0 };
	
	DbgIOLog(DEBUG_MASK_DISK_WARNING, ("Data Transfer Request %lld\n", GetRequestedDataTransferCount( request )));
	
	GetCommandDescriptorBlock ( request, &cdb );
	
	if ( commandLength == kSCSICDBSize_6Byte )
	{
		
		DbgIOLog(DEBUG_MASK_DISK_WARNING, ("cdb = %02x:%02x:%02x:%02x:%02x:%02x\n", cdb[0], cdb[1],
										  cdb[2], cdb[3], cdb[4], cdb[5] ));
		
	}
	
	else if ( commandLength == kSCSICDBSize_10Byte )
	{
		
		DbgIOLog(DEBUG_MASK_DISK_WARNING, ("cdb = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", cdb[0],
										  cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8],
										  cdb[9] ));
		
	}
	
	else if ( commandLength == kSCSICDBSize_12Byte )
	{
		
		DbgIOLog(DEBUG_MASK_DISK_WARNING, ("cdb = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", cdb[0],
										  cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8],
										  cdb[9], cdb[10], cdb[11] ));
		
	}
#endif
	
	request->retain();

	if ( isInactive ())
	{
		DbgIOLog(DEBUG_MASK_DISK_WARNING, ("Device is inactive.\n"));
		
		// device is disconnected - we can not service command request
		*serviceResponse = kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE;
		commandProcessed = false;
		
		goto exit;
	}
	
	// Check Workable.
	if (!fProvider 
		|| !fProvider->isWorkable()) {
		
		DbgIOLog(DEBUG_MASK_DISK_WARNING, ("Device is not workable.\n"));

		// device is disconnected - we can not service command request
		*serviceResponse = kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE;
		commandProcessed = false;
		
		goto exit;		
	}
	
	// Check Busy.
//	if (fProvider->isBusy() )
	if (fBusy)
	{
		DbgIOLog(DEBUG_MASK_DISK_INFO, ("Busy!!!\n"));

		*serviceResponse = kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE;
		commandProcessed = false;
		goto exit;
	}
	
	// Allocate Command.
	/*
	NDCmd_ptr = OSDynamicCast(com_ximeta_driver_NDASSCSICommand, 
							  OSMetaClass::allocClassWithName(NDAS_SCSI_COMMAND_CLASS));
    
    if(NDCmd_ptr == NULL || !NDCmd_ptr->init()) {
        DbgIOLog(DEBUG_MASK_DISK_ERROR, ("failed to alloc command class\n"));
		
		if (NDCmd_ptr) {
			NDCmd_ptr->release();
		}
		
		*serviceResponse = kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE;
		commandProcessed = true;
		goto exit;
    }
	*/
	NDCmd_ptr = (com_ximeta_driver_NDASSCSICommand*)fCommandPool->getCommand(false);
	
	if (NDCmd_ptr == NULL) {

		DbgIOLog(DEBUG_MASK_DISK_ERROR, ("No Commands.\n"));

		*serviceResponse = kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE;
		commandProcessed = true;
		goto exit;
	}
	
	NDCmd_ptr->init();
	
	memset(&scsiCommand, 0, sizeof(SCSICommand));
	
	scsiCommand.scsiTask = request;
//	scsiCommand.targetNo = fProvider->targetNo();
	scsiCommand.LogicalUnitNumber = GetLogicalUnitNumber( request );
	GetCommandDescriptorBlock ( request, &scsiCommand.cdb );
	scsiCommand.cdbSize = commandLength;
	scsiCommand.MemoryDescriptor_ptr = GetDataBuffer( request );
	scsiCommand.BufferOffset = GetDataBufferOffset( request );
	scsiCommand.RequestedDataTransferCount = GetRequestedDataTransferCount( request );
	scsiCommand.DataTransferDirection = GetDataTransferDirection( request );
//	scsiCommand.BlockSize = fProvider->blocksize();
		
	NDCmd_ptr->setCommand(&scsiCommand);
		
	//	CriticalCommandSubmission(NDCmd_ptr, &commandProcessed);
	
	fBusy = true;
	
	fCommandGate->runAction ( CriticalCommandSubmissionStatic, NDCmd_ptr);
	
	
	//fXiCommandGate->runCommand((void *)kNDASProtocolTransportRequestSendCommand, NDCmd_ptr, &commandProcessed);
	
exit:
		
	if ( kSCSIServiceResponse_Request_In_Process != *serviceResponse ) {
		
		DbgIOLog(DEBUG_MASK_DISK_INFO, ("ERROR Service Response = %x, task = %p\n", *serviceResponse, request));
		
		request->release();
		
		if(NDCmd_ptr) {
			NDCmd_ptr->release();
		}
	}
	
	DbgIOLog(DEBUG_MASK_DISK_INFO,("exit, Service Response = %x, task = %p\n", *serviceResponse, request));
	
	return commandProcessed;
	
}
SCSIServiceResponse
com_apple_dts_SCSIEmulatorAdapter::ProcessParallelTask ( SCSIParallelTaskIdentifier parallelRequest )
{
	// Not all of these may be required.  Unused ones are commented out to avoid compiler warnings
	SCSITargetIdentifier		targetID				= GetTargetIdentifier(parallelRequest);
//	SCSITaskIdentifier			task					= GetSCSITaskIdentifier(parallelRequest);
//	SCSITaggedTaskIdentifier	taggedTask				= GetTaggedTaskIdentifier(parallelRequest);
	SCSILogicalUnitNumber		lun						= GetLogicalUnitNumber(parallelRequest);
//	SCSITaskAttribute			taskAttribute			= GetTaskAttribute(parallelRequest);
	
	UInt8						transferDir				= GetDataTransferDirection(parallelRequest);
	UInt64						transferSize			= GetRequestedDataTransferCount(parallelRequest);
	IOMemoryDescriptor *		transferMemDesc			= GetDataBuffer(parallelRequest);
//	UInt64						transferMemDescOffset   = GetDataBufferOffset(parallelRequest);

	// Get the CDB
	UInt8						cdbLength				= GetCommandDescriptorBlockSize(parallelRequest);
	SCSICommandDescriptorBlock  cdbData;
	
	SCSITaskStatus 				scsiStatus 				= kSCSITaskStatus_GOOD;
	UInt64 						dataLen 				= 0;

	UInt8						senseBuffer[kSenseBufferLen];
	UInt64						senseBufferLen 			= sizeof(senseBuffer);

	com_apple_dts_SCSIEmulator *emulator = (com_apple_dts_SCSIEmulator *)mTargetsArray->getObject(targetID);

	// Fail if we don't have a SCSI emulator backing this target
	if (!emulator) {
		IOLog("ProcessParallelTask: ABORT - !emulator for targetID = %ud\n", targetID);
		goto failure_exit;
	}

	// Fail if we're supposed to transfer data and don't have a data buffer
	if (!transferMemDesc && (transferDir != kSCSIDataTransfer_NoDataTransfer)) {
		IOLog("ProcessParallelTask: ABORT - !transferMemDesc && (transferDir != kSCSIDataTransfer_NoDataTransfer) - %p and %d\n", transferMemDesc, transferDir);
		goto failure_exit;
	}

	// Fail if we don't have a large enough CDB buffer set aside
	if (cdbLength > sizeof(cdbData)) {
		IOLog("ProcessParallelTask: ABORT - cdbLength > sizeof(cdbData) - %d vs. %d\n", cdbLength, sizeof(cdbData));
		goto failure_exit;
	}

	if (!GetCommandDescriptorBlock(parallelRequest, &cdbData)) {
		IOLog("ProcessParallelTask: ABORT - !GetCommandDescriptorBlock(parallelRequest, &cdbData)\n");
		goto failure_exit;
	}

	if (transferMemDesc && (transferDir != kSCSIDataTransfer_NoDataTransfer)) {
#if 0
		// This block isn't necessary as memory descriptors passed in are always autoprepared for us.
		// Remember: Any memory descriptors allocated and used internally should be prepared before sending
		// or receiving data to/from real hardware
		IOReturn res = transferMemDesc->prepare();
		if (res != kIOReturnSuccess) {
			goto failure_exit;
		}
#endif

		// We are guaranteed that the memory descriptor will always be sized large enough by
		// by SAM/STUC to hold the transfer size requested
		dataLen = transferSize;
	}

	// This is where the "real" work should get done by your hardware.  The individual parameters
	// are being sent instead of just the task reference as the task is opaque by design and
	// the getter/setter methods are protected and available within this class, but not within
	// the emulator itself.
	emulator->sendCommand(cdbData, cdbLength, transferMemDesc, &dataLen, lun, &scsiStatus, senseBuffer, &senseBufferLen);

	// Real hardware should be doing the task processing internally and providing responses
	// via an interrupt mechanism.  IOSCSIParallelInterfaceController expects this and you
	// should always do your task completions from the workloop thread.
	CompleteTaskOnWorkloopThread(parallelRequest, true, scsiStatus, dataLen, senseBuffer, senseBufferLen);
	return kSCSIServiceResponse_Request_In_Process;

failure_exit:
	CompleteTaskOnWorkloopThread(parallelRequest, false, scsiStatus, dataLen, senseBuffer, senseBufferLen);
	return kSCSIServiceResponse_Request_In_Process;
}