aboutsummaryrefslogtreecommitdiffstats
path: root/Lisp/moxie/default.lisp
blob: a408d6894af21c349e1fcd3bef4d12153e829e3e (plain)
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
;;; -*- Lisp -*-
;; $Id: world.lisp 20 2005-12-27 15:21:23Z bjc $
;;
;; Functions that should eventually be moved to the real plug in
;; support methodology (i.e., with nib files).
;;
(in-package :moxie)

(defun notify-front-end-load (&rest args)
  (declare (ignore args))
  (send-event-to-world *world* :change-settings (world-vars *world*)))

(defun notify-front-end-close (&rest args)
  (declare (ignore args))
  (send-event-to-world *world* :world-closed))

(defun notify-front-end-connect (&rest args)
  (declare (ignore args))
  (set-status-buffer "Connected")
  (send-event-to-world *world* :world-connected))

(defun notify-front-end-disconnect (&rest args)
  (declare (ignore args))
  (set-status-buffer "Disconnected")
  (send-event-to-world *world* :world-disconnected))

(defun notify-front-end-data (line)
  (print-to-world *world* line))

(defun notify-back-end-data (line)
  (print-to-world *world* (format nil "-> ~A~%" line)))

(defun notify-back-end-settings (alist)
  (when (world-save-path *world*)
    (format t "DEBUG: saving new settings: ~S~%" alist)
    (save-world-state *world*)))

(add-hook 'notify-front-end-load :world-loaded-hook)
(add-hook 'notify-front-end-close :world-closed-hook)
(add-hook 'notify-front-end-connect :world-connected-hook)
(add-hook 'notify-front-end-disconnect :world-disconnected-hook)
(add-hook 'notify-front-end-data :output-from-server-hook)
(add-hook 'notify-back-end-data :input-from-client-hook)
(add-hook 'notify-back-end-settings :setting-changed-hook)

(defun show-by-filter (key val &optional (test #'eql))
  (map-by-filter (lambda (world)
                   (format t "Matches ~S = ~S: ~S~%" key val world))
                 key val test))

(defun map-by-filter (fn key val &optional (test #'eql))
  (map-worlds (lambda (world)
                (when (funcall test (world-var key world) val)
                  (funcall fn world)))))

(defun do-auto-connect (&rest args)
  (declare (ignore args))
  (setf *tmp* *world*)
  (when (and (not (world-connected *world*)) (world-var :connect-on-open))
    (format t "DEBUG: auto-connecting to ~A:~A~%" (world-var :hostname) (world-var :port))
    (world-connect)))

(add-hook 'do-auto-connect :world-loaded-hook)