diff --git a/config.lisp b/config.lisp index fca1657..dcbe9af 100644 --- a/config.lisp +++ b/config.lisp @@ -17,7 +17,8 @@ (defclass common () ((children :accessor children :initarg children - :initform nil))) + :initform nil) + (actions :accessor actions :initarg :actions :initform nil))) (defgeneric parent (cfg) (:method ((cfg common)) nil)) @@ -49,7 +50,8 @@ (setf (gethash sl data) dotenv-val))))))) (defun root (&rest params &key (class 'root) &allow-other-keys) - (setf *root* (apply #'make-instance class params))) + (setf *root* (apply #'make-instance class params)) + (setf *current* *root*)) ;;;; config base class @@ -57,8 +59,7 @@ ((name :reader name :initarg :name) (parent :accessor parent :initarg :parent) (setup :reader setup :initarg :setup :initform #'(lambda (cfg))) - (shutdown :reader shutdown :initarg :shutdown :initform #'(lambda (ctx))) - (actions :accessor actions :initarg :actions :initform nil))) + (shutdown :reader shutdown :initarg :shutdown :initform #'(lambda (ctx))))) (defmethod initialize-instance :after ((cfg base) &key parent &allow-other-keys) (if parent diff --git a/csys/csys.lisp b/csys/csys.lisp index fd54a3d..0285f82 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -10,8 +10,30 @@ (:shape :scopes/shape) (:util :scopes/util) (:alx :alexandria)) - (:export #:*dispatcher*)) + (:export #:*dispatcher* #:setup #:start + #:printer + )) (in-package :scopes/csys) (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) + (print msg)) + +;;;; example behaviors / actions + +(defun printer (msg) + (print msg)) diff --git a/scopes.asd b/scopes.asd index 749b43e..811a9ac 100644 --- a/scopes.asd +++ b/scopes.asd @@ -6,7 +6,7 @@ :version "0.0.1" :homepage "https://www.cyberconcepts.org" :description "Generic data processing" - :depends-on (:scopes-core :scopes-web + :depends-on (:scopes-core :scopes-csys :scopes-web :dbi :sxql) :components ((:file "storage/folder" :depends-on ("storage/tracking")) (:file "storage/msgstore" :depends-on ("storage/tracking")) @@ -16,7 +16,8 @@ ;;#.(uiop:read-file-string ;; (uiop:subpathname *load-pathname* "README.md"))) :in-order-to ((test-op - (test-op "scopes-core/test" "scopes-web/test" "scopes/test")))) + (test-op "scopes-core/test" "scopes-csys/test" + "scopes-web/test" "scopes/test")))) (defsystem :scopes/test :depends-on (:scopes) diff --git a/test/etc/config-csys.lisp b/test/etc/config-csys.lisp index dad17b9..ff9fa05 100644 --- a/test/etc/config-csys.lisp +++ b/test/etc/config-csys.lisp @@ -4,6 +4,8 @@ (config:root) +(config:add-action '(test) #'csys:printer) + (config:add :logger :class 'logging:config :loglevel (config:from-env :loglevel :info) :logfile (t:test-path "scopes-test.log" "log") diff --git a/test/test-csys.lisp b/test/test-csys.lisp index 482cb56..a695d3d 100644 --- a/test/test-csys.lisp +++ b/test/test-csys.lisp @@ -21,7 +21,6 @@ ;;;; 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 @@ -31,4 +30,9 @@ (t:show-result)))) (deftest test-basic () - (== csys:*dispatcher* nil)) + (csys:setup) + (!= csys:*dispatcher* nil) + (actor:send (core:mailbox csys:*dispatcher*) (message:create '(:test))) + (actor:stop (core:mailbox csys:*dispatcher*)) + (csys:start) + )