[ts-gen] Hooking into shim directly via C/C++

Ken Feng kfmfe04 at gmail.com
Wed Aug 26 04:28:34 EDT 2009


Hi Bill & Russ,

While trying to work the --risk side of my shim usage, I began to
realize that the large chunk of C/C++ code I need to maintain would
require duplication in Ruby, which is not a good idea, for maintenance
purposes (if I ever modify the C/C++ code, I will be relegated to
double-maintenance-debugging hell).

So I tried rewriting what little Ruby code there was in C/C++,
thinking it would be a little work, but really shouldn't be that
bad...  ...until I looked up popen() to replace Ruby's IO.popen().  It
appears that the call is at such a low level that only one direction
(read or write) can be opened at a time.  To do bi-directional piping,
I have to fork() and do all sorts of not-so-fun-stuff.

I began to wonder, is there a way to avoid popen() and hook into the
Shim directly?  I just want to write commands into it and read
responses, just like we normally do in Ruby.  In particular, I need to
implement my own risk.rb equivalent in C/C++.  In licensing terms, I
have no intention to use this code for anything but my personal use.

So what I would like to know is, is there a clear API in the Shim for
me write send commands in and read responses back?  My initial thought
was, probably not, if it's just reading from stdin and writing to
stdout.  But if there is, could you send me a snippet of code to get
me started?  I think I can handle the compile/linking, but I need to
figure out how/where I need to read/write.

Thanks!

- Ken
If there is no way to do this easily, I will have to try to work
things the other way around - refit my current code so it can be
invoked from Ruby and use Ruby as the main driver for both the Shim
and the signal calculator, but it will be ugly, because there will
probably be some real tight coupling between Ruby and my calculator -
not pretty at all.


More information about the ts-general mailing list