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