1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2005 Espen S. Johnsen <espen@users.sf.net>
4 ;; This library is free software; you can redistribute it and/or
5 ;; modify it under the terms of the GNU Lesser General Public
6 ;; License as published by the Free Software Foundation; either
7 ;; version 2 of the License, or (at your option) any later version.
9 ;; This library is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;; Lesser General Public License for more details.
14 ;; You should have received a copy of the GNU Lesser General Public
15 ;; License along with this library; if not, write to the Free Software
16 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ;; $Id: gerror.lisp,v 1.1 2005/02/14 00:39:39 espen Exp $
23 (defclass gerror (struct)
24 ((domain :allocation :alien :type quark :reader gerror-domain)
25 (code :allocation :alien :type int :reader gerror-code)
26 (message :allocation :alien :type string :reader gerror-message))
27 (:metaclass struct-class))
29 (defbinding (%gerror-copy "g_error_copy") () pointer
32 (defbinding (%gerror-free "g_error_free") () nil
35 (defmethod reference-foreign ((class (eql (find-class 'gerror))) location)
36 (declare (ignore class))
37 (%gerror-copy location))
39 (defmethod unreference-foreign ((class (eql (find-class 'gerror))) location)
40 (declare (ignore class))
41 (%gerror-free location))
44 (define-condition glib-error (error)
45 ((code :initarg :domain :reader gerror-code)
46 (message :initarg :message :reader gerror-message))
47 (:report (lambda (condition stream)
48 (write-string (gerror-message condition) stream))))
50 (define-condition glib-file-error (glib-error)
53 (defbinding file-error-quark () quark)
55 (defun signal-gerror (gerror)
58 ((= (gerror-domain gerror) (file-error-quark)) 'glib-file-error)
60 (error condition :code (gerror-code gerror) :message (gerror-message gerror))))
65 (eval-when (:compile-toplevel :load-toplevel :execute)
66 (deftype log-levels ()
68 :recursion :fatal ;; These are not real log-levels, but flags
77 (define-condition log-level (warning)
78 ((domain :initarg :domain :reader log-domain)
79 (message :initarg :message :reader log-message))
80 (:report (lambda (condition stream)
81 (format stream "~A: ~A"
82 (log-domain condition) (log-message condition)))))
84 (define-condition unknown-log-level (log-level)
87 (define-condition error-log-level (log-level)
90 (define-condition critical-log-level (log-level)
93 (define-condition warning-log-level (log-level)
96 (define-condition info-log-level (log-level)
99 (define-condition debug-log-level (log-level)
102 (defparameter *fatal-log-levels* '(error-log-level critical-log-level))
104 (defcallback log-handler (nil
105 (domain (copy-of string))
106 (log-level log-levels)
107 (message (copy-of string)))
109 (find :fatal log-level)
111 #'(lambda (level) (find level *fatal-log-levels*))
115 #'(lambda (level) (subtypep level 'condition))
117 'unknown-log-level)))
118 (funcall (if fatal-p #'error #'warn) condition
119 :domain domain :message message)))
121 (setf (extern-alien "log_handler" system-area-pointer) (callback log-handler))
126 ;; Unfortunately this will only work as long as we don't abort to
127 ;; toplevel from within the log handler. If we do that, the next
128 ;; invocation of g_log will be handled as a recursion and cause an
129 ;; abort (SIGABORT being signaled). To make things even worse, SBCL
130 ;; doesn't handle SIGABRT at all.
131 (defbinding %log-set-default-handler () pointer
132 ((callback log-handler) pointer)
134 (%log-set-default-handler))