[pytango] 10/98: Implement TANGO enumeration type (server)

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:17:39 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to tag v9.2.0
in repository pytango.

commit 3a8239782d09c3f5066a7843f8a8ea9b3be5db98
Author: Jose Tiago Coutinho Macara <tiago.coutinho at esrf.fr>
Date:   Mon Dec 14 11:27:04 2015 +0100

    Implement TANGO enumeration type (server)
---
 src/boost/cpp/fast_from_py.h                    |  2 +-
 src/boost/cpp/server/user_default_attr_prop.cpp |  4 +++-
 src/boost/python/attr_data.py                   | 11 ++++++++++-
 src/boost/python/device_server.py               | 24 ++++++++++++++++++++++--
 src/boost/python/server.py                      |  2 ++
 5 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/src/boost/cpp/fast_from_py.h b/src/boost/cpp/fast_from_py.h
index 39bfbcc..32cdb9f 100644
--- a/src/boost/cpp/fast_from_py.h
+++ b/src/boost/cpp/fast_from_py.h
@@ -184,7 +184,7 @@ DEFINE_FAST_TANGO_FROMPY_NUM(Tango::DEV_DOUBLE, double, PyFloat_AsDouble)
 
 // DEFINE_FAST_TANGO_FROMPY(Tango::DEV_STRING, PyString_AsString)
 DEFINE_FAST_TANGO_FROMPY(Tango::DEV_STRING, PyString_AsCorbaString)
-
+DEFINE_FAST_TANGO_FROMPY(Tango::DEV_ENUM, PyLong_AsUnsignedLong)
 
 template<long tangoArrayTypeConst>
 struct array_element_from_py : public from_py<TANGO_const2scalarconst(tangoArrayTypeConst)>
diff --git a/src/boost/cpp/server/user_default_attr_prop.cpp b/src/boost/cpp/server/user_default_attr_prop.cpp
index 6c8aabd..40e34a1 100644
--- a/src/boost/cpp/server/user_default_attr_prop.cpp
+++ b/src/boost/cpp/server/user_default_attr_prop.cpp
@@ -44,7 +44,8 @@ void export_user_default_attr_prop()
         .def("set_archive_event_abs_change", &Tango::UserDefaultAttrProp::set_archive_event_abs_change)
         .def("set_archive_event_rel_change", &Tango::UserDefaultAttrProp::set_archive_event_rel_change)
         .def("set_archive_event_period", &Tango::UserDefaultAttrProp::set_archive_event_period)
-        
+        .def("_set_enum_labels", &Tango::UserDefaultAttrProp::set_enum_labels)
+
         .def_readwrite("label", &Tango::UserDefaultAttrProp::label)
         .def_readwrite("description", &Tango::UserDefaultAttrProp::description)
         .def_readwrite("unit", &Tango::UserDefaultAttrProp::unit)
@@ -65,6 +66,7 @@ void export_user_default_attr_prop()
         .def_readwrite("archive_abs_change", &Tango::UserDefaultAttrProp::archive_abs_change)
         .def_readwrite("archive_rel_change", &Tango::UserDefaultAttrProp::archive_rel_change)
         .def_readwrite("archive_period", &Tango::UserDefaultAttrProp::archive_period)
+        .def_readwrite("enum_labels", &Tango::UserDefaultAttrProp::enum_labels)
     ;
 
 }
diff --git a/src/boost/python/attr_data.py b/src/boost/python/attr_data.py
index 7e806bf..47d95ae 100644
--- a/src/boost/python/attr_data.py
+++ b/src/boost/python/attr_data.py
@@ -149,7 +149,10 @@ class AttrData(object):
             method_name = "set_%s" % k_lower.replace(' ','_')
             if hasattr(p, method_name):
                 method = getattr(p, method_name)
-                method(str(v))
+                if method_name == 'set_enum_labels':
+                    method(v)
+                else:
+                    method(str(v))
             elif k == 'delta_time':
                 p.set_delta_t(str(v))
             elif not k_lower in ('display level', 'polling period', 'memorized'):
@@ -289,6 +292,12 @@ class AttrData(object):
         else:
             self.memorized = False
         
