chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] callbacks from C into Scheme


From: Shawn Rutledge
Subject: [Chicken-users] callbacks from C into Scheme
Date: Wed, 19 Mar 2008 22:51:23 -0700

This is intended to wrap a given Scheme callback as a C function, and
make some C library calls, then under the right conditions, call the
wrapped callback.  After several sessions of staring at it, I still
don't understand why this doesn't work.  Probably missing something
stupid though.

        (set! dbus:poll-for-message (lambda (context timeout msg-cb)
                (let ([conn (get-conn (vector-ref context context-idx-bus))]
                                [iface (vector-ref context 
context-idx-interface)] )
                        (define-external (C_msg_cb (message-ptr msg)) void
                                (printf "calling msg-cb~%")
                                ;(msg-cb msg)
                        )
                        ((foreign-safe-lambda* message-ptr ((connection-ptr 
conn) (int
timeout) (c-string iface))
                                "DBusMessage* msg = NULL;
                                dbus_connection_read_write(conn, timeout);
                                msg = dbus_connection_pop_message(conn);
                                if (msg)
                                {
                                        printf(\"rcv: %s, looking for %s\\n\",
dbus_message_get_interface(msg), iface);
                                        if (dbus_message_has_interface(msg, 
iface))
                                        {
                                                printf(\"calling cb from 
c\\n\");
                                                C_msg_cb(msg);
                                                printf(\"cb done, from c\\n\");
                                        }
                                }") conn timeout iface))))

calling cb from c
Warning (#<thread: thread0>): : bad argument count - received 1 but
expected 0: #<procedure>

        Call history:

        ##sys#gc
        ##sys#make-c-string
        dbus.scm: 230  thread-sleep!
        dbus.scm: 231  loop
        dbus.scm: 229  dbus:poll-for-message
        dbus.scm: 203  get-conn
        ##sys#gc
        ##sys#make-c-string                     <--

Seems like it's dying at

C_msg_cb(msg);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]