Results 1 to 11 of 11

Thread: how to notify an application when a usb flash drive gets connected..

  1. #1
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default how to notify an application when a usb flash drive gets connected..

    hello everyone,
    i am not sure where to start looking for what i want, which is as stated in the title, a way to notify an application that a usb has been connected. so that then the application can mount the file system and do some IO operations.
    Any hints and pointers as to what header file is suitable to do that (in linux) as well as any other pointers you have to offer are very welcome.
    thank you for your help
    nass

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to notify an application when a usb flash drive gets connected..

    Sounds like a job for HAL and DBUS.

  3. #3
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to notify an application when a usb flash drive gets connected..

    thank you for your fast reply.
    hmmm it looks it might be a generally appropriate technique,
    however is there some simpler technique of the form

    if the kernel (using hotplug or other means) realises that there a usb device has been connected, it should send a singal (SIGUSR1 or some other) which then i can intercept from within the application (and i can do a printf() or smth).

    nass

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to notify an application when a usb flash drive gets connected..

    Quote Originally Posted by nass View Post
    however is there some simpler technique of the form

    if the kernel (using hotplug or other means) realises that there a usb device has been connected,
    Currently hotplug uses hal to do its job.

    it should send a singal (SIGUSR1 or some other) which then i can intercept from within the application (and i can do a printf() or smth).
    A unix signal is sent to a particular application, so you can't simply "attach" to a signal.

    As an alternative you could try to monitor the file system (either /etc/fstab or /mnt/something) if you are sure that the device will be automounted in a particular location but this method might fail, so using HAL is a preffered solution.

  5. #5
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to notify an application when a usb flash drive gets connected..

    ok u convinced me
    i will look into it thoroughly
    thank you once again.
    nass

  6. #6
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to notify an application when a usb flash drive gets connected..

    As an alternative you could try to monitor the file system (either /etc/fstab or /mnt/something) if you are sure that the device will be automounted in a particular location but this method might fail, so using HAL is a preffered solution.
    How about /proc ?
    We can't solve problems by using the same kind of thinking we used when we created them

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to notify an application when a usb flash drive gets connected..

    Quote Originally Posted by sunil.thaha View Post
    How about /proc ?
    What about it?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to notify an application when a usb flash drive gets connected..

    Quote Originally Posted by sunil.thaha View Post
    How about /proc ?
    Yes, but not every system allows normal users to dig inside it. A similar solution is to use libusb and look from time to time for new devices.

  9. #9
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to notify an application when a usb flash drive gets connected..

    Quote Originally Posted by sunil.thaha View Post
    How about /proc ?
    The problem with /proc is that Linux treats it entirely different than do other Unix and Unix-like systems. Basing an application on Linux's procfs behavior means that it won't work under BSD, Solaris, etc. I would look for a better crossplatform approach.

  10. The following user says thank you to Brandybuck for this useful post:

    sunil.thaha (4th December 2006)

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to notify an application when a usb flash drive gets connected..

    Furthermore /proc under Linux starts to be deprecated in favour of /sys so there is a probability that /proc (or at least most of its functionality) will soon vanish from some Linux distros.

  12. The following user says thank you to wysota for this useful post:

    sunil.thaha (4th December 2006)

  13. #11
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to notify an application when a usb flash drive gets connected..

    Waw!!

    Didn't know all of those... Cross platform, Deprecated !!!
    Thanks for sharing the info, Guys
    We can't solve problems by using the same kind of thinking we used when we created them

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.