Subject: A mailbox driver initialization function.

From: "Rubinstein, Dmitry" <[email-masked]>
Date: Wed, 24 Mar 1999 15:54:26 +0200

Hi!

I'd like to add a function (two actually) to the interface of the mailbox
driver.
As it happens, I have a need to perform an initialization operations on the
mailbox driver. I could have done that in driver_open, but it is extremely
inconvinient. I'd rather have a function driver_init(), that is called on
startup and driver_uninit(), that is called before the termination (but
after close()). Is it a reasonable request for those to be added to the
DRIVER structure?

--
Dmitry Rubinstein  <*>

Home: (972)-8-8647229
Cell: (972)-53-428979
[email-masked]
http://www.wisdom.weizmann.ac.il/~dimrub
-- 
------------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/imap/c-client-list.html
------------------------------------------------------------------

---

From: Mark Crispin <[email-masked]>
Date: Wed, 24 Mar 1999 08:43:07 -0800 (PST)

On Wed, 24 Mar 1999 15:54:26 +0200, Rubinstein, Dmitry wrote:
> inconvinient.

This is the typical way that this is done.  In either the open method, or
perhaps in a common subroutine (e.g. "convert mailbox name to driver-specific
identifier"), do something like:
	static int once = -1;
	 . . .

	if (!++once) {
	  ... do once-only initialization code...
	}

Take a look at how mh.c initializes the mh_path string.

Another way is to add a call to the linkage.c module that is generated by the
makefile.

> I'd rather have a function driver_init(), that is called on

It's reasonable, but the cost of doing it probably exceeds the benefits.

The "startup" hook is easy enough to do in the driver (e.g. the once-only
example above) as above.  This has the advantage of being completely self
contained in the driver, without requiring changes to all the other drivers
which don't need such startup code.

The "termination" hook has a different problem; there is no termination code
in c-client at all, other than a fatal halt.  What this means is that even if
we put in a termination method, there's no reason to expect that any existing
c-client applications would ever call it.  So it wouldn't buy anything other
than for your program (since presumably your program would know to call it).
But in that case, you could just call the driver termination code yourself.

Another possibility is to have, in the driver, a static that is a count of the
open mailstreams for that driver.  This is a variation of the "once" technique
that I demonstrated above, but this time, we have the driver's close method
decrement the value.  There's a few other things that you'll need to deal
with, such as what to do if list/lsub/create/delete/rename/etc. need to have
the driver in initialized state and keeping things right.  But that's not
anything that should unduly distress a clever programmer.