46.7. Callbacks

The event builder supports wide variety of callbacks that allow user code to intervene when meaningful events occur. This section describes these callbacks and how to set them up.

46.7.1. Connection callbacks

The connection callback invokes user code when a new client has connected to the event builder as a source of event fragments.

When you write the callback, keep in mind that the script you provide will have the host and client description appended to it. This implies that most event builder connection callbacks wil be procs

Example 46-4. Establishing the connection callback


proc Connection  {host description}  {          (1)
    puts "$host just connected: $description"
}

EVB::setConnectionCallback Connection          (2)

                    
(1)
This is a sample connection callback proc. All it does is output information about the connection that was just processed.
(2)
The connection callback is established using the EVB::setConnectionCallback procecedure.

Note that EVB:Start must have been called prior to this cvall.

46.7.2. Establishing the disconnect callback

The disconnect callback is invoked when a data source disconnects. The callback is invoked for both normal and abnormal disconnects (there is a disconnect protocol prior to closing the link if the link closes without that protocol being followed, it is considered an abnormal disconnect).

The disconnect callback is passed the host and description of the source that has disconnected.

Example 46-5. Setting up the disconnect callback


proc disconnect {host description} {                    (1)
    puts "$description disconnected ($host)"
}

EVB::setDisconnectCallback disconnect                   (2)
                    
(1)
This is a simple sample disconnecdt callback. It just prints information about the disconnect on stdout.
(2)
This call establishes the callback. Note that prior to invoking this command, EVT::Start must have been called.