GLib Proposal: internal destroy func/data for GHook



Problem:

I'm implementing an IOChannel.  When the user removes a watch, the
appropriate hook gets destroyed, but I (the IOChannel implementor) have no
good way of knowing this.  I want to know this so I can update my internal
bookkeeping data (which the Win32 port of GNet needs).  I could set the
destroy func and user data on the hook, but then it will break
source_remove_by_user_data.  (It won't break the user's destroy callback
in general because I can still call it in my destroy callback).

Or, is there something I'm missing?


Solution:

Add an internal_destroy_func and internal_destory_user_data to GHook.  
IOChannel implementors may use it, g_source_add may not use it.  Call it
in hook_destroy_link.  Drawbacks: larger GHook, slower hook_destroy_link.

Or, is there a better way?


Workaround:

For each add_watch call, create two hooks.  The first is the 'real hook'
and we return the tag to this hook.  But, we use our destroy and user
data.  Our destroy calls the user's destroy then cleans up.  The second is
the 'dummy hook'.  It has our second destroy but the user's user_data.  
It's only purpose is to catch source_remove_by_user_data - it does not
handle IO.  Our second destroy calls the user's destroy and cleans up
(including getting rid of the first hook).  Ultimately our callbacks get
called so we can update our data and everything works.

Or, is there a less gross hack?

I can submit a patch against HEAD if this sounds good.


Thanks,
David


-- 
      __          _    __  David Helder - University of Michigan
  ___/ /__ __  __(_)__/ /  dhelder umich edu
 / _  / _ `/ |/ / / _  /   http://www.eecs.umich.edu/~dhelder
 |_,_/|_,_/|___/_/|_,_/    Jungle Monkey: http://www.junglemonkey.net





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]