Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

USB Notifications



Title: USB Notifications
Hello List:

I have a couple of questions regarding notifications of a USB device added to the system or removed from the system. I want my deviceAdded callback to be called if the device is added, I want my deviceRemoved callback to be called if the device is removed, and I want my deviceAdded callback to be called again if the device is re-added, and my deviceRemoved callback to be called again if my my device is re-removed, etc., etc., etc.

Some code snippets ...

In main:
    kr = IOServiceAddMatchingNotification(  gNotifyPort,
                                            kIOFirstMatchNotification,
                                            matchingDict,
                                            RawDeviceAdded,
                                            NULL,
                                            &gRawAddedIter );

    RawDeviceAdded(NULL, gRawAddedIter);        // Iterate once to get already-present devices and
                                                // arm the notification

    kr = IOServiceAddMatchingNotification(  gNotifyPort,
                                            kIOTerminatedNotification,
                                            matchingDict,
                                            RawDeviceRemoved,
                                            NULL,
                                            &gRawRemovedIter );
                                           
    RawDeviceRemoved(NULL, gRawRemovedIter);   // Iterate once to arm the notification*/


My callbacks:
    void RawDeviceAdded(void * refCon, io_iterator_t iterator){
       printf("\n\nEnteredRawDeviceAdded\n\n");
       IOIteratorNext(iterator);
       };

    void RawDeviceRemoved(void * refCon, io_iterator_t iterator){
       printf("\n\nEnteredRawDeviceRemoved\n\n");
       IOIteratorNext(iterator);
       };


With the above code I get notified (printf) when my device is added and I get notified (printf) when its removed, but I don't get re-notified when the device is re-added or re-removed. Does anyone know what I am doing wrong please?

2nd question ... even though the printf statements in my callbacks come before the IOIteratorNext statements, I only get the respective printf's to operate if the IOIterator statements are present. I don't understand how that can be. Once I've entered a callback, I think the printf's should operate regardless of what follows. Again, does anyone know what I am doing wrong please?

Thank you.
-- 



-----

B. Mitchell Loebel                                    408 425-9920 cell
       
Executive Director
The Tech Startup Connection
(formerly The PARALLEL Processing Connection)  
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.