#! /bin/sh # The next line is executed by /bin/sh, but not Tcl \ exec $TCLADAM_DIR/atclsh $0 ${1+"$@"} # # This script acts as a "go-between" between a tk application and adam # tasks. The tk application cannot communicate directly with an adam # task because adam_receive blocks waiting for messages and so if it # was called within the tk application, the user interface would "hang". # # The go-between waits for adam messages; if a message is received from # the tk application, the message value is executed as a tcl command and # the result sent to the tk application in an Adam inform message. If a # message is received from an adam task its contents are written to # standard output (for the tk application to read). # Initialise the adam message system using comand line argument as our # task name. set name [lindex $argv 0] set myname "${name}_relay" adam_start $myname # Send an initial OBEY to the tk application. set transaction [adam_send ${name} action OBEY ""] # Extract the path and messys id. set path [lindex $transaction 0] set messid [lindex $transaction 1] # Fetch the reply to the obey. adam_receive # Loop for ever collecting adam messages. for {} {1} {} { set message [adam_receive] # Extract the task name set task [lindex $message 1] # Compare the task name with the name of the tk application. if [string compare $task $name] { # Task did not match the name of the tk application so this must be # a message from and adam application. Send the message to the # tk application. puts stdout $message flush stdout } { # Message came from the tk application. Execute the message value as a # tcl command and send the result back to the tk application in a message # system message. set value [lindex $message 6] set status [catch {eval $value} result] if $status { adam_reply $path $messid SYNCREP TCL_ERROR $result } { adam_reply $path $messid SYNCREP TCL_OK $result } } }