🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Detecting when the user inserts a CD in the CD-ROM drive

Started by
2 comments, last by cody 16 years, 11 months ago
Hi, I'm a beginner in linux. I would like to detect, using C++, when the user inserts a CD in the CD-ROM drive. Is there some file that I could monitor to detect this user action? Notice that I'm not meaning to mount the drive, but to the action of inserting the CD. Thanks in advance
Advertisement
I have no experience with that kind of things at all, but I think you're going to need D-Bus. AFAIK udev will fire an event upon media insertion, and you should be able to get notified of it via D-Bus.
I am currently not running linux, so I cannot test it myself, but try out $ dmesg. Or maybe somewhere in /proc you can find something useful.
you can type dbus-monitor --system on the console and see what happens when you insert a cd:

signal sender=:1.0 -> dest=(null destination) path=/org/freedesktop/Hal/devices/storage_model_CD/DVDW_TS_L632B; interface=org.freedesktop.Hal.Device; member=PropertyModified
int32 1
array [
struct {
string "storage.removable.media_available"
boolean false
boolean false
}
]
signal sender=:1.0 -> dest=(null destination) path=/org/freedesktop/Hal/devices/storage_model_CD/DVDW_TS_L632B; interface=org.freedesktop.Hal.Device; member=PropertyModified
int32 1
array [
struct {
string "storage.removable.media_size"
boolean false
boolean true
}
]
signal sender=:1.0 -> dest=(null destination) path=/org/freedesktop/Hal/Manager; interface=org.freedesktop.Hal.Manager; member=DeviceAdded
string "/org/freedesktop/Hal/devices/volume_label_grml_small_0_4"

you can catch those signals in your program with libdbus.

This topic is closed to new replies.

Advertisement