chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] weird FFI callbacks


From: Tomtom
Subject: [Chicken-users] weird FFI callbacks
Date: Thu, 31 Mar 2011 13:05:46 +0200
User-agent: Sup/0.11

Hi again, I'm back with this callback problem

quick summary: a jack client have to set a callback so the jack server can call
it when the client is supposed to do something. Here, the callback call is
supposed to trigger some scheme code execution.

Today I tried a different approach: writing the callback in C, and then calling
back to scheme from this function.

> // C part
> extern int process (jack_nframes_t);
> 
> int callback(jack_nframes_t nframes, void* arg)
> {
>     int i;
>     printf("callback\n");
>     for (i = 0 ; i < nframes ; i++) {
>       process(now);
>       now++;
>     }
>     return 0;
> }

> ;; Scheme part
> (define-external (process (unsigned-long now)) int
>   (display now)(newline)
>   now)

A manual call to callback shows the expected behaviour : printing callback, and
then the successive values of now.

> (define callback
>  (foreign-safe-lambda int "callback" jack_nframes (c-pointer void) ))
> (callback 5 #f)

Now, if I let the jack server do the job ...

> ((foreign-lambda* 
>   void ()
>   "jack_set_process_callback(client, callback, NULL);"))
> 
> (jack_activate client)

this is what I get :

> Error: call of non-procedure: #<unspecified>
> 
>       Call history:
> 
>       client.scm:58: display          
>       client.scm:58: newline          
>       client.scm:71: jack_activate            
>       ##sys#gc                
>       g2930           
>       client.scm:72: jack_deactivate          
>       client.scm:74: jack_client_close                
>       ##sys#implicit-exit-handler                     <--

And there I am, completely lost. Any clue ?

thanks for reading

tom

Attachment: callback.c
Description: Text document

Attachment: client.scm
Description: Binary data


reply via email to

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