Download presentation
Presentation is loading. Please wait.
Published byNora Wilkins Modified over 9 years ago
1
Python/Tango Client Binding Swig (www.swig.org)www.swig.org Vs Boost (www.boost.org)
2
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
3
Swig C++ supported features Classes Virtual functions Pubilc inheritance Operator overloading References templates
4
Swig unsupported C++ features Namespaces Functions and method overloading Nested classes Overloaded versions of certain operators (new, delete, etc.)
5
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
6
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
7
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
8
Tango Client Binding Using boost.python
9
#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); };
10
#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) ; }
11
[ounsy@/home/ounsy/python]: python Python 2.2.1 (#1, Apr 9 2002, 13:10:27) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] 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': 'http://www.esrf.fr/tango', 'server_version': 2} >>> dev.description() 'A TANGO device' >>> dev.command_inout("DevString","Hello, World!") 'Hello, World!' >>>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.