Exemplo n.º 1
0
static void SignalHandler1(int sigraised)
{
    DEBUG_LOG("\nInterrupted\n");

    // special shutdown sequence
    //  - no longer tracking MouseCount, so set to zero
    //  - and send special -1 MouseCount so LED can be forced off 
    SendMouseCount(0);
    SendMouseCount(-1);
    
    // clean up here
    if (g_AddedIter)
    {
        IOObjectRelease(g_AddedIter);
        g_AddedIter = 0;
    }
    IONotificationPortDestroy(g_NotifyPort);
    
    if (g_ioservice)
    {
        IOObjectRelease(g_ioservice);
        g_ioservice = 0;
    }
   
    // exit(0) should not be called from a signal handler.  Use _exit(0) instead
    _exit(0);
}
Exemplo n.º 2
0
static void DeviceNotification(void* refCon, io_service_t service, natural_t messageType, void* messageArgument)
{
    NotificationData* pData = (NotificationData*)refCon;
    if (kIOMessageServiceIsTerminated == messageType)
    {
        if (g_MouseCount)
            --g_MouseCount;
        DEBUG_LOG("mouse count is now: %d\n", g_MouseCount);
        IOObjectRelease(pData->notification);
        free(pData);
        SendMouseCount(g_MouseCount);
    }
}
static void DeviceAdded(void *refCon, io_iterator_t iter1)
{
    int oldMouseCount = g_MouseCount;
    io_service_t service;
    while ((service = IOIteratorNext(iter1)))
    {
        io_iterator_t iter2;
        kern_return_t kr = IORegistryEntryCreateIterator(service, kIOServicePlane, kIORegistryIterateRecursively, &iter2);
        if (KERN_SUCCESS != kr)
        {
            DEBUG_LOG("IORegistryEntryCreateIterator returned 0x%08x\n", kr);
            continue;
        }
        
        io_service_t temp;
        while ((temp = IOIteratorNext(iter2)))
        {
            io_name_t name;
            kr = IORegistryEntryGetName(temp, name);
            if (KERN_SUCCESS != kr)
                continue;
            if (0 == strcmp("IOHIDPointing", name) || 0 == strcmp("IOHIDPointingDevice", name))
            {
                NotificationData* pData = (NotificationData*)malloc(sizeof(*pData));
                if (pData == NULL)
                    continue;
                kr = IOServiceAddInterestNotification(g_NotifyPort, temp, kIOGeneralInterest, DeviceNotification, pData, &pData->notification);
                if (KERN_SUCCESS != kr)
                {
                    DEBUG_LOG("IOServiceAddInterestNotification returned 0x%08x\n", kr);
                    continue;
                }
                ++g_MouseCount;
                DEBUG_LOG("mouse count is now: %d\n", g_MouseCount);
            }
            IOObjectRelease(temp);
        }
        IOObjectRelease(iter2);
        IOObjectRelease(service);
    }
    if (oldMouseCount != g_MouseCount)
        SendMouseCount(g_MouseCount);
}