Re: ncurses event loop
- From: Joe Beanfish <joe@xxxxxxxxxx>
- Date: Fri, 28 Sep 2007 13:02:47 -0400
Wellu wrote:
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 ;)
Your IPC from the background task could be a pipe. Then use select() on
that pipe and stdin to wait for something to do. If stdin is ready
call getch() to handle it. If the pipe call get_progress_info() to read it.
.
- References:
- ncurses event loop
- From: Wellu
- ncurses event loop
- Prev by Date: Re: GUI application
- Next by Date: Re: GUI application
- Previous by thread: Re: ncurses event loop
- Next by thread: advice on how to detect time change
- Index(es):
Relevant Pages
|