help-octave
[Top][All Lists]
Advanced

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

Re: Wrapper to use a C++ class in Octave


From: Mike Miller
Subject: Re: Wrapper to use a C++ class in Octave
Date: Thu, 10 Aug 2017 10:21:31 -0700
User-agent: NeoMutt/20170609 (1.8.3)

On Wed, Aug 09, 2017 at 23:40:49 +0200, Stefan Oltmanns wrote:
> The class is designed for non blocking operation and everything is done
> by a background thread (when result is ready the callback function is
> called).
> 
> Is there a simple way to write a wrapper around the class? Is there any
> example where something like this has been done?

This is certainly doable and has been done before. I can't say if you'll
call it simple. Take a look at Octave's own audioplayer and
audiorecorder classes, which have options to call user functions when
the audio driver needs data or has data ready.

  
https://hg.savannah.gnu.org/hgweb/octave/file/@/libinterp/dldfcn/audiodevinfo.cc

As a brief illustration, you would define a shim callback function that
can call a stored reference to an Octave function:

    static octave_function *octave_callback = nullptr;

    void real_callback_function (void)
    {
      if (octave_callback)
        feval (octave_callback, ovl (), 0);
    }

You would also want to translate any arguments or return values, there
are plenty of examples of that also

      octave_value_list args;
      args(0) = // translate from real_callback_function arguments
      args(1) = // ...

      octave_value_list out = feval (octave_callback, args, nout);
      // do something with return values out(0), out(1), etc.

-- 
mike

Attachment: signature.asc
Description: PGP signature


reply via email to

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