From cabdd279172ea90406e3426081ade0b77340bed0 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 11 Jun 2012 12:32:36 -0400 Subject: [PATCH] Sketchy role handler update. Pragmatic, rather than principled. --- os2.rkt | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/os2.rkt b/os2.rkt index de9d885..1e138a0 100644 --- a/os2.rkt +++ b/os2.rkt @@ -343,15 +343,37 @@ [(kill pid-to-kill reason) (do-kill (or pid-to-kill pid) reason state)])) +(define (topics-equal? ta tb) + ;; TODO: OK, if we had a couple of simple topics here, we'd be done + ;; by asking (and (specialization? ta tb) (specialization? tb ta)), + ;; but because we have sets of implicitly-unioned topics, things get + ;; jolly awkward. For now, we punt, trusting the user to not supply + ;; an incompatible set of topics on an endpoint update. This is + ;; definitely an interim position: full presence will require a + ;; serious treatment of topic unions via anti-unification. + #t) + (define (do-subscribe pid pre-eid topics hs state) (cond [(hash-has-key? (vm-processes state) pid) (define new-eid (eid pid pre-eid)) + (define old-endpoint (hash-ref (vm-endpoints state) new-eid #f)) (define new-endpoint (endpoint new-eid topics hs)) - (let* ((state (notify-route-additions state new-endpoint)) - (state (generic-update-process state pid (add-process-eid new-eid))) - (state (install-endpoint state new-eid new-endpoint))) - state)] + (if old-endpoint + ;; We are *updating* an existing endpoint's behaviour. + (if (topics-equal? (endpoint-topics old-endpoint) + (endpoint-topics new-endpoint)) + (let* ((state (install-endpoint state new-eid new-endpoint))) + state) + (error 'do-subscribe + "Topics must be equal when updating an endpoint: ~v vs ~v" + old-endpoint + new-endpoint)) + ;; We are installing a *new* endpoint. + (let* ((state (notify-route-additions state new-endpoint)) + (state (generic-update-process state pid (add-process-eid new-eid))) + (state (install-endpoint state new-eid new-endpoint))) + state))] [else state])) (define (generic-update-process state pid updater)