Skip to content

printer.device: unit lock, Preferences encoding, PRD_SETJOBINFO - #1966

Open
terminills wants to merge 1 commit into
aros-development-team:masterfrom
terminills:printer-device-fixes
Open

terminills wants to merge 1 commit into
aros-development-team:masterfrom
terminills:printer-device-fixes

Conversation

@terminills

Copy link
Copy Markdown
Contributor

Title: printer.device: unit lock, Preferences encoding, PRD_SETJOBINFO

Three fixes found while writing a printer.device driver (the Gutenprint port):

  1. pd_Close() released pb_UnitLock[] of the PDEV unit number from the prefs file instead of the unit the device was opened on; with a prefs file without a PDEV chunk that number was uninitialised stack ("Semaphore in an illegal state" after every print). Use the opened unit number and start the prefs from zero.
  2. Drivers got the raw PrinterTxtPrefs values in pd_Preferences, but the drivers (and AmigaOS) compare against the Preferences encoding (pitch, quality, spacing, paper size and type shifted into the flags words). Encode them as the Preferences structure defines.
  3. PRD_SETJOBINFO (CMD_NONSTD+13) with PJIA_Application/PJIA_Document lets an application say what it prints; printer.device also records the opener's command name, and passes both on to the output device with the same command, which output devices that do not know it ignore. For print queues.

Test: developer/debug/test/printer/unitlock writes ENV:SYS/printer1.prefs naming device unit 0, opens unit 1, closes it, has a second process open it again (10 s timeout) and sends PRD_SETJOBINFO; the unit uses the serial port so it runs on any machine. pc-x86_64 in QEMU on master 9802c8c: PASS: opened printer.device unit 1, PASS: a second task could open unit 1 after it was closed, PASS: PRD_SETJOBINFO accepted, UNITLOCK PASS.

Three fixes found while writing a printer driver against the device.

pd_Close() indexed pb_UnitLock[] with the PDEV unit number from the
prefs file instead of the unit the device was opened on. A printer.prefs
without a PDEV chunk (as written before PDEV existed) left that number,
and the unit name, as uninitialised stack memory in Printer_Unit(), so
closing the device obtained and released a semaphore outside the array
("Semaphore in an illegal state" twice, every time a print finished).
Use pd_UnitNumber, set from the opened unit, and start the prefs from
zero so missing chunks read as empty.

Printer prefs keep pitch, quality, spacing, paper size and paper type as
small numbers (prefs/printertxt.h: PP_ELITE 1, PS_EURO_A4 9, ...), but
struct Preferences, which printer.device fills in for the driver, holds
them in their bit positions (intuition/preferences.h: ELITE 0x400,
EURO_A4 0x90, ...). The values were copied over unconverted, so every
paper size but US Letter reached the driver as something it does not
know, and the PostScript driver refused to open with PDERR_BADDIMENSION
from its PRS_PREINIT. Shift the five fields into place; PostScript and
the skeleton driver compare against the Preferences constants throughout,
as a driver gets them.

A print queue can only show job numbers: nothing tells the output device
which program is printing what. printer.device now takes the opener's
program name when the unit is opened (its CLI command name, else its
task name), and a new command, PRD_SETJOBINFO (CMD_NONSTD + 13), lets an
application name the document (PJIA_Application, PJIA_Document tags).
Both are passed on to the output device with the same command when the
unit opens and whenever they change; output devices that do not know it
ignore it.

The test developer/debug/test/printer/unitlock writes a preferences file
for unit 1 naming device unit 0 and the serial port, opens the unit,
closes it, has a second process open it again, and sends PRD_SETJOBINFO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant