The IOServiceMatchingCallback prototype is incompatible with the non-static class method (and technically it is not compatible with the static class method or ), so you cannot use it.
But, fortunately, IOServiceAddMatchingNotification maintains a context pointer (or, as they call it, refCon), which allows you to create a thunk that does not depend on global data.
You need to define a callback with a compatible connection (that is, extern "C"). This function will pass your refCon to your object pointer, and then redirect the call to your instance method:
extern "C" void io_callback(void *refcon, io_iterator_t iterator) { myclass *c = static_cast<myclass *>(refcon); c->real_callback(iterator); }
Then, when you call IOServiceAddMatchingNotification, be sure to pass a pointer to your object for refCon (here I assume that you are calling IOServiceAddMatchingNotification from a member function, and you have this pointer):
result = IOServiceAddMatchingNotification( mNotifyPort, kIOMatchedNotification, IOServiceMatching( "IOFireWireLocalNode" ), serviceMatchingCallback, this, &enumerator );
R Samuel Klatchko
source share