Compile error OSX Callback problem for FSEventsCallback
I'm trying to code up a FSEvent callback using a member function. I may be suffering from a case of the post holiday stupids :) I am using both the boost::bind and boost::function libraries. I have the following declaration for declaring the signature of the FSEventCallback: typedef boost::function<void ( ConstFSEventStreamRef streamRef, // _1 void *clientCallBackInfo, // _2 size_t numEvents, // _3 void *eventPaths, // _4 const FSEventStreamEventFlags eventFlags[], // _5 const FSEventStreamEventId eventIds[] // _6 )> FSEventCallbackT; The above typedef has been derived from the OSX FSEvent API definition for the FSEventStreamCallback: typedef void ( *FSEventStreamCallback)( ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[] ); The skeleton of the struct that has the member function that is to be the call back is defined as: struct osx::detail { // Callback type definition static const CFAbsoluteTime LATENCY = 2.0; static const unsigned BUF_SIZE = 32768; CFStringRef pathToWatch; CFArrayRef pathsToWatch; FSEventStreamRef streamRef; void *callbackInfo; CFRunLoopRef mainLoop; boost::mutex event_mutex; typedef boost::mutex::scoped_lock lock_type; FSEventCallbackT callBack; // public methods detail( const boost::filesystem::path& base_path ); ~detail() { stop(); } void stop(); void FSEventTriggered( ConstFSEventStreamRef streamRef, // _1 void *clientCallBackInfo, // _2 size_t numEvents, // _3 void *eventPaths, // _4 const FSEventStreamEventFlags eventFlags[], // _5 const FSEventStreamEventId eventIds[] // _6 ); item get_item(); }; In the constructor I get a single compile error in the call to FSEventStreamCreate: osx::detail::detail( const boost::filesystem::path& base_path ) : base_path(base_path), stopped(false), pathToWatch(CFStringCreateWithCString(NULL,base_pa th.string().c_str(), kCFStringEncodingUTF8)), pathsToWatch(CFArrayCreate(NULL, (const void **) &pathToWatch, 1, NULL)) { callBack = boost::bind(&fsmon :: osx::detail::FSEventTriggered, this, _1, _2, _3, _4, _5, _6); streamRef = FSEventStreamCreate(NULL, &callBack, callbackInfo, pathsToWatch, kFSEventStreamEventIdSinceNow, LATENCY, kFSEventStreamCreateFlagNone ); ... } /Users/bill/ardev/CurrentDev/InternalLibs/fsmon/osxExample.cpp:111: error: cannot convert 'FSEventCallbackT*' to 'void (*)(const __FSEventStream*, void*, size_t, void*, const FSEventStreamEventFlags*, const FSEventStreamEventId*)' for argument '2' to '__FSEventStream* FSEventStreamCreate(const __CFAllocator*, void (*)(const __FSEventStream*, void*, size_t, void*, const FSEventStreamEventFlags*, const FSEventStreamEventId*), FSEventStreamContext*, const __CFArray*, FSEventStreamEventId, CFTimeInterval, FSEventStreamCreateFlags)' The typdef for FSEventCallbackT should be the same as the void (*)(const __FSEventStream*, void*, size_t, void*, const FSEventStreamEventFlags*, const FSEventStreamEventId*). I do not see what I am doing incorrectly. Thanks in advance. Bill
At 4:59 PM -0500 1/3/09, Bill McLean wrote:
I'm trying to code up a FSEvent callback using a member function. I may be suffering from a case of the post holiday stupids :)
[ Big snip ] Sadly, I don't think you can do this. The error message is telling you that the second param to FSEventStreamCreate is: 'void (*)(const __FSEventStream*, void*, size_t, void*, const FSEventStreamEventFlags*, const FSEventStreamEventId*)' and a bind expression is certainly not that. In general, the Mac OS X toolbox is not C++ aware, so using bind expressions for callbacks is not going to work. -- -- Marshall Marshall Clow Idio Software <mailto:marshall@idio.com> 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.
participants (2)
-
Bill McLean
-
Marshall Clow