1994.02.14 11:03 "Error/warning handlers in libtiff", by Erik Corry
As others have mentioned, there are of course ways to override the default action. The real point, though, is that you would like to formulate the new way of performing an interface-action in such a way that it can be gracefully integrated with the libtiff proper. The reason isn't just for other host's sake; if your code remains compatible with the public libtiff, then when improvements/new compression schemes (such as the long-awaited JPEG-in-TIFF) become part of libtiff you will not have to deal with so much grief.
While we are on the subject, there is a fairly simple change to the Tiff library, which I have not yet had time to do, but which would improve the usability of the library in applications with several threads.
The libtiff has a generally exemplary clean interface, but...
At the moment, the only way of getting information other than the error message itself into the error handler is through global variables. For example the infos allowing the error handler to pop up a window in X (application context, parent window, application name for the window manager bar) must be accessed by the error handler through global variables. This is generally undesirable and obviously precludes having several app-contexts. In the application in which I use the libtiff at the moment, there is a second problem, as the libtiff is called from signal handlers. (As well as from the User Interface, X-Windows code). It is very difficult to know what to do about error messages since X is not callable from a signal handler, and X is also not callable from a library which in turn uses the libtiff, but is not X-based. It all becomes very ugly.
My proposed solution would be:
- To allow the user of the library to give a void pointer as error-handler- client-data. When the error handler is called, it is given this void pointer which is cast into a pointer to a structure containing all the context the error handler needs. This technique, under the name of client_data, or closure works very well for X-Windows allowing you to avoid global variables, with the problems they bring with them.
- To allow the error handler and closure to be given on a per-tiff basis, ie as parameters to the 'open' functions. This means storing the values in the TIFF structure instead of in global variables. For backwards binary compatibility, the old functions could be adapted to still produce the expected results.
As I said, I have not yet had time to make these changes. Would they be integrated into the library if I did?
Erik Corry, Skagerrakstr. 2, D-79100 Freiburg, +49 761 406637