[pytango] 43/483: make dynamic attribute read/write/is_allowed method calls be called directly instead of poluting the device class with the methods in case the read/write/is_allowed methods are not the default ones
Sandor Bodo-Merle
sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:23 UTC 2017
This is an automated email from the git hooks/post-receive script.
sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.
commit d77faa3b695788506d16b9b2a71fe91978c6a5b9
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date: Fri Sep 9 11:30:06 2011 +0000
make dynamic attribute read/write/is_allowed method calls be called directly instead of poluting the device class with the methods in case the read/write/is_allowed methods are not the default ones
git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@17853 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
PyTango/device_server.py | 78 +++++++++++++++++++++++++++++-----------------
src/server/device_impl.cpp | 36 ++++++++++++++++++---
2 files changed, 82 insertions(+), 32 deletions(-)
diff --git a/PyTango/device_server.py b/PyTango/device_server.py
index 0e9bf1a..ea6c2e6 100644
--- a/PyTango/device_server.py
+++ b/PyTango/device_server.py
@@ -297,35 +297,57 @@ def __DeviceImpl__add_attribute(self, attr, r_meth=None, w_meth=None, is_allo_me
att_name = attr.get_name()
add_name_in_list = False
- if r_meth is not None:
- if attr_data is None:
- r_meth_name = 'read_%s' % att_name
- else:
- r_meth_name = attr_data.read_method_name
- if not hasattr(self.__class__, r_meth_name):
- setattr(self.__class__, r_meth_name, r_meth)
- add_name_in_list = True
-
- if w_meth is not None:
- if attr_data is None:
- w_meth_name = 'write_%s' % att_name
- else:
- w_meth_name = attr_data.write_method_name
- if not hasattr(self.__class__, w_meth_name):
- setattr(self.__class__, w_meth_name, w_meth)
- add_name_in_list = True
-
- if is_allo_meth is not None:
- if attr_data is None:
- allo_meth_name = 'is_%s_allowed' % att_name
- else:
- allo_meth_name = attr_data.is_allowed_name
- if not hasattr(self.__class__, allo_meth_name):
- setattr(self.__class__, allo_meth_name, is_allo_meth)
- add_name_in_list = True
-
+
+ r_name = 'read_%s' % att_name
+ if r_meth is None:
+ if attr_data is not None:
+ r_name = attr_data.read_method_name
+ else:
+ r_name = r_meth.__name__
+
+ w_name = 'write_%s' % att_name
+ if w_meth is None:
+ if attr_data is not None:
+ w_name = attr_data.write_method_name
+ else:
+ w_name = w_meth.__name__
+
+ ia_name = 'is_%s_allowed' % att_name
+ if is_allo_meth is None:
+ if attr_data is not None:
+ ia_name = attr_data.is_allowed_name
+ else:
+ ia_name = is_allo_meth.__name__
+
+# if r_meth is not None:
+# if attr_data is None:
+# r_meth_name = 'read_%s' % att_name
+# else:
+# r_meth_name = attr_data.read_method_name
+# if not hasattr(self.__class__, r_meth_name):
+# setattr(self.__class__, r_meth_name, r_meth)
+# add_name_in_list = True
+
+# if w_meth is not None:
+# if attr_data is None:
+# w_meth_name = 'write_%s' % att_name
+# else:
+# w_meth_name = attr_data.write_method_name
+# if not hasattr(self.__class__, w_meth_name):
+# setattr(self.__class__, w_meth_name, w_meth)
+# add_name_in_list = True
+
+# if is_allo_meth is not None:
+# if attr_data is None:
+# allo_meth_name = 'is_%s_allowed' % att_name
+# else:
+# allo_meth_name = attr_data.is_allowed_name
+# if not hasattr(self.__class__, allo_meth_name):
+# setattr(self.__class__, allo_meth_name, is_allo_meth)
+# add_name_in_list = True
+
try:
- self._add_attribute(attr)
+ self._add_attribute(attr, r_name, w_name, ia_name)
if add_name_in_list:
cl = self.get_device_class()
cl.dyn_att_added_methods.append(att_name)
diff --git a/src/server/device_impl.cpp b/src/server/device_impl.cpp
index f0e8400..2c4afc8 100644
--- a/src/server/device_impl.cpp
+++ b/src/server/device_impl.cpp
@@ -475,16 +475,44 @@ namespace PyDeviceImpl
}
}
- void add_attribute(Tango::DeviceImpl &self, const Tango::Attr &c_new_attr)
+ void add_attribute(Tango::DeviceImpl &self, const Tango::Attr &c_new_attr,
+ boost::python::object read_meth_name,
+ boost::python::object write_meth_name,
+ boost::python::object is_allowed_meth_name)
{
Tango::Attr &new_attr = const_cast<Tango::Attr &>(c_new_attr);
-
+
std::string
attr_name = new_attr.get_name(),
- is_allowed_method = "is_" + attr_name + "_allowed",
- read_name_met = "read_" + attr_name,
+ read_name_met, write_name_met, is_allowed_method;
+
+ if (read_meth_name.ptr() == Py_None)
+ {
+ read_name_met = "read_" + attr_name;
+ }
+ else
+ {
+ read_name_met = boost::python::extract<const char *>(read_meth_name);
+ }
+
+ if (write_meth_name.ptr() == Py_None)
+ {
write_name_met = "write_" + attr_name;
+ }
+ else
+ {
+ write_name_met = boost::python::extract<const char *>(write_meth_name);
+ }
+ if (is_allowed_meth_name.ptr() == Py_None)
+ {
+ is_allowed_method = "is_" + attr_name + "_allowed";
+ }
+ else
+ {
+ is_allowed_method = boost::python::extract<const char *>(is_allowed_meth_name);
+ }
+
Tango::AttrWriteType attr_write = new_attr.get_writable();
//
--
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