[liblouis-liblouisxml] Re: Unsure how to do a change to logging

  • From: "Michael Whapples" <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "mwhapples@xxxxxxx" for DMARC)
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Thu, 22 May 2014 08:51:20 +0100

Hello,
The difficulty is for the initial state, if an application never calls lbu_registerLogCallback (lbu_registerLogCallback being what I am calling the liblouisutdml function for registering a callback).

The initial default callback in liblouis is set in global code like this:
static logCallback = defaultLogCallback;

The only way an external library or application can alter the callback in liblouis is to call lou_registerLogCallback. However I believe a function call in C can only be made from within another function. This leads to the question of how liblouisutdml should change the logging callback in liblouis to the one in liblouisutdml, before any liblouisutdml function call is made?

So until lou_registerLogCallback is called, liblouis will be using its own default logging callback, and liblouisutdml will be using its own default logging callback (IE. there will be two different logging callbacks in use in different places,). If these two default callbacks try to write to one stream then we get the issue of resource access.

If liblouisutdml had a function which must be called before any other function in liblouisutdml, then placing a call to lou_registerLogCallback could be done there. However liblouisutdml has no such entry/initialisation function.

Another option is if liblouisutdml had an initialisation function which gets called by any public API function if liblouisutdml is not initialised, but again liblouisutdml has no such initialisation function.

In Java I would use a static initialiser, but C has no such concept.

What I seem to be left with is that every public liblouisutdml function should have a call to a function to check and set the default callback. If taking this route I probably would actually structure it as a initialisation function and look at refactoring liblouisutdml to migrate other potential initialisation code into such a function.

Does this make it clear where the difficulty is?

Michael Whapples
On 21/05/2014 19:13, Keith Creasy wrote:
Michael.

I may need to look at your implementation but I don't understand why you'd ever end up 
with more than one component trying to write to the same output stream. Is 
"handler" in this case what you are calling the callback function or is it an 
output stream?

LibLouis would use its default handler unless LibLouisUTDML or some other 
module registered a different one. If LibLouisUTDML registers a callback then 
all of LibLouis' messages would go through the LibLouisUTDML callback, in this 
case LibLouisUTDML default.
BrailleBlaster adds another layer, registering a callback in LibLouisUTDML and 
so we are now using BrailleBlaster's default.

When LibLouis generates a log message it calls the callback function in 
LlibLouisUTDML. The function in LouisUTDML then calls the BrailleBlaster 
callback. BrailleBlaster writes the message to an output stream.


-----Original Message-----
From: liblouis-liblouisxml-bounce@xxxxxxxxxxxxx 
[mailto:liblouis-liblouisxml-bounce@xxxxxxxxxxxxx] On Behalf Of Michael Whapples
Sent: Wednesday, May 21, 2014 1:15 PM
To: liblouis-liblouisxml@xxxxxxxxxxxxx
Subject: [liblouis-liblouisxml] Unsure how to do a change to logging

Hello,
In changing the logging so that lou_log and lou_logPrint are not public, I have 
hit a difficulty.

The problem is that in liblouisutdml, how I set a default log handler?
This might seem initially simple, just do it in the same way as in liblouis. 
This however is not enough, it sets a default handler in liblouisutdml but not 
in liblouis.

You may ask so what is the problem with that? It means that should someone set 
a file name for the default log handler (eg.
lbu_logFilename), this gets set on liblouisutdml but ont on liblouis.
Having two handlers accessing one file (one handler in liblouis and one in 
liblouisutdml) might cause file access problems.

What I need is a C version of a static initialiser (think of static 
initialisers in Java) where I could call lou_registerLogCallback(NULL) from 
liblouisutdml.

Failing that, I can only see two possible options:
1. Find every public function call in liblouisutdml and do a check/register 
there. Risk being one will get missed and may become a maintanence issue for 
the longer term.
2. The shared library option I suggested for logging code, then there is only a 
single storing of the registered callback.

Michael Whapples
For a description of the software, to download it and links to project pages go 
to http://www.abilitiessoft.com
For a description of the software, to download it and links to
project pages go to http://www.abilitiessoft.com

For a description of the software, to download it and links to
project pages go to http://www.abilitiessoft.com

Other related posts: