librelist archives

« back to archive

Ruby wrapper for the Firebird SQL C++ API

Ruby wrapper for the Firebird SQL C++ API

From:
Pierre Y.
Date:
2011-12-10 @ 00:59
Hi all,

The Firebird SQL [1] project team is working on the new Firebird 3
version [2] that will be out at the end of next year. They will
provide a fresh new C++ API and I want to write a new Ruby driver for
Firebird using this API.

An example of use of this API in C++ has been made by one of the core
team member and is here [3]

Somebody told me about RICE to create Ruby wrapper around C++ code.

But I don't know where to start. What I know is that the "old/legacy"
Firebird C API in libfbclient.so now exposes a new function called
"fb_get_master_interface" that returns an instance of a pure virtual
C++ class called IMaster from where everything in the new API is
accessible. Instance of classes that will be returned from IMaster are
refcounted and they are all pure virtual classes.

The header files for the pure virtual classes are here [4]

My questions : Is RICE the right tool to wrap this kind of API ? Do
you have an example of code from where I could start ? I'm more a
"Delphi/Windows" developer and quite good at Ruby but not so much
fluent with C++ and Ruby extensions/gems.

Many thanks for your help, regards,

--
Pierre Yager

[1] http://firebirdsql.org
[2] https://github.com/asfernandes/firebird
[3] https://github.com/asfernandes/fbstuff
[4] https://github.com/asfernandes/firebird/tree/master/src/include/firebird

Re: [rice] Ruby wrapper for the Firebird SQL C++ API

From:
Jason Roelofs
Date:
2011-12-10 @ 17:07
On Dec 9, 2011, at 7:59 PM, Pierre Y. wrote:

> Hi all,
> 
> The Firebird SQL [1] project team is working on the new Firebird 3
> version [2] that will be out at the end of next year. They will
> provide a fresh new C++ API and I want to write a new Ruby driver for
> Firebird using this API.
> 
> An example of use of this API in C++ has been made by one of the core
> team member and is here [3]
> 
> Somebody told me about RICE to create Ruby wrapper around C++ code.
> 
> But I don't know where to start. What I know is that the "old/legacy"
> Firebird C API in libfbclient.so now exposes a new function called
> "fb_get_master_interface" that returns an instance of a pure virtual
> C++ class called IMaster from where everything in the new API is
> accessible. Instance of classes that will be returned from IMaster are
> refcounted and they are all pure virtual classes.
> 
> The header files for the pure virtual classes are here [4]
> 
> My questions : Is RICE the right tool to wrap this kind of API ? Do
> you have an example of code from where I could start ? I'm more a
> "Delphi/Windows" developer and quite good at Ruby but not so much
> fluent with C++ and Ruby extensions/gems.
> 
> Many thanks for your help, regards,
> 
> --
> Pierre Yager
> 
> [1] http://firebirdsql.org
> [2] https://github.com/asfernandes/firebird
> [3] https://github.com/asfernandes/fbstuff
> [4] https://github.com/asfernandes/firebird/tree/master/src/include/firebird

Pierre,

I guess first and foremost using Rice does require a pretty good 
understanding of C++. Looking through the header files, I didn't see 
anything that gave me immediate pause in terms of complexity of wrapping, 
though because all of the classes are pure virtual you will need to hook 
up a Rice::Director for every one of the classes, as Ruby needs concrete 
code and you can't automatically virtual call yourself into C from C++.

If you're not the most comfortable with C++, particularly the more 
advanced concepts, I would recommend first trying to wrap this up with 
SWIG and see how far you can get with that tool. 

Almost all of the relevant Rice documentation is in the README: 
http://rice.rubyforge.org/. Rice::Director is about 3/4 the way down the 
page.

Let me know if you have more specific questions, it's hard to say more 
without actually diving in and trying to build up a wrapper.

Jason