michaelrsweet / pappl

PAPPL - Printer Application Framework
https://www.msweet.org/pappl
Apache License 2.0
309 stars 49 forks source link

Allow building driver list and registering it in system_cb, so that list build can get logged #42

Closed tillkamppeter closed 3 years ago

tillkamppeter commented 3 years ago

Is your feature request related to a problem? Please describe. I am creating a PostScript Printer Application which should support all PostScript printers which were supported in the Linux distributions. This means that it will contain the 1000s of manufacturer-supplied PostScript PPD files ("foomatic-db" package), each one being a driver in PAPPL terms. So a list of 1000s of drivers has to be built, where easily errors can happen. Therefore I want the Printer Application to start logging before the building of the driver list starts and to start logging I have to call papplMainloop(). I call it without driver list (0 drivers, no callback) and call papplSystemSetDrivers() from within the system_cb. Problem is that papplMainloop() calls the system_cb in the beginning and afterwards it calls papplSystemSetDrivers() with the empty driver list it got supplied. It should omit the papplSystemSetDrivers() call with an empty/invalid driver list, this way one can "manually" call papplSystemSetDrivers() somewhere else, like for example in system_cb.

Describe the solution you'd like The following patch solves the problem. Driver registration (papplSystemSetDrivers()) is only called if the papplMainloop() call actually specifies a driver list and a driver callback. If omitting these, one can register the drivers later and so build the driver list with the system available and so the possibility to log the list building process. Pre-defining the driverlist before starting the main loop and specifying the driver list and callback in the papplMainloop() is still possible.

--- a/pappl/mainloop-subcommands.c
+++ b/pappl/mainloop-subcommands.c
@@ -632,7 +632,8 @@ _papplMainloopRunServer(
     papplSystemSetFooterHTML(system, footer_html);

   // Set the driver info...
-  papplSystemSetDrivers(system, num_drivers, drivers, driver_cb, data);
+  if (num_drivers && drivers && driver_cb)
+    papplSystemSetDrivers(system, num_drivers, drivers, driver_cb, data);

   // Listen for connections...
   papplSystemAddListeners(system, _papplMainloopGetServerPath(base_name, sockna
tillkamppeter commented 3 years ago

This is the source of the PostScript Printer Application: system_cb calls ps_setup(), ps_setup() builds the driver list and registers it calling papplSystemSetDrivers(). ps-printer-app.c.txt

michaelrsweet commented 3 years ago

@tillkamppeter Sounds like a reasonable solution, will make the change.

michaelrsweet commented 3 years ago

[master b03bdb5] Allow mainloop to set drivers from system callback (Issue #42)

tillkamppeter commented 3 years ago

Thank you very much. It works now.