;;;; cl-scopes/csys - concurrent cybernetic communication systems (defpackage :scopes/csys (:use :common-lisp) (:local-nicknames (:actor :scopes/core/actor) (:async :scopes/util/async) (:config :scopes/config) (:core :scopes/core) (:message :scopes/core/message) (:shape :scopes/shape) (:util :scopes/util) (:alx :alexandria)) (:export #:*dispatcher* #:printer #:setup #:send )) (in-package :scopes/csys) (defun send (msg) (handle-message msg)) (defvar *dispatcher* nil) (defun setup (&optional (cfg config:*root*)) (setf *dispatcher* (make-instance 'core:context :config cfg)) (dolist (a (config:actions cfg)) (core:add-action *dispatcher* (car a) (cadr a)))) (defun handle-message (msg) (let ((hdlrs (core:select msg (core:actions *dispatcher*)))) (if hdlrs (mapcar #'(lambda (hdlr) (run-action hdlr msg)) hdlrs) (util:lgw "no action selected" msg)))) (defun run-action (job msg) (let ((mb (async:make-mb))) (async:submit-task mb (lambda () (funcall job msg))))) ;;;; example behaviors / actions (defun printer (msg) (format t "~&*** message: ~a~%" msg))