[Glade-users] Threading with GTK/Glade
- From: james cameron compaq com (James Cameron)
- Subject: [Glade-users] Threading with GTK/Glade
- Date: Tue, 27 Feb 2001 09:35:32 +1100
Johnathan,
I understand the need to keep the design of the interaction with the
external device in one piece of code ... I've done lots of state
critical code; microcontrollers, digital RF base stations, and computer
to computer communication.
Having thought again about the physical configuration you describe, I
would recommend a per serial port process instead of one for all ports.
Under Linux or another UNIX based operating system, you might then have
the following processes;
- gui
- port 1
- port 2
- port 3
etc
This will allow you to write the port processes without any threading;
instead using the operating system for process context switching. No
efficiency change; your time is more expensive anyway. An advantage of
using processes is that each process is isolated from the others, so a
fault (never! ;-)) in one process will not propogate and take down the
system as a whole.
Your description of operations suggests an event sequence to me; which
would represent the communication between the GUI process and the port
processes.
port -> gui : "i'm port 4; i'm started"
port -> gui : "i'm port 4; gizmo detected, serial number x, programming"
port -> gui : "i'm port 4; programming complete, success|fail"
I note there doesn't appear to be any communication in the other
direction. If that is so, a simple shared pipe would be sufficient.
I'd recommend a text protocol for ease of testing; you can use echo to
write messages into the pipe. Here is how I see the GUI operating;
a) the GUI creates the pipe,
b) the GUI fork()'s and exec()'s the port processes attached to pipe,
c) the GUI tells GTK+ that the pipe is an input source,
(using gtk_input_add_full)
d) the GUI returns to the GTK+ main loop,
e) GTK+ calls the GUI handler when a message arrives in the pipe,
f) the handler figures out what to update on screen and returns.
Have a look at my gtsl program on http://quozl.netrek.org/ts/ for an
example of connecting a Glade application to an external event source;
in this case a serial port.
--
James Cameron (james cameron compaq com)
http://quozl.linux.org.au/ (or) http://quozl.netrek.org/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]