X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/e7225d0fbfd6ba01fc0a5125af1ab7b4f84bbe61..c4fb29d01d845c8964ce2874516811d952461210:/glib/gcallback.lisp diff --git a/glib/gcallback.lisp b/glib/gcallback.lisp index 2ee583f..79d3413 100644 --- a/glib/gcallback.lisp +++ b/glib/gcallback.lisp @@ -20,14 +20,14 @@ ;; 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.36 2006-07-14 10:51:07 espen Exp $ +;; $Id: gcallback.lisp,v 1.42 2007-05-10 20:25:09 espen Exp $ (in-package "GLIB") (use-prefix "g") -;;;; Callback invokation +;;;; Callback invocation (deftype gclosure () 'pointer) (register-type 'gclosure '|g_closure_get_type|) @@ -40,22 +40,22 @@ (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)) @@ -119,7 +119,7 @@ (tag unsigned-int)) (define-callback source-callback-marshal nil ((callback-id unsigned-int)) - (callback-trampoline callback-id 0 nil)) + (callback-trampoline #'invoke-callback callback-id 0 nil)) (defbinding (timeout-add "g_timeout_add_full") (interval function &optional (priority +priority-default+)) unsigned-int @@ -207,16 +207,18 @@ (defun describe-signal (signal-id &optional type) (let ((info (signal-query (ensure-signal-id-from-type signal-id type)))) (with-slots (id name type flags return-type n-params) info - (format t "The signal with id ~D is named '~A' and may be emitted on instances of type ~S~%~%" id name (type-from-number type t)) - (format t "Signal handlers should return ~A and take ~A~%" - (cond - ((= return-type (find-type-number "void")) "no values") - ((not (type-from-number return-type)) "values of unknown type") - ((format nil "values of type ~S" (type-from-number return-type)))) + (format t "The signal with id ~D is named '~A' and may be emitted on instances of type ~S." id name (type-from-number type t)) + (when flags + (format t " It has the followin invocation flags: ~{~S ~}" flags)) + (format t "~%~%Signal handlers should take ~A and return ~A~%" (if (zerop n-params) "no arguments" (format nil "arguments with the following types: ~A" - (signal-param-types info))))))) + (signal-param-types info))) + (cond + ((= return-type (find-type-number "void")) "no values") + ((not (type-from-number return-type)) "values of unknown type") + ((format nil "values of type ~S" (type-from-number return-type)))))))) ;;;; Signal connecting and controlling @@ -350,7 +352,7 @@ (detail quark) (closure (or null pointer)) (func (or null pointer)) - (data unsigned-long)) + (data pointer-data)) (defbinding signal-handler-disconnect () nil (instance ginstance) @@ -360,28 +362,49 @@ (instance ginstance) (handler-id unsigned-long)) -(defbinding (callback-closure-new "clg_callback_closure_new") () gclosure +(defbinding (closure-new "g_cclosure_new") () gclosure + ((make-pointer #xFFFFFFFF) pointer) (callback-id unsigned-int) - (callback callback) (destroy-notify callback)) -(defun make-callback-closure (function marshaller) +(defbinding closure-set-meta-marshal () nil + (gclosure gclosure) + (callback-id unsigned-int) + (callback callback)) + +(defun callback-closure-new (callback-id callback destroy-notify) + (let ((gclosure (closure-new callback-id destroy-notify))) + (closure-set-meta-marshal gclosure callback-id callback) + gclosure)) + +(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) callback-id))) -(defgeneric compute-signal-function (gobject signal function object)) +(defgeneric compute-signal-function (gobject signal function object args)) -(defmethod compute-signal-function ((gobject gobject) signal function object) +(defmethod compute-signal-function ((gobject gobject) signal function object args) (declare (ignore signal)) (cond - ((or (eq object t) (eq object gobject)) function) - ((not object) - #'(lambda (&rest args) (apply function (rest args)))) + ((or (eq object t) (eq object gobject)) + (if args + #'(lambda (&rest emission-args) + (apply function (nconc emission-args args))) + function)) + (object + (if args + #'(lambda (&rest emission-args) + (apply function object (nconc (rest emission-args) args))) + #'(lambda (&rest emission-args) + (apply function object (rest emission-args))))) + (args + #'(lambda (&rest emission-args) + (apply function (nconc (rest emission-args) args)))) (t - #'(lambda (&rest args) (apply function object (rest args)))))) - + #'(lambda (&rest emission-args) + (apply function (rest emission-args)))))) (defgeneric compute-signal-id (gobject signal)) @@ -389,7 +412,7 @@ (ensure-signal-id signal gobject)) -(defgeneric signal-connect (gobject signal function &key detail after object remove)) +(defgeneric signal-connect (gobject signal function &key detail after object remove args)) (defmethod signal-connect :around ((gobject gobject) signal function &rest args) (declare (ignore gobject signal args)) @@ -398,20 +421,21 @@ (defmethod signal-connect ((gobject gobject) signal function - &key detail after object remove) + &key detail after object remove args) "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 is passed as the first argument instead. If :AFTER is non NIL, the 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." +once. ARGS is a list of additional arguments passed to the callback +function." (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)) + (callback (compute-signal-function gobject signal function object args)) (wrapper #'(lambda (&rest args) (let ((*signal-stop-emission* signal-stop-emission)) (apply callback args))))) @@ -481,6 +505,25 @@ once." (apply #'signal-emit-with-detail object signal 0 args)) +;;;; Signal registration + +(defbinding %signal-newv (name itype flags return-type param-types) + unsigned-int + ((signal-name-to-string name) string) + (itype gtype) + (flags signal-flags) + (nil null) ; class closure + (nil null) ; accumulator + (nil null) ; accumulator data + (nil null) ; c marshaller + (return-type gtype) + ((length param-types) unsigned-int) + (param-types (vector gtype))) + +(defun signal-new (name itype flags return-type param-types) + (when (zerop (signal-lookup name itype)) + (%signal-newv name itype flags return-type param-types))) + ;;;; Convenient macros (defmacro define-callback-marshal (name return-type args &key (callback-id :last)) @@ -507,8 +550,8 @@ once." (t (second arg)))))) `(define-callback ,name ,return-type ,(ecase callback-id - (:first `((callback-id unsigned-int) ,@(mapcar #'list names types))) - (:last `(,@(mapcar #'list names types) (callback-id unsigned-int)))) + (:first `((callback-id pointer-data) ,@(mapcar #'list names types))) + (:last `(,@(mapcar #'list names types) (callback-id pointer-data)))) (declare (ignore ,@ignore)) (invoke-callback callback-id ',return-type ,@(nreverse params)))))