2016-07-20 22:54:31 +00:00
|
|
|
#lang racket/base
|
|
|
|
;; Keep track of actor hierarchy, e.g. for
|
|
|
|
;; - naming specific actors in traces, or
|
|
|
|
;; - injecting events from the outside world to specific locations in the tree
|
|
|
|
|
2016-07-20 23:27:40 +00:00
|
|
|
(provide (struct-out targeted-event)
|
|
|
|
target-event
|
|
|
|
current-actor-path-rev
|
2016-07-20 22:54:31 +00:00
|
|
|
current-actor-path
|
2016-07-20 23:27:40 +00:00
|
|
|
call/extended-actor-path)
|
2016-07-20 22:54:31 +00:00
|
|
|
|
2016-07-20 23:27:40 +00:00
|
|
|
;; An event destined for a particular node in the actor hierarchy.
|
|
|
|
;; Used to inject events from the outside world.
|
|
|
|
(struct targeted-event (relative-path event) #:prefab)
|
|
|
|
|
|
|
|
;; If a non-null path is provided, wraps event in a targeted-event
|
|
|
|
;; struct.
|
|
|
|
(define (target-event relative-path event)
|
|
|
|
(if (pair? relative-path)
|
|
|
|
(targeted-event relative-path event)
|
|
|
|
event))
|
2016-07-20 22:54:31 +00:00
|
|
|
|
|
|
|
;; Parameterof (Listof Any)
|
|
|
|
;; Path to the active leaf in the process tree. The car end is the
|
|
|
|
;; leaf; the cdr end, the root.
|
|
|
|
(define current-actor-path-rev (make-parameter '()))
|
|
|
|
|
|
|
|
;; Retrieves current-actor-path-rev, but reversed, for use with
|
2016-07-20 23:27:40 +00:00
|
|
|
;; target-event.
|
2016-07-20 22:54:31 +00:00
|
|
|
(define (current-actor-path) (reverse (current-actor-path-rev)))
|
|
|
|
|
|
|
|
;; Any (-> Any) -> Any
|
|
|
|
;; Pushes pid on current-actor-path for the duration of the call to thunk.
|
|
|
|
(define (call/extended-actor-path pid thunk)
|
|
|
|
(parameterize ((current-actor-path-rev (cons pid (current-actor-path-rev))))
|
|
|
|
(thunk)))
|