store the pre-alphacomposit hook and allow it to be queried.
[AROS.git] / workbench / devs / printer / printer.c
blobf64fb43021b1fbd5976e0fa94bac317b2ab76c51
1 /*
2 * Copyright (C) 2012, The AROS Development Team. All rights reserved.
3 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
5 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
6 */
8 #include <aros/debug.h>
9 #include <aros/printertag.h>
11 #include <exec/errors.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <proto/asl.h>
17 #include <devices/printer.h>
18 #include <datatypes/datatypesclass.h>
20 #include LC_LIBDEFS_FILE
22 #include "printer_intern.h"
24 static int GM_UNIQUENAME(Init)(struct PrinterBase *PrinterBase)
26 int i;
28 D(bug("init printer.device\n"));
29 for (i = 0; i < PRINTER_UNITS; i++) {
30 InitSemaphore(&PrinterBase->pb_UnitLock[i]);
33 if ((PrinterBase->pb_DOSBase = OpenLibrary("dos.library", 35))) {
34 D(bug("initted\n"));
35 return TRUE;
38 return FALSE;
41 static int GM_UNIQUENAME(Expunge)(struct PrinterBase *PrinterBase)
43 CloseLibrary(PrinterBase->pb_DOSBase);
44 D(bug("expunged\n"));
46 return TRUE;
49 /* Opening PrinterBase creates a new struct PrinterData * device
50 * for that unit.
52 * For now, we only support one opener of a unit at a time.
54 static int GM_UNIQUENAME(OpenDevice)(struct PrinterBase *PrinterBase, union printerIO *pio, LONG unitnum, ULONG flags)
56 struct PrinterUnit *pu = NULL;
57 struct IOStdReq *io = &pio->ios;
59 D(bug("open unit %d\n", unitnum));
61 if (unitnum < 0) {
62 /* 'system' printer device */
63 io->io_Unit = (struct Unit *)PrinterBase;
64 return TRUE;
67 if (unitnum < 0 || unitnum >= PRINTER_UNITS)
68 return FALSE;
70 ObtainSemaphore(&PrinterBase->pb_UnitLock[unitnum]);
71 if ((PrinterBase->pb_Unit[unitnum] == NULL)) {
72 pu = Printer_Unit(PrinterBase,(LONG)unitnum);
73 PrinterBase->pb_Unit[unitnum] = pu;
75 ReleaseSemaphore(&PrinterBase->pb_UnitLock[unitnum]);
77 if (pu) {
78 io->io_Device = (struct Device *)pu;
79 io->io_Unit = (struct Unit *)(IPTR)unitnum;
80 io->io_Error = 0;
81 AROS_LVO_CALL3NR(void,
82 AROS_LCA(struct IORequest *,(struct IORequest *)io,A1),
83 AROS_LCA(IPTR, unitnum, D0),
84 AROS_LCA(ULONG, flags, D1),
85 struct Device *, (struct Device *)pu, 1 , dev);
86 if (io->io_Error)
87 CloseDevice((struct IORequest *)io);
88 } else {
89 io->io_Error = IOERR_OPENFAIL;
92 D(bug("io device %p (%d)\n", io->io_Device, io->io_Error));
93 return (io->io_Error == 0) ? TRUE : FALSE;
96 static int GM_UNIQUENAME(CloseDevice)(struct PrinterBase *PrinterBase, union printerIO *io)
98 return TRUE;
101 AROS_LH1(void, BeginIO,
102 AROS_LHA(struct IORequest *, io, A1),
103 struct PrinterBase *, PrinterBase, 5, Printer)
105 AROS_LIBFUNC_INIT
107 D(bug("System BeginIO: io_Command = %d\n", io->io_Command));
109 switch (io->io_Command) {
110 default:
111 io->io_Error = IOERR_NOCMD;
112 break;
115 if (!(io->io_Flags & IOF_QUICK))
116 ReplyMsg(&io->io_Message);
118 return;
120 AROS_LIBFUNC_EXIT
123 AROS_LH1(LONG, AbortIO,
124 AROS_LHA(struct IORequest *, io, A1),
125 struct PrinterBase *, PrinterBase, 6, Printer)
127 AROS_LIBFUNC_INIT
128 return IOERR_NOCMD;
129 AROS_LIBFUNC_EXIT
133 ADD2OPENDEV(GM_UNIQUENAME(OpenDevice), 0)
134 ADD2CLOSEDEV(GM_UNIQUENAME(CloseDevice), 0)
136 ADD2INITLIB(GM_UNIQUENAME(Init), 0)
137 ADD2EXPUNGELIB(GM_UNIQUENAME(Expunge), 0)