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
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
)
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))) {
41 static int GM_UNIQUENAME(Expunge
)(struct PrinterBase
*PrinterBase
)
43 CloseLibrary(PrinterBase
->pb_DOSBase
);
49 /* Opening PrinterBase creates a new struct PrinterData * device
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
));
62 /* 'system' printer device */
63 io
->io_Unit
= (struct Unit
*)PrinterBase
;
67 if (unitnum
< 0 || unitnum
>= PRINTER_UNITS
)
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
]);
78 io
->io_Device
= (struct Device
*)pu
;
79 io
->io_Unit
= (struct Unit
*)(IPTR
)unitnum
;
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
);
87 CloseDevice((struct IORequest
*)io
);
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
)
101 AROS_LH1(void, BeginIO
,
102 AROS_LHA(struct IORequest
*, io
, A1
),
103 struct PrinterBase
*, PrinterBase
, 5, Printer
)
107 D(bug("System BeginIO: io_Command = %d\n", io
->io_Command
));
109 switch (io
->io_Command
) {
111 io
->io_Error
= IOERR_NOCMD
;
115 if (!(io
->io_Flags
& IOF_QUICK
))
116 ReplyMsg(&io
->io_Message
);
123 AROS_LH1(LONG
, AbortIO
,
124 AROS_LHA(struct IORequest
*, io
, A1
),
125 struct PrinterBase
*, PrinterBase
, 6, Printer
)
133 ADD2OPENDEV(GM_UNIQUENAME(OpenDevice
), 0)
134 ADD2CLOSEDEV(GM_UNIQUENAME(CloseDevice
), 0)
136 ADD2INITLIB(GM_UNIQUENAME(Init
), 0)
137 ADD2EXPUNGELIB(GM_UNIQUENAME(Expunge
), 0)