Skip to content

05 SampleProgram

JackHeeley edited this page Jun 22, 2018 · 27 revisions

Sample Program

SampleProgram is a windows console application project that builds and integrates the features of this solution.

Features

SampleProgram consists of - cd_rom_device a concrete device to access CDROM/DVD, and main - the main program and entrypoint that uses cd_rom_device to create an ISO 9660 image of any CDROM/DVD media found in the drive.

main demonstrates RAII paradigm by locking the cdrom tray door, and unlocking it on all return paths.

Limitations

cd_rom_device builds a set of features which are limited to the purpose stated above. It is in no way intended to expose the full functionality of the windows CDROM driver stack. Some CDROM devices do not support lock, eject and load by program.

The main program makes fixed hard coded selection of the first physical cdrom drive found in the system at runtime. It logs to a fixed hard coded log file called "ripper.log", and creates an iso image file in the fixed hard coded location "cdrom_image.iso".

The main program currently makes no effort to show progress during a read operation that may take many minutes. During this time the system is under heavy memory load and may become temporarily unresponsive. Hint: cd_rom_device::get_image() issues one large blocking synchronous read operation to the underlying kernel device. While this is optimal for efficiency, it offers no opportunity to maintain a progress member, which could be interrogated by a std::future for the purpose of showing progress to the user. This is an easy enhancement for you to attempt as an exercise.

Large dvd images can exceed the virtual address space available to the 32-bit build binaries. In these circumstances an exception will be reported (to the console).

Image files ripped from cd's that are not ISO 9660 format, obviously won't be ISO 9660 compliant, and the fixed .iso extension of the image file is then a lie. Windows will advise you that such a file is 'corrupt'. On Windows 10 Home 1803 edition the file won't be mountable, and if you try, you will need to eject the failed new volume (visible in the left panel of the file explorer), before the backing file can be accessed or deleted. With all of Windows 7-10 you'll see something similar to this.

Signalled program termination (Eg ctrl+break ctrl+c) demonstrate an important limitation of RAII. Destructors are not invoked if a process is signalled to stop. A terminated process releases its resources more brutally. This means that system state cannot be reliably restored using RAII techniques alone, and that fact compromises the design. If the program is terminated in this way during reading (when the CDROM tray door is locked) then the door will remain in the locked state. This could pose a real practical difficulty because the kernel device may refuse an unlock request coming from a different process from the one that locked it, and you might need to reboot to get your disk back! This whole effect will only be visible if your hardware supports tray door locking. Hint: As an exercise, provide signal handler(s) and issue a preventative speculative unlock whenever the program is signalled to stop.