Re: Keyboard input
Posted: Sun Nov 11, 2012 8:13 am
I can understand what is compelling, but OTOH, few people today use command-line like they did when this was invented. For typical end users, this feature has no relevance at all. For an advanced user, it seems just as easy to write a proper application that uses the serial port API rather than opening it as a file. For one thing, the file API doesn't handle timeouts and doesn't support baud rate settings. The problems for sockets are similar, but then the issue is destination IP & port, and also broken sockets and timeouts, which are unsupported in the file API.Jezze wrote:Well, what is compelling about it should be pretty obvious and I'm unsure if I really need to explain why? A program writing data to stdout does not need to know anything about the target device. It could be a printer, a framebuffer or a serial console but it does not matter from the program's perspective, it will just work.
When I add a new device type, I first add a "virtual interface" (similar to virtual methods in C++), which is the basis of what all real devices must support. Then I give the device type a unique handle ID so references to handles are unique.Jezze wrote:I understand that thinking of everything as streams might not feel clean from your perspective but consider the problem you will have when you add a new device type to your os. You will have to modify all programs who wants to utilize that device. Each program will eventually grow incredibly large and difficult to maintain. It would be a nightmare.
So the main issue isn't really how clean the design is, but rather that no device that isn't a file in a file system has the same methods as files, and thus cannot implement the file API methods properly, and typically also has a few extra required methods that cannot be added to the file API since they typically have no meaning for a file.
The traditional solution to the above is that things like file positioning are ignored for non-file objects, while the additional methods required by non-file objects are implemented with IOCTL or similar bastard-solutions. Some systems also invent strange file names for devices, and open these as if they were files.
In RDOS, none of this is supported, and if required, need to be implemented in the C library as the kernel will not support it. Ever.
Besides, it is pretty trivial to implement the typical *nix view of handles in the C library. You can keep the OS handle & type per C handle, and then call the correct read/write method in a switch statement. The reverse (to provide a clean OO interface) is not trivial though, as it needs to know the specifics of special file names and IOCTL control methods in order to implement device-specific methods. It is also faster to have a simple interface to the OS kernel, and let time-sensitive applications use it directly, rather than on top of a file-API abstraction. I practically never use the C file handle interface myself, but rather use the TFile object which goes directly to the relevant OS API.