Re: Any toy code showing use of fork & pipes & GTK+ together anywhere? (e.g. real time EKG simulation!!!)



Dov

Thank you so much for your offer of help and this reply!!!
I *was* able to get a toy program with gdk_input_add that
accepts data as events from STDIO (i.e. file descriptor = 0)
and works perfectly!!!

It has code snippet below:

   int fd = 0;
   fcntl(fd, F_SETFL, O_NONBLOCK);
   gdk_input_add(fd, GDK_INPUT_READ, (GdkInputFunction) dataProcessor, NULL);

In a REAL APPLICATION I will have parents processes and child
processes.  I will want to communicate between parent and children
IN BOTH DIRECTIONS.  How to I modify code snippet below to do this???

I played with popen, fork and execlp.  The problem is how to
translate all this stuff into a "file descriptor" since that
is what gdk_input_add wants.  Can you give me pointers on this
last step regarding first argument of gdk_input_add to move
beyond STDIO???

Thanks in advance,

Chris


On Mon, Jan 21, 2002 at 09:33:51AM +0200, dov imagic weizmann ac il wrote:
> The key to using data from external sources is by turning the
> arrival of the data into events. This is the essense of event
> driven programming. The way you do this for your own input
> sources is by calling the gdk_input_add_call() function:
> 
>   gint        gdk_input_add                 (gint source,
>                                              GdkInputCondition condition,
>                                              GdkInputFunction function,
>                                              gpointer data);
> 
>   Establish a callback when a condition becomes true on a file descriptor.
> 
> The 'function' is just like any other function that you connect to
> with signal_connect().
> 
> So, the scenario of what you want to do is the following:
> 
>    1. Set up your widgets.
>    2. open up the pipe (with or without forking yourself)
>    3. call gdk_input_add() on the pipe filedescriptor
>    4. call gtk_main()
> 
> It is of course also possible to call gdk_input_add in one of the
> normal signal callback functions. Please let me know if this isn't 
> enough to get you going, and I'll try to put together an example.
> 
> Regards,
> --
>                                                         ___   ___
>                                                       /  o  \   o \
> Dov Grobgeld                                         ( o  o  ) o   |
> The Weizmann Institute of Science, Israel             \  o  /o  o /
> "Where the tree of wisdom carries oranges"              | |   | |
>                                                        _| |_ _| |_
> 
>  
> On Thu, Jan 17, 2002 at 11:56:44PM -0800, Chris Seberino wrote:
> > This list is giving me great advice on lots of stuff
> > but I am nowhere near some of the GTK+ gods on this
> > list and won't be for a long time if ever.
> > 
> > Does anyone know of any sample GTK+ programs that
> > fork off a data generating program and then collect
> > that data with pipes to affect GUI????
> > 
> > e.g. Imagine simulating an EKG for a hospital in GTK+.
> > The EKG object would keep getting data from a patient's
> > heart and we would need to read it and update a plot
> > of that data constantly.
> > 
> > Similarly, one could simulate a tape that kept
> > blaring stock quotes across it.  There would
> > be a forked process that read stock data and
> > GUI would read it as an event.
> > 
> > 
> > Chris
> > 
> > 
> > -- 
> > =======================================================
> > | Dr. Christian Seberino  || (619) 553-7940  (office) |
> > | SPAWARSYSCEN 2363       || (619) 553-2836  (fax)    |
> > | 53560 HULL ST           ||                          |
> > | SAN DIEGO CA 92152-5001 || seberino spawar navy mil |
> > =======================================================
> > _______________________________________________
> > gtk-list mailing list
> > gtk-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtk-list

-- 
=======================================================
| Dr. Christian Seberino  || (619) 553-7940  (office) |
| SPAWARSYSCEN 2363       || (619) 553-2836  (fax)    |
| 53560 HULL ST           ||                          |
| SAN DIEGO CA 92152-5001 || seberino spawar navy mil |
=======================================================



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]