next up previous contents index
Next: Splats Up: Utilities Previous: Display Servers

    
Trackers

The file $VULCAN/src/object-tracker.scm defines the class <object-tracker>. Tracking an object accounts to provide estimations on some parameters associated with such object. In order to define a tracker, one has to define a function to calculate such parameters. In addition, one has to specify how often this function runs, whether is runs in its own thread or in the thread of the function using the tracker, etc. The class <object-tracker> provides the abstract interface to define the scheduling of a tracker.

All active trackers are kept in the list *system::active-trackers*. One can add or remove a tracker from this list by calling the functions

(system::add-tracker tracker)
(system::remove-tracker tracker)
respectively. The function (get-<tracker> t-name) returns the <object-tracker> instance whose name is t-name.

The public fields of the class <object-tracker> are:

  (name         (self <object-tracker>))
  (ground?      (self <object-tracker>))
  (same-thread? (self <object-tracker>))
  (loop-delay   (self <object-tracker>))
The field ground? tells whether the tracker currently is tracking an object. The field same-thread? specifies whether the tracker function should be run in its own thread or the same thread of the function declaring the tracker. The field loop-delay specify how often (in seconds) the tracker should run. This field makes sense when the tracker runs in its own thread. In particular, if loop-delay is x, and it takes the tracker y seconds to do its work, then the tracker sleep for (max 0 (- x y)) seconds.

The methods associated with the class <object-tracker> are:

 (mstart (self <object-tracker>))
 (finalize (self <object-tracker>))
 (track-object (self <object-tracker>))  // virtual method
 (tracker-function (self <object-tracker>))
 (tracker-sleep (self <object-tracker>))
As <object-tracker> is an abstract class, one has to define a subclass for which the method track-object is provided. The method tracker-function will then call track-object as well as keep track of the other tracker's parameters. One example is in place.

Suppose we want to define a tracker for tracking people. Here is a possible realization of this tracker class:

(define-class <people-tracker> (<object-tracker>)
  (name-person-tracked init-value: ")
)

(define-method track-object ((self <people-tracker>))
 ;;; ask whether the person being tracked is around
 (format #t ``Is ~a around?'' (name-person-tracked self))
 (set-grounded? self (read))
)
In order to use this tracker one has to create and start an instance of this class:
(set! mt (mstart (make <people-tracker> 
                      name: ``my tracker''
                      name-person-tracked: ``Ben''
                      same-thread?: #f
                      loop-delay: 5)))
A new tracker will be created which every 5 seconds will ask for Ben.!! The tracker will be done by calling (finalize mt).


next up previous contents index
Next: Splats Up: Utilities Previous: Display Servers
Emilio Remolina
2000-10-04