work in progress: csys basics

This commit is contained in:
Helmut Merz 2025-06-11 18:32:42 +02:00
parent 445c5a5c3b
commit 0eb98e357e
5 changed files with 39 additions and 9 deletions

View file

@ -17,7 +17,8 @@
(defclass common () (defclass common ()
((children :accessor children ((children :accessor children
:initarg children :initarg children
:initform nil))) :initform nil)
(actions :accessor actions :initarg :actions :initform nil)))
(defgeneric parent (cfg) (defgeneric parent (cfg)
(:method ((cfg common)) nil)) (:method ((cfg common)) nil))
@ -49,7 +50,8 @@
(setf (gethash sl data) dotenv-val))))))) (setf (gethash sl data) dotenv-val)))))))
(defun root (&rest params &key (class 'root) &allow-other-keys) (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 ;;;; config base class
@ -57,8 +59,7 @@
((name :reader name :initarg :name) ((name :reader name :initarg :name)
(parent :accessor parent :initarg :parent) (parent :accessor parent :initarg :parent)
(setup :reader setup :initarg :setup :initform #'(lambda (cfg))) (setup :reader setup :initarg :setup :initform #'(lambda (cfg)))
(shutdown :reader shutdown :initarg :shutdown :initform #'(lambda (ctx))) (shutdown :reader shutdown :initarg :shutdown :initform #'(lambda (ctx)))))
(actions :accessor actions :initarg :actions :initform nil)))
(defmethod initialize-instance :after ((cfg base) &key parent &allow-other-keys) (defmethod initialize-instance :after ((cfg base) &key parent &allow-other-keys)
(if parent (if parent

View file

@ -10,8 +10,30 @@
(:shape :scopes/shape) (:shape :scopes/shape)
(:util :scopes/util) (:util :scopes/util)
(:alx :alexandria)) (:alx :alexandria))
(:export #:*dispatcher*)) (:export #:*dispatcher* #:setup #:start
#:printer
))
(in-package :scopes/csys) (in-package :scopes/csys)
(defvar *dispatcher* nil) (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))

View file

@ -6,7 +6,7 @@
:version "0.0.1" :version "0.0.1"
:homepage "https://www.cyberconcepts.org" :homepage "https://www.cyberconcepts.org"
:description "Generic data processing" :description "Generic data processing"
:depends-on (:scopes-core :scopes-web :depends-on (:scopes-core :scopes-csys :scopes-web
:dbi :sxql) :dbi :sxql)
:components ((:file "storage/folder" :depends-on ("storage/tracking")) :components ((:file "storage/folder" :depends-on ("storage/tracking"))
(:file "storage/msgstore" :depends-on ("storage/tracking")) (:file "storage/msgstore" :depends-on ("storage/tracking"))
@ -16,7 +16,8 @@
;;#.(uiop:read-file-string ;;#.(uiop:read-file-string
;; (uiop:subpathname *load-pathname* "README.md"))) ;; (uiop:subpathname *load-pathname* "README.md")))
:in-order-to ((test-op :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 (defsystem :scopes/test
:depends-on (:scopes) :depends-on (:scopes)

View file

@ -4,6 +4,8 @@
(config:root) (config:root)
(config:add-action '(test) #'csys:printer)
(config:add :logger :class 'logging:config (config:add :logger :class 'logging:config
:loglevel (config:from-env :loglevel :info) :loglevel (config:from-env :loglevel :info)
:logfile (t:test-path "scopes-test.log" "log") :logfile (t:test-path "scopes-test.log" "log")

View file

@ -21,7 +21,6 @@
;;;; test runner ;;;; test runner
(defun run () (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")))
(load (t:test-path "config-csys" "etc")) (load (t:test-path "config-csys" "etc"))
(unwind-protect (unwind-protect
@ -31,4 +30,9 @@
(t:show-result)))) (t:show-result))))
(deftest test-basic () (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)
)