ncurses event loop



Hi,

I need to program a simple user interface using ncurses and I'm a bit
stuck with the event loop in it. Basically I need to launch a new
process from a list of processes in my app. Once this new process is
started it starts to send progress information using some IPC
mechanism.

So what I have now is something like:

timeout(10); // timeout to 10 ms

while(1)
{
int ch = getch(); // get character blocking 10 ms at max
if(ch != ERR) // key pressed
{
// do something with the key such as update screen
// or launch another process
}
else
{
// no keypress in last 10 ms so poll progress info
get_progress_info();
}
}


To me this looks weird but that can be due to fact that this is my
first ncurses program :) Anyway.. Is this kind of programming as "bad"
as it looks? Let's say get_progress_info() function takes 10 ms to
respond. That means that CPU-usage would be 100% all the time which is
vey bad thing. Does getch() really sleep when no keypress is coming?

Anyway, I come from Symbian world where event loops built in so
forgive my stupidity ;)

--
Wellu

.


Quantcast