agora inbox for [email protected]  
help / color / mirror / Atom feed
From: Andrew Chernow <[email protected]>
To: Merlin Moncure <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: Andrew Dunstan <[email protected]>
Cc: Alvaro Herrera <[email protected]>
Cc: Patches (PostgreSQL) <[email protected]>
Subject: Re: libpq object hooks
Date: Wed, 14 May 2008 12:02:17 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

>> I'm wondering why the hooks need names at all.  AFAICS all that
>> libpq needs to know about a hook is a callback function address
>> and a void * passthrough pointer.
> 
> 
> In question is:
> + void *
> + PQhookData(const PGconn *conn, const char *hookName)
> 
> Basically, libpqtypes has various functions that take a PGconn that
> need the private data that is stored in libpq with the connection.
> PQhookData just does simple linear search and returns the data.
> 
> [thinks]
> are you suggesting something like
> + void *
> + PQhookData(const PGconn *conn, const void *hookHandle)
> ?
> 
> I would have to take a quick look at the code with Andrew C (he'll be
> in in a bit)...but this might be doable.
> 

The hook callback functions allow the hook implementor to receive 
created/destroyed events about a PGconn and PGresult (PQreset as well).  The 
hook implementor has the option of associating some memory with either.  But, 
that memory pointer is worthless unless there is a way of referencing it at a 
later time.

HookName would not be needed if the libpq hook API only supported a single 
Object Hook to be registered per conn (or library-wide).  It was requested of us 
to allow a list of hooks per conn.  This requries a way of referencing the item.

Functions outside the hook callback functions:
- PQparamCreate needs libpq-hook-func void *PQhookData(conn, hookName)
- PQgetf needs libpq-hook-func void *PQresultHookData(res, hookName)
- Also, the "void *resultCreate(...)" hook callback implementation inside 
libpqtypes must use PQhookData on the provided conn so it can copy some 
conn.hookData properties to the result.hookData.  The created result.hookData is 
returned (one can return NULL if no hookData is needed).

I have no issue with merlin's idea of a void *handle, but that doesn't really 
change the concept at all ... just allows someone registering hooks with libpq 
to use something other than a string.  The hookName string idea feels a little 
more natural and simple.

-- 
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/



view thread (64+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: libpq object hooks
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox