Applications in my OS are event based. That is, they're based around a messaging loop:
Code: Select all
// main loop
while(running)
{
GetNextMessage();
// handle message (click, key down, redraw window, etc)
}
Code: Select all
int main()
{
char name[100];
printf("What is your name? ");
scanf("%s", name);
return 0;
}
I'm thinking when reading/writing to stdout/stdin/stderr for the first time I should create a console window (that way GUI applications which don't write to/read from the console won't have standard console window open) inside the newlib backend.
But then, there is also the problem of handling window events (redraw, move, get input, closed) and file IO messages. Especially things like file IO, require a lot of messaging due to my microkernel design.
So I was thinking, in of the newlib backend inside open/read/lseek/close/reed etc I should have an event loop that flush out the remaining messages (window and input, etc), hoping that at least one of these functions are called often enough that the program doesn't become unresponsive (e.g. you close the window but the program is too busy processing that it doesn't call one of these functions to handle the event).
But if this loop handles handles events and messages, ones it ignores (not targetted at the console window, and non-io ones) are will be deleted if the messenger hasn't be initialised that way they won't pile up and flood an innocent procedural program. (An event based program will initialise the messenger and handle it themselves).
What I really want to know, is how do other microkernels handle this?