+        if self.attr_type == CmdArgType.DevEnum:
+            if not 'enum_labels' in extra_info:
+                throw_ex("Missing 'enum_labels' key in attr_list definition "\
+                         "for enum attribute %s in class %s" % (attr_name, name))
+            self.enum_labels = extra_info["enum_labels"]
+
         self.attr_class = extra_info.get("klass", self.DftAttrClassMap[self.attr_format])
         self.attr_args.extend((self.attr_name, self.attr_type, self.attr_write))
         if not self.attr_format == AttrDataFormat.SCALAR:
diff --git a/src/boost/python/device_server.py b/src/boost/python/device_server.py
index cabeb9a..e91e5be 100644
--- a/src/boost/python/device_server.py
+++ b/src/boost/python/device_server.py
@@ -26,11 +26,11 @@ __docformat__ = "restructuredtext"
 
 import copy
 
-from ._PyTango import DeviceImpl, Device_3Impl, Device_4Impl, \
+from ._PyTango import DeviceImpl, Device_3Impl, Device_4Impl, Device_5Impl, \
     DevFailed, Attribute, WAttribute, \
     MultiAttribute, MultiClassAttribute, \
     Attr, Logger, AttrWriteType, PipeWriteType, AttrDataFormat, \
-    DispLevel, UserDefaultAttrProp
+    DispLevel, UserDefaultAttrProp, StdStringVector
 
 from .utils import document_method as __document_method
 from .utils import copy_doc
@@ -628,6 +628,22 @@ def __Logger__fatal(self, msg, *args):
     """
     self.__fatal(msg % args)
 
+def __UserDefaultAttrProp_set_enum_labels(self, enum_labels):
+    """
+    set_enum_labels(self, enum_labels) -> None
+
+            Set default enumeration labels.
+
+        Parameters :
+            - enum_labels : (seq<str>) list of enumeration labels
+
+        New in PyTango 9.1.0
+    """
+    elbls = StdStringVector()
+    for enu in enum_labels:
+        elbls.append(enu)
+    return self._set_enum_labels(elbls)
+
 def __Attr__str(self):
     return '%s(%s)' % (self.__class__.__name__, self.get_name())
 
@@ -635,6 +651,9 @@ def __init_Attr():
     Attr.__str__ = __Attr__str
     Attr.__repr__ = __Attr__str
 
+def __init_UserDefaultAttrProp():
+    UserDefaultAttrProp.set_enum_labels = __UserDefaultAttrProp_set_enum_labels
+
 def __init_Logger():
     Logger.log = __Logger__log
     Logger.log_unconditionally = __Logger__log_unconditionally
@@ -2614,6 +2633,7 @@ def device_server_init(doc=True):
     __init_DeviceImpl()
     __init_Attribute()
     __init_Attr()
+    __init_UserDefaultAttrProp()
     __init_Logger()
     if doc:
         __doc_DeviceImpl()
diff --git a/src/boost/python/server.py b/src/boost/python/server.py
index 1efb7b7..1fabda8 100644
--- a/src/boost/python/server.py
+++ b/src/boost/python/server.py
@@ -79,6 +79,7 @@ def __build_to_tango_type():
         'char'      : CmdArgType.DevUChar,
         'None'      : CmdArgType.DevVoid,
         'state'     : CmdArgType.DevState,
+        'enum'      : CmdArgType.DevEnum,
     }
 
     try:
@@ -602,6 +603,7 @@ class attribute(AttrData):
     fset (or fwrite)       :obj:`str` or :obj:`callable`    'write_<attr_name>'                     write method name or method object
     is_allowed             :obj:`str` or :obj:`callable`    'is_<attr_name>_allowed'                is allowed method name or method object
     label                  :obj:`str`                       '<attr_name>'                           attribute label
+    enum_labels            sequence                         None                                    the list of enumeration labels (enum data type)
     doc (or description)   :obj:`str`                       ''                                      attribute description
     unit                   :obj:`str`                       ''                                      physical units the attribute value is in
     standard_unit          :obj:`str`                       ''                                      physical standard unit

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list