[OSC_dev] advice for callback (oscit)

Gaspard Bucher gaspard at teti.ch
Fri Dec 26 08:43:08 PST 2008


Hi list !

I started extracting the library from rubyk but I jump on a difficult
problem: in rubyk all values passed between objects and used in OSC
calls are sub-classes of Value (a smart pointer with reference
counting). This means every function has the type:

const Value method_name (const Value& param)

A "Value" can be a Number, a Hash, a Matrix, a String or just Nil
(Array coming soon).

All this is fine in a C++ environment but I do not see how we could
easily use the "value" stuff in a plain C interface.

========= oscit C interface ========

The values will be replaced by an array of union [float / int / string
/ xxx]. So the signature of registering methods will be (C interface)
:

void my_function(OscVal * ret, const OscVal * arg)

You register the function with something like:

register_method("/some/url", my_function, "ffi")

Inside "my_function", values are simply retrieved with:

arg[0]->f = float
arg[1]->i = int
etc.

Type checking is done by "oscit", the only verification should be (arg
== NULL) because methods can either receive the correct signature or
Nil.

The storage space for return values is also prepared and the function
should just write:

ret[0]->f = ...
ret[1]->i = ...
etc

This setting has the following advantages:

1. fast to parse
2. no dynamic memory allocation during runtime (done once on
registration for "ret" and "arg")

The drawbacks are:

1. fixed type signature
2. same type signature for argument and return value

Does this seem ok for the "C" users out there ?

========= oscit C++ interface ========

For the "C++" users, the idea is to build the "tree" structure by
creating sub-classes of "oscit::Object" and using code such as:

class Effect : public oscit::Object
{
  virtual const String info()
  {
    return String("I am a great super genius effect");
  }
  // etc
};

oscit::Root root; ==> lives at url ""

root.adopt( new Effect("foo", ...) );  ==> lives at url "/foo"

In the Effect initialization code, you have things like:

adopt( new Method<Effect,&Effect::filter>("filter", "f", ...) ) ==>
new url "/foo/filter"

What do you think ?

Gaspard


More information about the OSC_dev mailing list