cl-scopes/csys/csys.lisp

42 lines
1.3 KiB
Common Lisp

;;;; 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 #:printer #:send
#:*sensors*))
(in-package :scopes/csys)
(defvar *sensors* (make-hash-table :test #'equal))
(defun send (msg)
(dolist (sn (find-create-sensors msg))
(actor:send sn msg)))
(defun find-create-sensors (msg)
(let* ((key (cddr (shape:head msg)))
(sns (gethash key *sensors*)))
(format t "~&~a ~a" key sns)
(or sns
(let* ((mx (message:create
(list :csys :sensor (shape:head-value msg :class))))
(hdlrs (core:select mx (core:actions core:*root*))))
(if hdlrs
(let ((tsks (mapcar #'actor:create hdlrs)))
(setf (gethash key *sensors*) tsks))
(util:lgw "no action selected" msg))))))
;;;; example behaviors / actions
(defun printer (msg)
(util:lgi msg)
;(format t "~&~a" msg)
)