$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] Compile error OSX Callback problem for
From: Marshall Clow (marshall_at_[hidden])
Date: 2009-01-04 12:57:46
Bill McLean wrote:
>Marshall,
>
>Thanks for the reply. You have touched upon an issue that I'm not sure how
>to solve.
>
>The general problem is how to use boost::function and boost::bind to
>register a member callback function for a c style library.
>
>A proxy function that has signature of the c callback function and the
>correct instance of the class containing the member function to call.
>
>Any thoughts or approaches to solve it.
I don't think it's possible to do so in a type-safe manner.
The problem is that deep inside the (Mac OS X) file system, there's 
some code that looks like this:
        push <param1>
        push <param2>
        ...
        push <param6>
        jsr  (callback fn)
And that just won't work with boost::function or boost::bind expressions.
You can do it using a "trampoline function", but again, w/o type safety:
//	psuedo code
void FSEventStreamTrampoline ( < params > ) {
        boost::function< void ( <param types ) > cb = clientCallBackInfo;
        return cb ( params );
        }
.....
      callBack = boost::bind(&fsmon :: osx::detail::FSEventTriggered, 
this, _1, _2, _3, _4, _5, _6);
      streamRef = FSEventStreamCreate(NULL,
                         FSEventStreamTrampoline,
                         &callBack,
                         pathsToWatch,
                         kFSEventStreamEventIdSinceNow,
                         LATENCY,
                         kFSEventStreamCreateFlagNone
                     );
and you have to package up the information that you previously passed 
as "callbackInfo".
This may not work anyway, since I'm mixing boost::function and 
boost::bind here - but you get the idea.
-- -- Marshall Marshall Clow Idio Software <mailto:marshall_at_[hidden]> It is by caffeine alone I set my mind in motion. It is by the beans of Java that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning. It is by caffeine alone I set my mind in motion.