Rationalise layers a little more to add the POSIX standard fdopen(int)
and a local open(FileHandle) to map a FileHandle to a POSIX file
descriptor.
fdopen(FileHandle) is now a composite of those two, rather than being
a primitive.
There is currently no proper wake up mechanism provided
by mbed-os. _poll_change() was supposed to wake upa blocking
poll() in case of a POLL event but the implementation was dependent
upon underlying wake up mechanism. In the absence of conditioanl
variables or some other alternative, _poll_change() wasn't able to
serve its purpose. Removing it for now. Should be implemented at some later stage
Make FileHandle more of an interface class, by requiring implementers to
provide the sigio() functionality themselves.
sigio() and poll() remain parallel independent mechanisms, so FileHandle
implementations must trigger both on state changes.
This has been an attempt to extend existing FileHandle to behave like POSIX
file descriptor for input/output resources/devices too.
This will now provide an abstract indicator/handle any arbitrary file or device
type resource. May be in future, sockets too.
In order to correctly detect availability of read/write a FileHandle, we needed
a select or poll mechanisms. We opted for poll as POSIX defines in
http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html Currently,
mbed::poll() just spins and scans filehandles looking for any events we are
interested in. In future, his spinning behaviour will be replaced with
condition variables.
In retarget.cpp we have introduced an mbed::fdopen() function which is
equivalent to C fdopen(). It attaches a std stream to our FileHandle stream.
newlib-nano somehow does not seem to call isatty() so retarget doesn't work for
device type file handles. We handle this by checking ourselves in
mbed::fdopen() if we wish to attach our stream to std stream. We also turn off
buffering by C library as our stuff will be buffered already.
sigio() is also provided, matching the API of the Socket class, with a view to
future unification. As well as unblocking poll(), _poll_change calls the user
sigio callback if an event happens, i.e., when FileHandle becomes
readable/writable.