-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
standard-events.lisp
59 lines (44 loc) · 1.83 KB
/
standard-events.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(in-package #:org.shirakumo.maiden)
(defgeneric respond (event &key &allow-other-keys))
(defmethod respond ((event event) &rest args &key (class (class-of event)) &allow-other-keys)
(issue (apply #'make-instance class args)
(event-loop event)))
(define-event passive-event ()
())
(define-event active-event ()
())
(define-event client-event ()
((client :initarg :client :reader client))
(:default-initargs
:client (error "CLIENT required.")))
(defmethod respond ((event client-event) &rest args &key (class (class-of event)) &allow-other-keys)
(remf args :class)
(issue (apply #'make-instance class :client (client event) args)
(event-loop event)))
(define-event instruction-event (active-event)
())
(define-event query-event (identified-event instruction-event)
())
(defmethod respond ((event query-event) &key payload)
(issue (make-instance 'response-event :identifier (identifier event)
:payload payload)
(event-loop event)))
(define-event response-event (identified-event payload-event passive-event)
()
(:default-initargs :identifier (error "IDENTIFIER required.")))
(define-event core-event ()
())
(define-event consumer-added (core-event passive-event)
((consumer :initarg :consumer))
(:default-initargs
:consumer (error "CONSUMER required.")))
(defmethod print-object ((event consumer-added) stream)
(print-unreadable-object (event stream :type T :identity T)
(format stream "~a" (slot-value event 'consumer))))
(define-event consumer-removed (core-event passive-event)
((consumer :initarg :consumer))
(:default-initargs
:consumer (error "CONSUMER required.")))
(defmethod print-object ((event consumer-removed) stream)
(print-unreadable-object (event stream :type T :identity T)
(format stream "~a" (slot-value event 'consumer))))