[Glade-users] Started glade 2 days ago!
- From: james cameron compaq com (James Cameron)
- Subject: [Glade-users] Started glade 2 days ago!
- Date: Thu, 08 Mar 2001 09:05:11 +1100
Ahmad Al-rasheedan wrote:
3) Have a C function 'tail_log_file()' that merely tail -f log_file.
Where would one put it provided I need the output be placed in
GtkText window on some small UI I am doing just to learn glade.
The way I would do it, to make sure that the UI will always be able to
respond the fastest to either X server events or data from the tail, is
to express an interest in the file descriptor from which the tail data
will arrive, using gtk_input_add_full() ...
FILE *pipe; /* the pipe to the tail process */
guint input; /* the input source identifier */
/* start the tail process, perhaps as a callback on map for GtkText */
initialise() {
pipe = popen("tail -f log", "r");
input = gtk_input_add_full(fileno(pipe), GDK_INPUT_READ, reader, NULL,
NULL, NULL);
}
/* process arriving data from the tail */
static void reader (gpointer data, gint source, GdkInputCondition
condition) {
char buffer[1024], *p;
p = fgets(buffer, 1024, pipe);
if (p == NULL) {
/* process send end of file? */
gtk_input_remove(input);
}
/* add the line of text to the GtkText widget */
...
/* remove an old line if necessary */
...
}
However, if your tail_log_file() is implemented in the manner of tail(1)
itself, rather than forking a process to run tail(1), then you need to
adjust your thinking. tail(1) normally waits for a second or so between
checking the file size. To do this in GTK, add a timeout during
initialisation that causes your tail_log_file() function to be called.
So long as the function returns TRUE, it will be rescheduled for another
execution.
gtk_timeout_add(1000, tail_log_file, NULL);
These functions are described by the GTK+ documentation and source code.
--
James Cameron (cameron stl dec com)
http://www.opensource.org/ http://vanilla.us.netrek.org/ http://lwn.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]