Python/Tango Client Binding Swig ( Vs Boost (
Swig wrapping Compiles interfaces connecting C/C++ code to scripting languages (Perl, Python, …) Generates glue code (wrappers) that scripting language needs to access underlying C/C++ code
Swig C++ supported features Classes Virtual functions Pubilc inheritance Operator overloading References templates
Swig unsupported C++ features Namespaces Functions and method overloading Nested classes Overloaded versions of certain operators (new, delete, etc.)
Boost Is a set of free portable C++ source libraries Some of the libraries have already been proposed for inclusion in the C++ Standard Library Among available libraries : any, date_time, math, pool, python, smart_ptr, thread, timer
Boost.Python wrapping Boost.python is a C++ library which enables seamless interoperability between C++ and Python Allows python to access C++ functions and data directly as if they were written in Python Does not involve any changes to the code
Boost.Python supported features References and Pointers Globally registered type coercions Automatic cross-module type conversions Efficient function overloading C++ to Python Exception translation Manipulating python objects in C++ Documentation strings
Tango Client Binding Using boost.python
#include class DeviceProxy { public: DeviceProxy(std::string name) : deviceName(name) { deviceProxy = new Tango::DeviceProxy(deviceName); } boost::python::dict info(); Tango::DevState state(); std::string status(); int ping(); int get_idl_version(); void set_source(Tango::DevSource source); Tango::DevSource get_source(); boost::python::tuple black_box(int n); boost::python::dict import_info(); boost::python::dict command_query(std::string command); boost::python::list command_list_query(); std::string description(); boost::python::object command_inout(std::string name, boost::python::object pyData); };
#include BOOST_PYTHON_MODULE(PyTango) { using namespace boost::python; enum_ ("DevState").value("ON",Tango::ON).value("OFF",Tango::OFF).value("CLOSE",Tango::CLOSE) .value("UNKNOWN",Tango::UNKNOWN) ; enum_ ("DevSource").value("DEV",Tango::DEV).value("CACHE",Tango::CACHE).value("CACHE_DEV",Tango::CACHE_DEV) ; enum_ ("DispLevel").value("OPERATOR",Tango::OPERATOR).value("EXPERT",Tango::EXPERT) ; class_ ("DeviceProxy", init ()).def("status", &DeviceProxy::status).def("description", &DeviceProxy::description).def("ping", &DeviceProxy::ping) .def("command_query", &DeviceProxy::command_query).def("command_list_query", &DeviceProxy::command_list_query).def("command_inout", &DeviceProxy::command_inout) ; }
python Python (#1, Apr , 13:10:27) [GCC (Red Hat Linux )] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import PyTango >>> dev = PyTango.DeviceProxy("tango/tangotest/1") >>> dev.info() {'server_host': 'ganymede.synchrotron-soleil.fr', 'server_id': 'tangotest/1', 'dev_type': 0, 'dev_class': 'TangoTest', 'doc_url': ' 'server_version': 2} >>> dev.description() 'A TANGO device' >>> dev.command_inout("DevString","Hello, World!") 'Hello, World!' >>>