chiark / gitweb /
Changed return type for SIGNAL-NAME
[clg] / glib / gcallback.lisp
index d80f89fd2cc0b083fc420bfcab971806e7c588e6..357535d94b434cacfdda31a3e6511425fb3699dc 100644 (file)
@@ -20,7 +20,7 @@
 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-;; $Id: gcallback.lisp,v 1.40 2007-02-19 13:46:44 espen Exp $
+;; $Id: gcallback.lisp,v 1.49 2008-04-11 20:51:45 espen Exp $
 
 (in-package "GLIB")
 
@@ -36,26 +36,37 @@ (defun register-callback-function (function)
   (check-type function (or null symbol function))
   (register-user-data function))
 
+(deftype user-callback () '(or function symbol))
+
+(define-type-method alien-type ((type user-callback))
+  (declare (ignore type))
+  (alien-type 'pointer-data))
+
+(define-type-method to-alien-form ((type user-callback) func &optional copy-p)
+  (declare (ignore type copy-p))
+  `(register-callback-function ,func))
+
+
 ;; Callback marshaller for regular signal handlers
 (define-callback signal-handler-marshal nil
     ((gclosure gclosure) (return-value gvalue) (n-params unsigned-int) 
      (param-values pointer) (invocation-hint pointer) 
-     (callback-id unsigned-long))
+     (callback-id pointer-data))
   (declare (ignore gclosure invocation-hint))
   (callback-trampoline #'invoke-signal-handler callback-id n-params param-values return-value))
 
-;; Callback marshaller  for class handlers
+;; Callback marshaller for class handlers
 (define-callback class-handler-marshal nil
     ((gclosure gclosure) (return-value gvalue) (n-params unsigned-int) 
      (param-values pointer) (invocation-hint pointer) 
-     (callback-id unsigned-long))
+     (callback-id pointer-data))
   (declare (ignore gclosure invocation-hint))
   (callback-trampoline #'invoke-callback callback-id n-params param-values return-value))
 
 ;; Callback marshaller for emission hooks
 (define-callback emission-hook-marshal nil
     ((invocation-hint pointer) (n-params unsigned-int) (param-values pointer)
-     (callback-id unsigned-long))
+     (callback-id pointer-data))
   (declare (ignore invocation-hint))
   (callback-trampoline #'invoke-callback callback-id n-params param-values))
 
@@ -87,12 +98,12 @@ (defun invoke-signal-handler (callback-id return-type &rest args)
     (signal-handler-block instance handler-id)
     (unwind-protect
        (restart-case (apply #'invoke-callback callback-id nil args)
-         (abort () :report "Disconnect and exit signal handler"
+         (disconnect () :report "Disconnect and exit signal handler"
            (when (signal-handler-is-connected-p instance handler-id)
              (signal-handler-disconnect instance handler-id))
-           (values nil t))))
+           (values nil t)))
       (when (signal-handler-is-connected-p instance handler-id)
-       (signal-handler-unblock instance handler-id))))
+       (signal-handler-unblock instance handler-id)))))
 
 (defun invoke-callback (callback-id return-type &rest args)
   (restart-case (apply (find-user-data callback-id) args)
@@ -118,8 +129,18 @@ (defconstant +priority-low+ 300)
 (defbinding source-remove () boolean
   (tag unsigned-int))
 
-(define-callback source-callback-marshal nil ((callback-id unsigned-int))
-  (callback-trampoline #'invoke-callback callback-id 0 nil))
+(define-callback source-callback-marshal boolean ((callback-id unsigned-int))
+  (invoke-source-callback callback-id))
+
+(defun invoke-source-callback (callback-id &rest args)
+  (restart-case (apply (find-user-data callback-id) args)
+    (remove () :report "Exit and remove source callback"
+      nil)
+    (continue () :report "Return from source callback"
+      t)
+    (re-invoke nil :report "Re-invoke source callback"
+      (apply #'invoke-source-callback callback-id args))))
+
 
 (defbinding (timeout-add "g_timeout_add_full")
     (interval function &optional (priority +priority-default+)) unsigned-int 
@@ -149,7 +170,7 @@ (defbinding signal-lookup (name type) unsigned-int
   ((signal-name-to-string name) string)
   ((find-type-number type t) type-number))
 
-(defbinding signal-name () (copy-of string)
+(defbinding signal-name () (or null (copy-of string))
   (signal-id unsigned-int))
 
 (defbinding signal-list-ids (type) (vector unsigned-int n-ids)
@@ -223,6 +244,8 @@ (defun describe-signal (signal-id &optional type)
 
 ;;;; Signal connecting and controlling
 
+(define-flags-type connect-flags :after :swapped)
+
 (defvar *overridden-signals* (make-hash-table :test 'equalp))
 
 (defbinding %signal-override-class-closure () nil
@@ -352,7 +375,7 @@ (defbinding signal-handler-find () unsigned-long
   (detail quark)
   (closure (or null pointer))
   (func (or null pointer))
-  (data unsigned-long))
+  (data pointer-data))
 
 (defbinding signal-handler-disconnect () nil
   (instance ginstance)
@@ -377,7 +400,7 @@ (defun callback-closure-new (callback-id callback destroy-notify)
     (closure-set-meta-marshal gclosure callback-id callback)
     gclosure))
 
-(defun make-callback-closure (function marshaller)
+(defun make-callback-closure (function &optional (marshaller signal-handler-marshal))
   (let ((callback-id (register-callback-function function)))
     (values
      (callback-closure-new callback-id marshaller user-data-destroy-callback)
@@ -473,7 +496,7 @@ (defun create-signal-emit-function (signal-id)
           (params (allocate-memory (* n-params +gvalue-size+))))
       #'(lambda (detail object &rest args)
          (unless (= (length args) (1- n-params))
-           (error "Invalid number of arguments: ~A" (+ 2 (length args))))
+           (error "Invalid number of arguments in emmision of signal ~A: ~A" signal-id (length args)))
          (unwind-protect
              (loop
               for arg in (cons object args)
@@ -483,7 +506,7 @@ (defun create-signal-emit-function (signal-id)
               finally 
               (if return-type
                   (return 
-                   (with-gvalue (return-value)
+                   (with-gvalue (return-value return-type)
                      (%signal-emitv params signal-id detail return-value)))
                 (%signal-emitv params signal-id detail (make-pointer 0))))
            (loop