Examples of C++-Python interoperability using Thrift services based on SWIG and YARP.
The test case considered in this repository is related to the following Thrift service definition:
thrift-cpp-python-interop/cpp_library/src/thrift/service.thrift
Lines 1 to 22 in 737b10e
where the service Service
offers three methods:
get_poses
returns a list ofyarp::sig::Matrix
4x4 matrices representing posesget_position
returns ayarp::sig::Vector
vector representing a 3D positionget_distance
return a double representing a distance
git clone https://github.com/xEnVrE/thrift-cpp-python-interop
cd thrift-cpp-python-interop/cpp-library
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=<your_install_prefix> ../
make install
Note: it is required to build and install the C++ library first.
Warning: It is suggested to build and install the library within a virtual environment.
(env) git clone https://github.com/xEnVrE/thrift-cpp-python-interop
(env) cd thrift-cpp-python-interop/python-library
(env) mkdir build && cd build
(env) cmake ../
(env) make install
Note: the names of the target can be changed in the following:
- Client: C++ Client CMake project
In order to build and run the client:
git clone https://github.com/xEnVrE/thrift-cpp-python-interop cd thrift-cpp-python-interop/samples/cpp-client mkdir build && cd build make ./tcpi-cpp-clientThe client opens an RPC port
/tcpi/cpp-client/rpc:o
.
- Server: C++ Server CMake project
In order to build and run the server:
git clone https://github.com/xEnVrE/thrift-cpp-python-interop cd thrift-cpp-python-interop/samples/cpp-server mkdir build && cd build make ./tcpi-cpp-serverThe server opens an RPC port
/tcpi/cpp-server/rpc:i
.
Note: the names of the library can be changed in the following:
- Client: Python Client project
In order to build and run the client:
git clone https://github.com/xEnVrE/thrift-cpp-python-interop cd thrift-cpp-python-interop/samples/python-client python client.pyThe client opens an RPC port
/tcpi/python-client/rpc:o
.
- Server: Python Server project
In order to build and run the server:
git clone https://github.com/xEnVrE/thrift-cpp-python-interop cd thrift-cpp-python-interop/samples/python-server python server.pyThe server opens an RPC port
/tcpi/python-server/rpc:i
.
It is as easy as connecting the corresponding YARP
ports using yarp connect
.