示例#1
0
static status_t
usb_printer_write(void *cookie, off_t position, const void *buffer,
	size_t *length)
{
	if (buffer == NULL || length == NULL)
		return B_BAD_VALUE;

	TRACE("write(%" B_PRIdOFF ", %" B_PRIuSIZE ")\n", position, *length);
	printer_device *device = (printer_device *)cookie;
	mutex_lock(&device->lock);
	if (device->removed) {
		*length = 0;
		mutex_unlock(&device->lock);
		return B_DEV_NOT_READY;
	}

	status_t result = usb_printer_transfer(device, false, (void*)buffer,
		length);

	mutex_unlock(&device->lock);
	if (result == B_OK) {
		TRACE("write successful with %" B_PRIuSIZE " bytes\n", *length);
		return B_OK;
	}

	*length = 0;
	TRACE_ALWAYS("write fails with 0x%08" B_PRIx32 "\n", result);
	return result;
}
示例#2
0
static status_t
usb_printer_read(void *cookie, off_t position, void *buffer, size_t *length)
{
	if (buffer == NULL || length == NULL)
		return B_BAD_VALUE;

	TRACE("read(%lld, %ld)\n", position, *length);
	printer_device *device = (printer_device *)cookie;
	mutex_lock(&device->lock);
	if (device->removed) {
		*length = 0;
		mutex_unlock(&device->lock);
		return B_DEV_NOT_READY;
	}

	status_t result = usb_printer_transfer(device, true, buffer, length);

	mutex_unlock(&device->lock);
	if (result == B_OK) {
		TRACE("read successful with %ld bytes\n", *length);
		return B_OK;
	}

	*length = 0;
	TRACE_ALWAYS("read fails with 0x%08lx\n", result);
	return result;
}