python/tango client binding swig () vs boost ()

11
Python/Tango Client Binding Swig (www.swig.org ) Vs Boost (www.boost.org)

Upload: nora-wilkins

Post on 05-Jan-2016

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Python/Tango Client Binding Swig () Vs Boost ()

Python/Tango Client Binding

Swig (www.swig.org)

Vs

Boost (www.boost.org)

Page 2: 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

Page 3: Python/Tango Client Binding Swig () Vs Boost ()

Swig C++ supported features

• Classes

• Virtual functions

• Pubilc inheritance

• Operator overloading

• References

• templates

Page 4: Python/Tango Client Binding Swig () Vs Boost ()

Swig unsupported C++ features

• Namespaces

• Functions and method overloading

• Nested classes

• Overloaded versions of certain operators (new, delete, etc.)

Page 5: Python/Tango Client Binding Swig () Vs Boost ()

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

Page 6: Python/Tango Client Binding Swig () Vs Boost ()

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

Page 7: Python/Tango Client Binding Swig () Vs Boost ()

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

Page 8: Python/Tango Client Binding Swig () Vs Boost ()

Tango Client Binding

Using boost.python

Page 9: Python/Tango Client Binding Swig () Vs Boost ()

#include <tango.h>#include <boost/any.hpp>#include <boost/python/dict.hpp> 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);};

Page 10: Python/Tango Client Binding Swig () Vs Boost ()

#include <device_proxy.h>#include <boost/python/class.hpp>#include <boost/python/module.hpp>  BOOST_PYTHON_MODULE(PyTango){ using namespace boost::python;  enum_<Tango::DevState>("DevState") .value("ON",Tango::ON) .value("OFF",Tango::OFF) .value("CLOSE",Tango::CLOSE) .value("UNKNOWN",Tango::UNKNOWN) ;  enum_<Tango::DevSource>("DevSource") .value("DEV",Tango::DEV) .value("CACHE",Tango::CACHE) .value("CACHE_DEV",Tango::CACHE_DEV) ;  enum_<Tango::DispLevel>("DispLevel") .value("OPERATOR",Tango::OPERATOR) .value("EXPERT",Tango::EXPERT) ;  class_<DeviceProxy>("DeviceProxy", init<std::string>()) .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)

;}

Page 11: Python/Tango Client Binding Swig () Vs Boost ()

[ounsy@/home/ounsy/python]: pythonPython 2.2.1 (#1, Apr 9 2002, 13:10:27)[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2Type "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': 'http://www.esrf.fr/tango','server_version': 2}>>> dev.description()'A TANGO device'>>> dev.command_inout("DevString","Hello, World!")'Hello, World!'>>>