Tuesday, May 28, 2013

Python <-> C++ object oriented communication

Python <-> C++ object oriented communication

I want to write a daemon in C++, which will hold a graph data structure and will compute some dependencies. I also want to have Python Batch (also a daemon - a backend to HTML based GUI), which will allow users to interactivly operate on these C++ structures - add / remove / connect / ... nodes and read results of computations.
I would love to choose the best communication mechanism available.
The mandatory functionality is:
Python and C++ should be able to operate on nodes in object oriented way, so I would love to be able to write code like n1 = node('a'); n2 = n1.add_subnode('b'); n2.ports('test').connect(node('c'))
The Python Batch does NOT have to be "separated" from the C++ daemon - they can have the same lifetime (but it would be good to somehow separate batch from C++ daemon in case of C++ crash or something wrong - this separation is optional)
The communication should be fast - the Python should be able to get information about a lot of nodes and allow end - users to work smoothly as much as possible.
Currently I was thinking about:
IPC (like 0MQ) with some kind of data serialization mechanism.
RPC based on Protocol Buffers or Thrift.
Integration based on Boost.Python
The IPC and RPC solutions seems good, but I have to write a big wrappers to get the functionality from point 1. On the other hand I have found no information about using Boost.Python in C++ daemon and I don't know if it is even possible.