next up previous index
Next: Type conversion between Tcl Up: Embedding into Tcl/Tk Previous: Communication via Queues   Index

Subsections

Attaching Handlers to Queues

ECLiPSe to Tcl

In order to handle ECLiPSe I/O on queues more conveniently, it is possible to associate a Tcl handler with every queue. These handlers can be invoked automatically whenever ECLiPSe flushes a write-queue or reads from an empty read-queue.

For that purpose, the queue must be created using open/4 with the yield-option. The following example creates a queue that can be written from the ECLiPSe side, and whose contents, if flushed, is automatically displayed in a text widget:

ECLiPSe:  open(queue(""), write, my_out_queue, [yield(on)]).
Tcl:      pack [text .tout]
          ec_queue_connect my_out_queue r {ec_stream_to_window "" .tout}
Assume that ECLiPSe is then resumed, writes to the queue and flushes it. This will briefly pass control back to Tcl, the ec_stream_to_window-handler will be executed (with the stream number added to its arguments), afterwards control is passed back to ECLiPSe. Note that ec_stream_to_window is a predefined handler which reads the whole queue contents and displays it in the given text widget.

Similarly, an ECLiPSe input queue could be configured as follows:

ECLiPSe:  open(queue(""), read, my_in_queue, [yield(on)]).
Tcl:      ec_queue_connect my_in_queue w \
                        {ec_stream_input_popup "Type here:"}
Assume that ECLiPSe is then resumed and reads from my_in_queue. This will briefly yield control back to Tcl, the ec_stream_input_popup-handler will be executed, afterwards control is passed back to ECLiPSe.

Three predefined handlers are provided:

ec_stream_to_window tag text_widget stream_nr

Inserts all the current contents of the specified queue stream at the end of the existing text_widget, using tag.

ec_stream_output_popup label_text stream_nr

Pops up a window displaying the label_text, a text field displaying the contents of the specified queue stream, and an ok-button for closing.

ec_stream_input_popup label_text stream_nr

Pops up a window displaying the label_text, an input field and an ok-button. The text typed into the input field will be written into the specified queue stream.
When ECLiPSe is initialised with the default options, its output and error streams are queues and have the ec_stream_output_popup handler associated. Similarly, the input stream is a queue with the ec_stream_input_popup handler attached. These handler settings may be changed by the user's Tcl code.


Tcl to ECLiPSe

A queue whose read-end is on the ECLiPSe-side can be configured to raise an ECLiPSe-event (see event/1 and the User Manual chapter on event handling) whenever the Tcl program writes something into the previously empty queue. To allow that, the queue must have been created using open/4 with the event-option, e.g.5.1
open(queue(""), read, my_queue, [event(my_queue_event)])
Assuming something was written into the queue from within Tcl code, the ECLiPSe event will be handled as soon as ECLiPSe is resumed or ec_handle_events (a restricted form of ec_resume) is invoked.

Note that it is also possible to raise ECLiPSe events which are not linked to queues, using ec_post_event.


next up previous index
Next: Type conversion between Tcl Up: Embedding into Tcl/Tk Previous: Communication via Queues   Index

1999-08-06