@TCL_STARTUP@

# handler.tcl
#
# This agent illustrates how to associate event handlers with incoming
# messages, events or meeting requests.  Procedure stopEvent is called
# when the agent receives an event with the tag "STOP".  Procedure
# otherEvent is called when the agent receives any other event.

set events 0

  # an event with tag "STOP" has arrived

proc stopEvent {source security tag string} {

  global done

  puts "Received STOP so stopping ...."
  set done 1
}

  # some other event arrived

proc otherEvent {source security tag string} {

  global events

  puts "Event $events"
  puts "Source   ==> $source"
  puts "Security ==> $security"
  puts "Tag      ==> $tag"
  puts "String   ==> $string"
  puts ""

  incr events
}

  # register the agent

agent_begin

  # get our symbolic name

catch {agent_force "$agent(local-ip) handler"}
agent_name handler

  # set up the handlers

set m [mask new]
mask add $m "default -event otherEvent"
mask add $m "ANY ANY -tag STOP -event stopEvent"
mask_replace event $m

  # wait for the STOP event

vwait done

  # done

agent_end
