1 ;;; riece-signal.el --- "signal-slot" abstraction for routing display events
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;;; This module implements Qt like "signal-slot" abstraction for
28 ;;; routing display events.
32 (require 'riece-options)
34 (defvar riece-signal-slot-obarray
37 (defun riece-make-slot (function &optional filter handback)
38 "Make an instance of slot object.
39 Arguments are corresponding to callback function, filter function, and
40 a handback object, respectively.
41 This function is for internal use only."
42 (vector function filter handback))
44 (defun riece-slot-function (slot)
45 "Return the callback function of SLOT.
46 This function is for internal use only."
49 (defun riece-slot-filter (slot)
50 "Return the filter function of SLOT.
51 This function is for internal use only."
54 (defun riece-slot-handback (slot)
55 "Return the handback object of SLOT.
56 This function is for internal use only."
59 (defun riece-make-signal (name args)
60 "Make an instance of signal object.
61 The 1st arguments is the name of the signal and the rest of arguments
62 are the data of the signal.
63 This function is for internal use only."
66 (defun riece-signal-name (signal)
67 "Return the name of SIGNAL."
70 (defun riece-signal-args (signal)
71 "Return the data of SIGNAL."
74 (defun riece-connect-signal (signal-name function &optional filter handback)
75 "Add SLOT as a listener of a signal identified by SIGNAL-NAME."
76 (let ((symbol (intern (symbol-name signal-name) riece-signal-slot-obarray)))
77 (set symbol (cons (riece-make-slot function filter handback)
79 (symbol-value symbol))))))
81 (defun riece-emit-signal (signal-name &rest args)
83 (let ((symbol (intern-soft (symbol-name signal-name)
84 riece-signal-slot-obarray))
88 (setq signal (riece-make-signal signal-name args)
89 slots (symbol-value symbol))
92 (if (or (null (riece-slot-filter (car slots)))
94 (funcall (riece-slot-filter (car slots)) signal)
98 "Error in signal filter for \"%S\": %S"
101 (funcall (riece-slot-function (car slots))
102 signal (riece-slot-handback (car slots))))
105 (message "Error in slot function for \"%S\": %S"
106 signal-name error))))
107 (setq slots (cdr slots))))))
109 (provide 'riece-signal)
111 ;;; riece-signal.el ends here