-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't make DEFAULT_DEVICE a constant #30
Conversation
I would rather see that as an implementation problem in libdiscid or even a general problem for Mac OS X. The solution for mac is to use device numbers, rather than raw devices. |
For Windows the default device can technically change, but does so only when explicitely reassigned in the partitioning managment. |
Well, my portable CD drive is not a constant, especially as I frequently run out of free USB ports ;) Not even it's drive letter on Windows is constant as it all depends on whether I plug in some other drive before or after connecting the CD drive. The point is that it is not a libdiscid issue. libdiscid is just fine, it's interface can handle a runtime change in the default device, even though the current libdiscid implementation can't. I would advise not to cripple the python-discid interface by making the default device a constant. If you use a method to access the default device you keep the interface flexible without loosing anything. |
Hm, didn't think about portable CD drives. That is kind of a problem. So for portable drives the situation is similar to Mac OS X, but in contrast to Mac OS X, device numbers are used nowhere in Windows environments. (and on Windows the drive letter doesn't depend on an actual disc beeing in the drive. Having a static device name always was the intended way for libdiscid (MB_DEFAULT_DEVICE internally on platforms except Mac). I wouldn't call something "default device" if it changes often. |
I understand that you want to read automatically from the first disc (drive) currently detected, but I am not sure if we should make that available as something called "default device". |
One possibility to make this available would be to allow "drive numbering" in general (not only on Mac, where it is proposed only). This would enable "1" as a default device, though I would still use "/dev/cdrom" as a default on Linux. Anyways. I don't like the idea of an ever-changing "default device" (as returned string, the internal device mapping can change as often as it wants to). |
Yes, indeed, metabrainz/libdiscid#20 is the libdiscid side of this (for Windows). When you look at discid_get_default_device() from the outside it does not look like it is meant to return a hard coded constant all the time. My assumption as a user of the library would rather be that it returns a meaningful device for my system. That it uses a constant internally for most implementations is IMHO an incomplete implementation and I can't really see the intention that the implementation should work that way. As it is the default device works on none of my systems. On my Windows laptop it returns "D:" although my CD drive is E:, and on my Linux it returns "/dev/cdrom" even though I only have "/dev/cdrom1" (a symlink to /dev/sr0). To make it worse if I boot Windows on the same laptop the actual drive letter is either E:, F: or none at all depending on whether an external HDD is plugged in and whether the CD drive is plugged in or not. Picard can handle at least the first two cases, but I see no reason why this detection shouldn't get implemented directly in libdiscid. But no matter how you turn it, discid_get_default_device() doesn't look like it returns a constant, doesn't actually return a constant on OSX and might not return a constant on other platforms in the future. So I wouldn't make it a constant in your implementation. Feel free to ignore my advice, but in general when designing a public API and something is not absolutely without doubt a constant you are better off not making it a constant. Just for the record: I think using device numbering is a bad solution on any platform where it is not common. But that's only indirectly related to this ticket so let's discuss that somewhere else :) (EDIT: I've commented on http://tickets.musicbrainz.org/browse/LIB-28) |
To me that sounds much like there is exactly one outcome on a specific operating system that should not be dependent on the actual system. That OS X is messed up in that context is a problem, but that is only an OS X problem and only until we implement device numbers on OS X. There are no actual names for the device, only for a disc loaded in a device (and with that name you can access the device again, but only then). |
That's an explanation why it is not technically a constant. But it does not explain why it should be a constant. I at least hope that discid_get_default_device() exists not only as a workaround for the fact that a define would not work but also because it is just sane API design. You can't assume a hard coded constant will work on every system and indeed the current implementation makes discid_get_default_device() on some systems rather useless for everything but a libdiscid usage example. I think before insisting on discid_get_default_device() being a constant we should be clear about why it should be a constant (sorry, that's absolutely not clear to me) and what the intended use case for discid_get_default_device() is. |
What you cited is not the explanation, yes. But what I quoted is the definition of the value that makes it constant per operating system. This doesn't mean we can't change it, but this change might be unexpected. I also want to note, that discid_read() does mention the default device should be exactly what is used by read (when NULL is given):
So implementing something different for the use in read() would be even worse than making default_device depend on the current state of the current machine. I'll think about it. |
As you said in http://tickets.musicbrainz.org/browse/PICARD-503 this discussion is blocking you from releasing a stable API. So maybe I ask it the other way this time: Were do you see the downside of not having DEFAULT_DEVICE a constant? Not having it a constant would mean the python-discid API is decoupled from our general "how constant should the default device be" discussion. This is a pretty nice example on how constants can lead to a less stable and future proof API ;) |
Pure API design reasons. Using a function, rather than a constant gives more possibilities. That is correct. I am not at all opposed to having a default device that is of actual use to the user. For Mac OS X I proposed a solution (having numbers, possibly adding the (current) device name as a run-time information). For Linux/BSD/Solaris a default is already anticipated (though /dev/cdrom on linux is by convention, not sure if there is an actual standard involved, probably not; on the BSDs this works fine out of the box). So I really would like to hear some feedback/opinion. |
Python-discid (http://python-discid.readthedocs.org) is a Python binding of libdiscid. It resolves http://tickets.musicbrainz.org/browse/PICARD-503
It will add default drive as returned by libdiscid to the list of known drives Ie. on linux, list is : /dev/cdrom, /dev/sr0, /dev/sr1 (default link + 2 sata cd readers) On first start it will populate the list with default drive provided by libdiscid, which means Picard is now able to scan CD without going to Options (to set cd reader) first, which was not the case before.
I would prefer a function, returning an ordered list of detected devices, with the first one = default. This way, if libdiscid is able to provide the list of devices (ie. on win D:,E: or on linux /dev/cdrom, /dev/dvrom, /dev/sr3 ), we'll still have one call. And implement it as discid.get_devices() == [disc.DEFAULT_DEVICE], for now. Of course, i would keep constant for a while for compatibility, deprecated. |
Returning lists is something that would work fine for python-discid, but not so well in C on the actual libdiscid. Returning string lists isn't something that can be done nicely in a C API (due to explicit memory management). Moving the This is basically about (newly created) #33, but doesn't directly answer the question whether the (single) default value should be |
Well, then the question is simply : is "default device" something that change or no ? |
Well, not trying to argue for both sides, but to get the facts right: The current libdiscid code gets the first available disc drive on Mac OS X and returns it as default. So when you remove the disc from the drive, mount a .dmg file and then put again a disc in the drive the device name changes (like from /dev/rdisk2 to /dev/rdisk3). Similar for Windows and USB disc drives, but not as bad. However, on Windows people actually understand drive letters as device names and the solution just returning "1" might not be what people want. So a decision for having "DEFAULT_DEVICE" as a constant is probably a decision for using "1" for OSs that don't have stable device names in libdiscid (and adding the feature to return a list of currently available device names later on) |
@JonnyJD : Thanks for this explanition. |
@zas: You should probably read the related ticket at http://tickets.musicbrainz.org/browse/LIB-28 . This python-discid ticket here depends mostly on the outcome of the discussion there (and JonnyJD and myself don't come to a conclusion there, so feedback is appreciated). |
This is not decided, but I added a commit to show what possible code change we are talking about. |
It looks better in my eyes as a function. |
me in LIB-28:
I will probably make a decision on Monday. |
I would consider not to have a DEFAULT_DEVICE constant but rather do an actual function call. Even though the default device is at the moment mostly a constant in libdiscid, it might be something which changes on runtime.
I am not entirely sure how OSX handles the devices, but isn't it the case there that the devices change on runtime when the users inserts / removes a disc? At least https://github.com/metabrainz/libdiscid/blob/master/src/disc_darwin.c#L155 suggest this and Picard has issues with it. Even on other systems that could happen when the user attaches a portable drive, even though dynamic detection of the device is currently not supported by libdiscid on those platforms.