Files CCore/inc/sys/SysCon.h CCore/src/sys/SysCon.cpp
This part supports console input-output operations.
#ifndef CCore_inc_sys_SysCon_h #define CCore_inc_sys_SysCon_h #include <CCore/inc/sys/SysError.h> #include <CCore/inc/TimeScope.h> namespace CCore { namespace Sys { /* functions */ void ConWrite(StrLen str) noexcept; /* classes */ struct ConRead; /* struct ConRead */ struct ConRead { // private .... // public struct IOResult { ulen len; ErrorType error; }; // public ErrorType init() noexcept; ErrorType exit() noexcept; IOResult read(char *buf,ulen len) noexcept; IOResult read(char *buf,ulen len,MSec timeout) noexcept; IOResult read(char *buf,ulen len,TimeScope time_scope) noexcept; }; } // namespace Sys } // namespace CCore #endif
ConWrite() outputs the given string to the console. This function is a 0-priority function. I.e. if it is required some initialization, it must be done using the CCORE_INITPRI_0 priority qualifier.
The structure ConRead supports the console reading. To read characters from the console, you create an instance of this structure, initialize it and then use its methods to read the input character stream. Finally, you uninitialize the instance. Copying of the instances is prohibited. The private content of the structure is target-dependent. The reader implements "non-buffered read without echo". It means, if the console buffer is not empty, the read operations do not block. If the buffer is empty, they wait for input. No echo is printed.
init() performs the initialization. The error code is returned. If the object is successfully initialized, it must be uninitialized by the method exit().
exit() performs the uninitialization. The error code is returned.
read() tries to read the input stream into the provided buffer. The second variant uses the timeout for the operation. The third variant uses the time_scope for the operation. All functions return the internal type IOResult. This structure has two fields: len and error. The error is the error code. If it is zero, then the len is the number of characters, copied to the buffer. This value is less or equal than the argument len. The first function may block infinitely. The second and third — up to the given timeout. The first function must either return a error or a character(s). The second and third may return neither error, nor character, if the user did not hit any key during the given time period.