# $Author: schaal $ # $Date: 1998/12/07 20:26:08 $ # $Locker: $ # $RCSfile: applicationHandlerAgent-tmpl.etcli,v $ # $Revision: 1.7 $ # $Source: /mdvg/CVSRepository/agni/agni/applications/tkwb/applicationHandlerAgent-tmpl.etcli,v $ # $State: Exp $ # Content: # Local proxy agent to get/push tk event from/to and application # Warning: this piece of tcl code MUST be only use as an include # It relies on the existence of the placeNumber and appliPort bApplicationsDesc variable # See also: dispatcher-tmpl.etcl register_agent $newName [list $placeNumber $appliPort [array get bApplicationsDesc]] { m4_include(debug.etcli) #not append in init part => no PRINTERROR or PRINTMESSAGE on monitor if {[llength $argv] != 3} { puts stdout { m4___file__ m4___line__ \ "applicationHandler: invalid number of argument in init part"} return } #set brief case NOW, even not in target place: #to filter any futher on_stream_append events... #put mostly ANYTHING into briefcase... add_briefcase bAppliPlace add_briefcase bAppliPort add_briefcase bOtherApplications add_briefcase bInitPlaceDone global bAppliPlace global bAppliPort global bOtherApplications global bInitPlaceDone set bAppliPlace [lindex $argv 0] set bAppliPort [lindex $argv 1] array set bOtherApplications [lindex $argv 2] set bInitPlaceDone 0 global gAppliSocket set gAppliSocket "" on_stream_append { global gAppliSocket global bAppliPlace set lArgc [llength $argv] if { $lArgc == "0"} { PRINTERROR { m4___file__ m4___line__ "error protocol" } } else { switch -exact [lindex $argv 0] { "EXIT" { if {$bAppliPlace == [stream_location] } { if { $gAppliSocket != ""} { catch {close $gAppliSocket} } } agent_exit } "FORWARD_GUI_EVT" { # event-to-replay if { $lArgc != 2 } { PRINTERROR {m4___file__ m4___line__ \ "FORWARD_GUI_EVT error protocol"} return } if {$bAppliPlace == [stream_location]} { catch { puts $gAppliSocket [format "ReplayOneAction {%s}" [lindex $argv 1]] flush $gAppliSocket } } else { PRINTERROR {m4___file__ m4___line__ \ "appliHandler: not in my place!"} puts stdout [list_streams] puts stdout [stream_name] } } "MOVE" { # place-to-move : currently this argument is usefulless: # we already have the "target place" in bAppliPlace if {$lArgc != 2} { PRINTERROR {m4___file__ m4___line__ \ "error protocol: MOVE place-to-move"} } else { set lNewPlace [lindex $argv 1] PRINTMESSAGE [list m4___file__ m4___line__ \ "MOVE from %d to %d" $lNewPlace $bAppliPlace] if {$lNewPlace != $bAppliPlace} { PRINTERROR {m4___file__ m4___line__ \ "AppliHandler: This is not my target application place !"} stream_relocate $lNewPlace } else { stream_relocate $lNewPlace } } } "OTHERAPPLIJOIN" { # new-appli-token {info} if {$lArgc !=3} { PRINTERROR {m4___file__ m4___line__ \ "OTHERAPPLIJOIN error protocol"} return } set lNewAppli [lindex $argv 1] set lInfo [lindex $argv 2] set bOtherApplications($lNewAppli) $lInfo catch { puts $gAppliSocket [format "__collabUpdateNewAppli %s {%s}" $lNewAppli $lInfo] flush $gAppliSocket } } "OTHERAPPLIQUIT" { # new-appli-token if {$lArgc !=2} { PRINTERROR {m4___file__ m4___line__ \ "OTHERAPPLIQUIT error protocol"} return } set lQuittingAppli [lindex $argv 1] puts "$lQuittingAppli quit" catch {unset bOtherApplications($lQuittingAppli)} catch { puts $gAppliSocket [format "__collabUpdateAppliQuit %s" $lQuittingAppli] flush $gAppliSocket } } "REJOINACCEPTED" { # applicationS-descriptor-array if {$lArgc != 2} { PRINTERROR {m4___file__ m4___line__ \ "REJOINACCEPTED: error protocol"} return } catch { puts $gAppliSocket [format "__collabRejoinAccepted {%s}" [lindex $argv 1]] flush $gAppliSocket } } default { PRINTERROR [list m4___file__ m4___line__ \ "appliHandler: protocol error %s" \ [lindex $argv 0]] } } } } on_stream_relocation { global bAppliPlace global bOtherApplications global bInitPlaceDone if {[stream_location] == $bAppliPlace} { global gAppliSocket global bAppliPort if $bInitPlaceDone { PRINTMESSAGE {m4___file__ m4___line__ \ "appliHandler: come AGAIN in target place, init already done"} } else { set bInitPlaceDone 1 set gAppliSocket "" if [catch {set gAppliSocket [ socket localhost $bAppliPort ]} errorMsg ] { PRINTERROR [list m4___file__ m4___line__ \ "applicationHandler: can not connect to local application %s" \ $errorMsg ] } else { catch { puts $gAppliSocket [format "global db__rd;set db__rd(AgentHdlName) %s" [stream_name]] flush $gAppliSocket puts $gAppliSocket { m4_include(recrep-crunched.tcli) } puts $gAppliSocket [format "global __collabOtherApplications; array set __collabOtherApplications {%s}" [array get bOtherApplications]] puts $gAppliSocket { m4_include(extraAppliGui-crunched.tcli) } flush $gAppliSocket } } } } else { PRINTMESSAGE [list m4___file__ m4___line__ \ "nothing %d is not my application place (%d)" \ [stream_location] \ [lindex $argv 0] ] } } on_stream_failure { puts "outch [stream_name]" # send a message to the other stream_open /tkshare/dispatcher stream_append /tkshare/dispatcher "APPLIEMERGENCYQUIT [stream_name]" puts "local agent send message to dispatcher" } }