mac os x - usb hid - how the receive device added / device removed callbacks? I'm a beginner at programming on mac os x.

I am following this tutorial.

And I have this program:

#include &lt;stdio.h&gt;
#include &lt;IOKit/hid/IOHIDManager.h&gt;
#include &lt;IOKit/hid/IOHIDKeys.h&gt;
#include &lt;CoreFoundation/CoreFoundation.h&gt;

static void Handle_DeviceMatchingCallback(void *inContext, IOReturn inResult, void *inSender, IOHIDDeviceRef inIOHIDDeviceRef)
{
    puts("YAY Handle_DeviceMatchingCallback");
}

static void Handle_DeviceRemovalCallback(void *inContext, IOReturn inResult, void *inSender, IOHIDDeviceRef inIOHIDDeviceRef)
{
    puts("YAY Handle_DeviceRemovalCallback");
}

int main()
{
    IOHIDManagerRef HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
    IOHIDManagerSetDeviceMatching(HIDManager, NULL);

    IOHIDManagerRegisterDeviceMatchingCallback(HIDManager, &amp;Handle_DeviceMatchingCallback, NULL);
    IOHIDManagerRegisterDeviceRemovalCallback(HIDManager, &amp;Handle_DeviceRemovalCallback, NULL);

    IOHIDManagerScheduleWithRunLoop(HIDManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);

    IOReturn IOReturn = IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone);
    if(IOReturn) puts("IOHIDManagerOpen failed.");

    while(1)
    {
        puts("sleeping...");
        sleep(1);
    }

    return 0;
}


What I am doing wrong, because I do not get the callbacks when I insert or remove any hid device in the USB port.
IOHIDManagerScheduleWithRunLoop is hooked to RunLoop, so You need to start one. while loop is not the solution here. So in order to get callbacks You should replace while loop with CFRunLoopRun() call. More informations about RunLoops in documentation.