Understanding GHook (tutorial? example code?)

Dears,

I came across GHook, and it looks vaguely useful for some code I’m working on.
However, I could not yet find an introductional documentation on the subject.
Is there any? Or a tutorial or example code?
The existing usage of GHook, e.g. in Evolution, is not easy to understand for me.

Many thanks in advance!

It should be pretty self-explanitory; what is it you don’t understand about it?

I’ve never used it before, but just by glancing it seems to be equivalent to a signal-callback framework. You create a GHookList, add GHook instances (functions with data) and invoke them with g_hook_invoke ().

Yes, that is what I believe to understand, too :wink:

What confuses me, is that there are many more functions, e.g.
“marshalling”. How are hooks related to marshalling?

Also, GHook seems to be more advanced than a simple list of hook
functions, e.g. hooks can be invalidated somehow and there are
“check functions”.

All that might be self-explanitory, but not to me…

I wonder, whether I can use (abuse?) GHook for what I need:

  • always a pair of hooks, one for setup, one for freeing
    “something”
  • the pair of hooks need to share some data, e.g. a resource
    id, but that depends on the hook
  • the hooks should work in reverse order, like a stack

I probably will just create two GHookLists and write a wrapper,
that always adds hooks to both lists, one append, one prepend.
I don’t know yet, how both hooks can share data, though.

Any idea?

“Marshalling” is when you take a generic function pointer and wrap all the arguments and return value in a GValue data type, so you can call the function across programming language barriers—e.g. signals marshal their emission so you can connect to a signal defined in C with a callback defined in Python, or JavaScript.

GHook is like signals, except it does not type its payloads, and it’s not bound to an instance type.

To be quite honest, there’s really little reason to use GHook and GHookList, these days; you’re just as well served as using a simple list of function pointers.

Thanks to both of you for the help!

And yes, for my simple use case, two lists of function pointers
is sufficient.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.