chiark / gitweb /
Definition of SIGNAL-NAME-TO-STRING moved to gobject.lisp
[clg] / glib / gcallback.lisp
index 72e24a9e4dd817cb38ed25c0a9504055b618246a..14ac0fbde8ecf7dac60599f0522cf3c7e7c3f5e6 100644 (file)
@@ -15,7 +15,7 @@
 ;; License along with this library; if not, write to the Free Software
 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-;; $Id: gcallback.lisp,v 1.2 2001-02-11 21:49:12 espen Exp $
+;; $Id: gcallback.lisp,v 1.7 2002-03-24 12:52:11 espen Exp $
 
 (in-package "GLIB")
 
@@ -26,20 +26,22 @@ (use-prefix "g")
 
 (deftype gclosure () 'pointer)
 
-(define-foreign lisp-callback-closure-new () gclosure
+(defbinding lisp-callback-closure-new () gclosure
   (callback-id unsigned-int))
 
+(defun register-callback-function (function)
+  (check-type function (or null symbol function))
+  (register-user-data function))
 
+(defun make-callback-closure (function)
+  (lisp-callback-closure-new (register-callback-function function)))
 
-;;;; Callback mechanism
 
-(defun register-callback-function (function)
-  (check-type function (or null symbol function))
-  (lisp-callback-closure-new (register-user-data function)))
+;;;; Callback mechanism
 
 (defun callback-trampoline (callback-id params return-value)
   (let* ((return-type (unless (null-pointer-p return-value)
-                       (type-from-number (gvalue-type return-value))))
+                       (gvalue-type return-value)))
         (args nil)
         (callback-function (find-user-data callback-id)))
 
@@ -50,9 +52,9 @@ (defun callback-trampoline (callback-id params return-value)
     (labels ((invoke-callback ()
               (restart-case
                   (unwind-protect
-                      (let ((result (apply callback-function args)))
+                      (let ((result (apply callback-function (reverse args))))
                         (when return-type
-                          (gvalue-set return-value result))))
+                          (gvalue-set (print return-value) result))))
                
                 (continue nil :report "Return from callback function"
                  (when return-type
@@ -77,17 +79,37 @@ (pushnew 'after-gc-hook ext:*after-gc-hooks*)
 (after-gc-hook)
 
 
+;;;; Timeouts and idle functions
 
-;;;; Signals
+(defvar *source-callback-marshal*
+  (system:foreign-symbol-address "source_callback_marshal"))
+(defvar *destroy-notify*
+  (system:foreign-symbol-address "destroy_notify"))
+
+(defbinding (timeout-add "g_timeout_add_full")
+    (function interval &optional (priority 0)) unsigned-int 
+  (priority int)
+  (interval unsigned-int)
+  (*source-callback-marshal* pointer)
+  ((register-callback-function function) unsigned-long)
+  (*destroy-notify* pointer))
 
-(defun signal-name-to-string (name)
-  (substitute #\_ #\- (string-downcase (string name))))
+(defbinding (idle-add "g_idle_add_full")
+    (function &optional (priority 0)) unsigned-int 
+  (priority int)
+  (*source-callback-marshal* pointer)
+  ((register-callback-function function) unsigned-long)
+  (*destroy-notify* pointer))
 
-(define-foreign signal-lookup (name itype) unsigned-int
+
+
+;;;; Signals
+
+(defbinding signal-lookup (name itype) unsigned-int
   ((signal-name-to-string name) string)
   (itype type-number))
 
-(define-foreign signal-name () string
+(defbinding signal-name () string
   (signal-id unsigned-int))
 
 (defun ensure-signal-id (signal-id instance)
@@ -96,27 +118,27 @@ (defun ensure-signal-id (signal-id instance)
     (string (signal-lookup signal-id (type-number-of instance)))
     (symbol (signal-lookup signal-id (type-number-of instance)))))
   
-(define-foreign signal-stop-emission (instance signal-id) nil
+(defbinding signal-stop-emission (instance signal-id) nil
   (instance ginstance)
   ((ensure-signal-id signal-id instance) unsigned-int))
 
-; (define-foreign ("g_signal_add_emission_hook_full" signal-add-emisson-hook)
+; (defbinding (signal-add-emisson-hook "g_signal_add_emission_hook_full")
 ;     () unsigned-int
 ;   (signal-id unsigned-int)
 ;   (closure gclosure))
 
-; (define-foreign signal-remove-emisson-hook () nil
+; (defbinding signal-remove-emisson-hook () nil
 ;   (signal-id unsigned-int)
 ;   (hook-id unsigned-int))
 
-(define-foreign ("g_signal_has_handler_pending" signal-has-handler-pending-p)
+(defbinding (signal-has-handler-pending-p "g_signal_has_handler_pending")
     (instance signal-id &key detail blocked) boolean
   (instance ginstance)
   ((ensure-signal-id signal-id instance) unsigned-int)
   ((or detail 0) quark)
   (blocked boolean))
     
-(define-foreign ("g_signal_connect_closure_by_id" signal-connect-closure)
+(defbinding (signal-connect-closure "g_signal_connect_closure_by_id")
     (instance signal-id closure &key detail after) unsigned-int
   (instance ginstance)
   ((ensure-signal-id signal-id instance) unsigned-int)
@@ -124,36 +146,31 @@ (define-foreign ("g_signal_connect_closure_by_id" signal-connect-closure)
   (closure gclosure)
   (after boolean))
 
-(define-foreign signal-handler-block () nil
+(defbinding signal-handler-block () nil
   (instance ginstance)
   (handler unsigned-int))
 
-(define-foreign signal-handler-unblock () nil
+(defbinding signal-handler-unblock () nil
   (instance ginstance)
   (handler unsigned-int))
 
-(define-foreign signal-handler-disconnect () nil
+(defbinding signal-handler-disconnect () nil
   (instance ginstance)
   (handler unsigned-int))
 
 
-(defun signal-connect (instance signal function &key after object)
-  (let ((callback
-        (cond
-         ((or (eq object t) (eq object instance)) function)
-         ((not object)
-          #'(lambda (&rest args) (apply function (cdr args))))
-         (t
-          #'(lambda (&rest args) (apply function object (rest args)))))))
-    
-    (signal-connect-closure
-     instance signal (register-callback-function callback) :after after)))
-
+(defmethod signal-connect ((gobject gobject) signal function &rest args &key after object)
+  (declare (ignore signal args after))
+  (cond
+   ((or (eq object t) (eq object gobject)) function)
+   ((not object)
+    #'(lambda (&rest args) (apply function (cdr args))))
+   (t
+    #'(lambda (&rest args) (apply function object (rest args))))))
 
-;;;; Idles and timeouts
 
-; (defun timeout-remove (tag)
-;   (source-remove tag))
-  
-; (defun idle-remove (tag)
-;   (source-remove tag))
+(defmethod signal-connect :around ((gobject gobject) signal function
+                                  &key after object)
+  (declare (ignore object))
+  (let ((callback-id (make-callback-closure (call-next-method))))
+    (signal-connect-closure gobject signal callback-id :after after)))