-
Notifications
You must be signed in to change notification settings - Fork 9
/
states.lisp
69 lines (62 loc) · 2.97 KB
/
states.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
60
61
62
63
64
65
66
67
68
69
;;; -*- Package: de.setf.amqp.implementation; -*-
(in-package :de.setf.amqp.implementation)
(:documentation "This file defines the state model for AMQP classes for the 'de.setf.amqp' library."
(copyright
"Copyright 2010 [james anderson](mailto:[email protected]) All Rights Reserved"
"'de.setf.amqp' is free software: you can redistribute it and/or modify it under the terms of version 3
of the GNU Affero General Public License as published by the Free Software Foundation.
'setf.amqp' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the Affero General Public License for more details.
A copy of the GNU Affero General Public License should be included with 'de.setf.amqp' as `AMQP:agpl.txt`.
If not, see the GNU [site](http://www.gnu.org/licenses/)."))
;;;
;;; states
(macrolet ((defstate (name supers slots &rest options)
(setf name (intern (string name) :de.setf.amqp-state))
(setf supers (or (mapcar #'(lambda (s) (intern (string s) :de.setf.amqp-state)) supers)
(unless (eq name 'amqp.s:state) '(de.setf.amqp-state:state))))
`(prog1 (defclass ,name ,supers ,slots ,@options)
(eval-when (:compile-toplevel :load-toplevel :execute)
(export ',name :de.setf.amqp-state))
(defparameter ,name (make-instance ',name))))
(defstates (&rest states)
`(progn ,@(loop for state in states
collect (etypecase state
(symbol
`(defstate ,state () ()))
(cons
(destructuring-bind (name supers &optional slots &rest options) state
`(defstate ,name ,supers ,slots ,@options ))))))))
(defstates
state
connection-state
channel-state
open
(open-connection (open connection-state))
(open-connection.start (open-connection))
(open-connection.secure (open-connection))
(open-connection.tune (open-connection))
(open-connection.host (open-connection))
(open-channel (open channel-state))
use
(use-connection (use connection-state))
(use-channel (use channel-state))
body
input
output
chunked
(use-channel.body (use-channel body))
(use-channel.body.input (use-channel.body input))
(use-channel.body.input.chunked (chunked use-channel.body.input))
(use-channel.body.output (use-channel.body output))
(use-channel.body.output.chunked (chunked use-channel.body.output))
method
(use-channel.method (use-channel method))
header
(use-channel.header (use-channel header))
heartbeat
(use-channel.heartbeat (use-channel heartbeat))
close
(close-connection (close connection-state))
(close-channel (close channel-state))))