Compare commits
2 commits
2aaf8a482d
...
2f5a3b1d74
Author | SHA1 | Date | |
---|---|---|---|
2f5a3b1d74 | |||
3ccf33393e |
4 changed files with 39 additions and 26 deletions
|
@ -24,8 +24,7 @@
|
|||
(defmethod print-object ((msg message) stream)
|
||||
;(shape:print-slots msg stream 'shape:head 'actor:customer 'shape:data)
|
||||
(format stream "#<message ~a ~a ~a>"
|
||||
(shape:head msg) (actor:customer msg) (shape:data msg))
|
||||
)
|
||||
(shape:head msg) (actor:customer msg) (shape:data msg)))
|
||||
|
||||
(defmethod actor:content ((msg message))
|
||||
(list (shape:head-plist msg) (shape:data msg)))
|
||||
|
|
|
@ -10,26 +10,39 @@
|
|||
(:shape :scopes/shape)
|
||||
(:util :scopes/util)
|
||||
(:alx :alexandria))
|
||||
(:export #:*dispatcher* #:printer #:setup #:send
|
||||
))
|
||||
(:export #:send #:*sensors* #:neuron
|
||||
#:nprint))
|
||||
|
||||
(in-package :scopes/csys)
|
||||
|
||||
(defvar *sensors* (make-hash-table :test #'equal))
|
||||
|
||||
(defun send (msg)
|
||||
(let ((hdlrs (core:select msg (core:actions core:*root*))))
|
||||
(if hdlrs
|
||||
;(mapcar #'(lambda (hdlr) (run-action hdlr msg)) hdlrs)
|
||||
(let ((tsks (mapcar (lambda (hdlr) (actor:create hdlr)) hdlrs)))
|
||||
(dolist (tsk tsks) (actor:send tsk msg)))
|
||||
(util:lgw "no action selected" msg))))
|
||||
(if (eq (shape:head-value msg :domain) :csys)
|
||||
(dolist (sn (find-create-sensors msg))
|
||||
(actor:send sn msg))
|
||||
(core:handle-message core:*root* msg)))
|
||||
|
||||
(defun run-action (job msg)
|
||||
(let ((mb (async:make-task job)))
|
||||
(async:submit-task mb (lambda () (funcall job 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
|
||||
;;;; neurons (= behavior generators)
|
||||
|
||||
(defun printer (msg)
|
||||
(util:lgi msg)
|
||||
;(format t "~&~a" msg)
|
||||
)
|
||||
(defun neuron (proc &optional state syns env)
|
||||
(lambda (msg) (funcall proc msg state syns env)))
|
||||
|
||||
;;;; predefined neuron processors
|
||||
|
||||
(defun nprint (msg state syns env)
|
||||
(util:lgi msg state)
|
||||
(actor:become (neuron #'nprint (shape:data msg) syns env)))
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
(config:root)
|
||||
|
||||
(config:add-action '(:test) #'csys:printer)
|
||||
(config:add-action '(:csys :sensor :log)
|
||||
(csys:neuron #'csys:nprint :testing))
|
||||
|
||||
(config:add :logger :class 'logging:config
|
||||
:loglevel (config:from-env :loglevel :info)
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
(defun run ()
|
||||
(async:init)
|
||||
(let* ((t:*test-suite* (make-instance 't:test-suite :name "csys")))
|
||||
(let* ((t:*test-suite* (make-instance 't:test-suite :name "csys"))
|
||||
(csys:*sensors* (make-hash-table :test #'equal)))
|
||||
(load (t:test-path "config-csys" "etc"))
|
||||
(unwind-protect
|
||||
(progn
|
||||
|
@ -32,10 +33,9 @@
|
|||
|
||||
(deftest test-nodispatch ()
|
||||
(core:setup-services)
|
||||
;(csys:setup)
|
||||
(csys:send (message:create '(:test :add :op :n1) :data 1))
|
||||
(csys:send (message:create '(:test :add :op :n1) :data 3))
|
||||
(csys:send (message:create '(:test :sub :op :n2) :data 4))
|
||||
(csys:send (message:create '(:test :add :op :n2) :data 5))
|
||||
(sleep 0.2)
|
||||
(csys:send (message:create '(:csys :add :log :s1) :data 1))
|
||||
(csys:send (message:create '(:csys :add :log :s1) :data 3))
|
||||
(csys:send (message:create '(:csys :sub :log :s2) :data 4))
|
||||
(csys:send (message:create '(:csys :add :log :s2) :data 5))
|
||||
(sleep 0.1)
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue