chiark / gitweb /
Added declaration to get rid of a couple of warnings.
[clg] / glib / gcallback.lisp
index 3ad404271bd94d7d404e0a051770448636322aa0..3eac603223828d586d99762915095ca5f1686766 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.18 2005-01-30 14:23:20 espen Exp $
+;; $Id: gcallback.lisp,v 1.23 2005-03-06 17:18:00 espen Exp $
 
 (in-package "GLIB")
 
@@ -28,9 +28,6 @@ (defun register-callback-function (function)
   (check-type function (or null symbol function))
   (register-user-data function))
 
-(defcallback %destroy-user-data (nil (id unsigned-int))
-  (destroy-user-data id))
-
 ;; Callback marshal for regular signal handlers
 (defcallback closure-marshal (nil
                              (gclosure pointer)
@@ -39,6 +36,7 @@ (defcallback closure-marshal (nil
                              (param-values pointer)
                              (invocation-hint pointer) 
                              (callback-id unsigned-int))
+  (declare (ignore gclosure invocation-hint))
   (callback-trampoline callback-id n-params param-values return-value))
 
 ;; Callback function for emission hooks
@@ -92,7 +90,7 @@ (defbinding (timeout-add "g_timeout_add_full")
   (interval unsigned-int)
   ((callback source-callback-marshal) pointer)
   ((register-callback-function function) unsigned-long)
-  ((callback %destroy-user-data) pointer))
+  ((callback user-data-destroy-func) pointer))
 
 (defun timeout-remove (timeout)
   (source-remove timeout))
@@ -102,7 +100,7 @@ (defbinding (idle-add "g_idle_add_full")
   (priority int)
   ((callback source-callback-marshal) pointer)
   ((register-callback-function function) unsigned-long)
-  ((callback %destroy-user-data) pointer))
+  ((callback user-data-destroy-func) pointer))
 
 (defun idle-remove (idle)
   (source-remove idle))
@@ -203,7 +201,7 @@ (defbinding signal-add-emission-hook (type signal function &key (detail 0))
   (detail quark)
   ((callback signal-emission-hook) pointer)
   ((register-callback-function function) unsigned-int)
-  ((callback %destroy-user-data) pointer))
+  ((callback user-data-destroy-func) pointer))
 
 (defbinding signal-remove-emission-hook (type signal hook-id) nil
   ((ensure-signal-id-from-type signal type) unsigned-int)
@@ -215,7 +213,7 @@ (defbinding (signal-has-handler-pending-p "g_signal_has_handler_pending")
   (instance ginstance)
   ((ensure-signal-id signal-id instance) unsigned-int)
   ((or detail 0) quark)
-  (may-be-blocked boolean))
+  (blocked boolean))
     
 (defbinding %signal-connect-closure-by-id () unsigned-int
   (instance ginstance)
@@ -252,19 +250,37 @@ (defun make-callback-closure (function)
     (values
      (callback-closure-new 
       callback-id (callback closure-marshal) 
-      (callback %destroy-user-data))
+      (callback user-data-destroy-func))
      callback-id)))
 
-(defmethod create-callback-function ((gobject gobject) function arg1)
+(defgeneric compute-signal-function (gobject signal function object))
+
+(defmethod compute-signal-function ((gobject gobject) signal function object)
+  (declare (ignore signal))
   (cond
-   ((or (eq arg1 t) (eq arg1 gobject)) function)
-   ((not arg1)
+   ((or (eq object t) (eq object gobject)) function)
+   ((not object)
     #'(lambda (&rest args) (apply function (rest args))))
    (t
-    #'(lambda (&rest args) (apply function arg1 (rest args))))))
+    #'(lambda (&rest args) (apply function object (rest args))))))
+
+
+(defgeneric compute-signal-id (gobject signal))
+
+(defmethod compute-signal-id ((gobject gobject) signal)
+  (ensure-signal-id signal gobject))
+
+
+(defgeneric signal-connect (gobject signal function &key detail after object remove))
+
+(defmethod signal-connect :around ((gobject gobject) signal function &rest args)
+  (declare (ignore gobject signal args))
+  (when function
+    (call-next-method)))
+
 
 (defmethod signal-connect ((gobject gobject) signal function
-                          &key (detail 0) after object remove)
+                          &key detail after object remove)
 "Connects a callback function to a signal for a particular object. If
 :OBJECT is T, the object connected to is passed as the first argument
 to the callback function, or if :OBJECT is any other non NIL value, it
@@ -272,19 +288,19 @@ (defmethod signal-connect ((gobject gobject) signal function
 handler will be called after the default handler for the signal. If
 :REMOVE is non NIL, the handler will be removed after beeing invoked
 once."
-  (when function
-    (let* ((signal-id (ensure-signal-id signal gobject))
-          (signal-stop-emission
-           #'(lambda ()
-               (%signal-stop-emission gobject signal-id detail)))
-          (callback (create-callback-function gobject function object))
-          (wrapper #'(lambda (&rest args)
-                       (let ((*signal-stop-emission* signal-stop-emission))
-                         (apply callback args)))))
+(let* ((signal-id (compute-signal-id gobject signal))
+       (detail-quark (if detail (quark-intern detail) 0))
+       (signal-stop-emission
+       #'(lambda ()
+           (%signal-stop-emission gobject signal-id detail-quark)))
+       (callback (compute-signal-function gobject signal function object))
+       (wrapper #'(lambda (&rest args)
+                   (let ((*signal-stop-emission* signal-stop-emission))
+                     (apply callback args)))))
       (multiple-value-bind (closure-id callback-id)
          (make-callback-closure wrapper)
        (let ((handler-id (%signal-connect-closure-by-id 
-                          gobject signal-id detail closure-id after)))
+                          gobject signal-id detail-quark closure-id after)))
          (when remove
            (update-user-data callback-id
             #'(lambda (&rest args)
@@ -292,7 +308,7 @@ (defmethod signal-connect ((gobject gobject) signal function
                     (let ((*signal-stop-emission* signal-stop-emission))
                       (apply callback args))
                   (signal-handler-disconnect gobject handler-id)))))
-         handler-id)))))
+         handler-id))))
 
 
 ;;;; Signal emission
@@ -346,19 +362,6 @@ (defun signal-emit (object signal &rest args)
   (apply #'signal-emit-with-detail object signal 0 args))
 
 
-
-;;; Message logging
-
-;; TODO: define and signal conditions based on log-level
-
-(def-callback log-handler (c-call:void (domain c-call:c-string) 
-                                      (log-level c-call:int) 
-                                      (message c-call:c-string))
-  (error "~A: ~A" domain message))
-
-(setf (extern-alien "log_handler" system-area-pointer) (callback log-handler))
-
-
 ;;;; Convenient macros
 
 (defmacro def-callback-marshal (name (return-type &rest args))