diff --git a/csys/csys.lisp b/csys/csys.lisp index c7f9afe..fdab40b 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -10,42 +10,32 @@ (:shape :scopes/shape) (:util :scopes/util) (:alx :alexandria)) - (:export #:*dispatcher* #:setup #:start #:shutdown + (:export #:*dispatcher* #:setup #:send #:printer )) (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)) - (setf (core:mailbox *dispatcher*) (async:make-mb)) (dolist (a (config:actions cfg)) (core:add-action *dispatcher* (car a) (cadr a)))) -(defun start () - (async:init) - (actor:start (core:mailbox *dispatcher*) - (lambda (msg) (funcall #'handle-message msg)) - :foreground t)) - (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))) - nil) + (util:lgw "no action selected" msg)))) (defun run-action (job msg) (let ((ch (async:make-ch))) (async:submit-task ch (lambda () (funcall job msg))))) -(defun shutdown (msg &optional (delay 0.1)) - (sleep delay) - (format t "~&*** shutdown ~a~%" msg) - (actor:stop (core:mailbox *dispatcher*))) - ;;;; example behaviors / actions (defun printer (msg) diff --git a/test/etc/config-csys.lisp b/test/etc/config-csys.lisp index 90de118..2b91b25 100644 --- a/test/etc/config-csys.lisp +++ b/test/etc/config-csys.lisp @@ -5,7 +5,6 @@ (config:root) (config:add-action '(:test) #'csys:printer) -(config:add-action '(:stop) #'csys:shutdown) (config:add :logger :class 'logging:config :loglevel (config:from-env :loglevel :info) diff --git a/test/test-csys.lisp b/test/test-csys.lisp index 9057cdc..e9471d5 100644 --- a/test/test-csys.lisp +++ b/test/test-csys.lisp @@ -21,19 +21,19 @@ ;;;; test runner (defun run () + (async:init) (let* ((t:*test-suite* (make-instance 't:test-suite :name "csys"))) (load (t:test-path "config-csys" "etc")) (unwind-protect (progn - (test-basic)) + (test-nodispatch)) (async:finish) (t:show-result)))) -(deftest test-basic () +(deftest test-nodispatch () (csys:setup) - (!= csys:*dispatcher* nil) - (actor:send (core:mailbox csys:*dispatcher*) (message:create '(:test))) - (actor:send (core:mailbox csys:*dispatcher*) (message:create '(:stop))) - ;(actor:stop (core:mailbox csys:*dispatcher*)) - (csys:start) - ) + (csys:send (message:create '(:test 1))) + (csys:send (message:create '(:test 2))) + (csys:send (message:create '(:test 3))) + (csys:send (message:create '(:test 4))) +)