1#! /bin/sh 2# \ 3 exec wish $0 ${1+"$@"} 4 5# BEGIN LICENSE BLOCK 6# Version: CMPL 1.1 7# 8# The contents of this file are subject to the Cisco-style Mozilla Public 9# License Version 1.1 (the "License"); you may not use this file except 10# in compliance with the License. You may obtain a copy of the License 11# at www.eclipse-clp.org/license. 12# 13# Software distributed under the License is distributed on an "AS IS" 14# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 15# the License for the specific language governing rights and limitations 16# under the License. 17# 18# The Original Code is The ECLiPSe Constraint Logic Programming System. 19# The Initial Developer of the Original Code is Cisco Systems, Inc. 20# Portions created by the Initial Developer are 21# Copyright (C) 2006 Cisco Systems, Inc. All Rights Reserved. 22# 23# Contributor(s): 24# 25# END LICENSE BLOCK 26# 27# Example for Tcl Peer Multitasking. See example_multi.ecl for more 28# information 29# 30#---------------------------------------------------------------------- 31# Find and load the eclipse package 32#---------------------------------------------------------------------- 33set tkecl(ECLIPSEDIR) $env(ECLIPSEDIR) 34lappend auto_path [file join $tkecl(ECLIPSEDIR) lib_tcl] 35 36package require eclipse_peer_multitask 37package require remote_eclipse 38 39set argstate flag 40set host [info hostname] 41set port "" 42set return_code continue 43 44foreach arg $argv { 45 switch -- $argstate { 46 flag { 47 switch -exact -- $arg { 48 -h {set argstate host} 49 -p {set argstate port} 50 default: {error "Unknown flag $arg"} 51 } 52 } 53 host { 54 set host $arg 55 set argstate flag 56 } 57 port { 58 set port $arg 59 set argstate flag 60 } 61 } 62} 63 64 65#---------------------------------------------------------------------- 66# Registration and deregistration 67#---------------------------------------------------------------------- 68 69proc register_for_multi {} { 70 ec_multi:peer_register [list start multi_start_handler interact multi_interact_handler] 71 ;# toggle the .reg button 72 .reg configure -command {deregister_for_multi} 73 .reg configure -text "Deregister multitasking" 74} 75 76proc deregister_for_multi {} { 77 ec_multi:peer_deregister 78 ;# toggle the .reg button 79 .reg configure -command {register_for_multi} 80 .reg configure -text "Register multitasking" 81} 82 83 84#---------------------------------------------------------------------- 85# Handlers 86#---------------------------------------------------------------------- 87 88proc multi_start_handler {type} { 89 global return_code 90 91 if {$type == "demo"} { 92 set return_code continue 93 enable_buttons 94 } else { 95 disable_buttons 96 set return_code no 97 } 98 return $return_code 99} 100 101proc multi_interact_handler {type} { 102 global return_code 103 104 if {$return_code == "terminate"} { 105 disable_buttons 106 } 107 return $return_code 108} 109 110proc ec_end {} { 111 if {[ec_multi:get_multi_status] != "on"} { 112 enable_buttons 113 } 114} 115 116proc ec_start {} { 117 if {[ec_multi:get_multi_status] != "on"} { 118 disable_buttons 119 } 120} 121 122 123#---------------------------------------------------------------------- 124# Actions for buttons 125#---------------------------------------------------------------------- 126 127proc end_interaction {} { 128 global return_code 129 set return_code terminate 130 if {[ec_multi:get_multi_status] != "on"} { 131 ;# we are not multitasking, hand control back to ECLiPSe directly 132 ec_resume 133 } 134} 135 136proc enable_buttons {} { 137 .run configure -state normal 138 .end configure -state normal 139 .reg configure -state normal 140} 141 142proc disable_buttons {} { 143 .run configure -state disabled 144 .end configure -state disabled 145 .reg configure -state disabled 146} 147 148 149#---------------------------------------------------------------------- 150# Intialisation 151#---------------------------------------------------------------------- 152 153pack [button .run -state disabled -command {ec_rpc \ 154 [list writeln [list - ok [ec_peer_name]]] {((()()))}} -text run] 155pack [button .end -state disabled -command {end_interaction} -text "end interaction"] 156pack [button .reg -state disabled] 157 158 159ec_remote_init $host $port 160ec_running_set_commands ec_start ec_end {} disable_buttons 161register_for_multi 162 163ec_resume 164 165 166 167