[pytango] 365/483: Implement #102
Sandor Bodo-Merle
sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:15:00 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 a9477bccf26cafdb794156d614cc500333e5bbb0
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date: Tue Apr 1 09:07:20 2014 +0000
Implement #102
git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@25330 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
doc/revision.rst | 1 +
src/boost/cpp/server/attribute.cpp | 152 ++++++++++++++++++++---------------
src/boost/cpp/server/attribute.h | 7 ++
src/boost/cpp/server/device_impl.cpp | 83 ++++++++++++++++++-
4 files changed, 178 insertions(+), 65 deletions(-)
diff --git a/doc/revision.rst b/doc/revision.rst
index a55bd56..c8010e6 100644
--- a/doc/revision.rst
+++ b/doc/revision.rst
@@ -88,6 +88,7 @@ Version history
+==========+===================================================================================================================================================================+
| 8.1.2 | Features: |
| | - `98: PyTango.server.server_run needs additional post_init_callback parameter <https://sourceforge.net/p/tango-cs/feature-requests/98>`_ |
+| | - `102: DevEncoded attribute should support a python buffer object <https://sourceforge.net/p/tango-cs/feature-requests/102>`_ |
| | |
| | Bug fixes: |
| | - `641: python3 error handling issue <https://sourceforge.net/p/tango-cs/bugs/641/>`_ |
diff --git a/src/boost/cpp/server/attribute.cpp b/src/boost/cpp/server/attribute.cpp
index 705bb59..94c321a 100644
--- a/src/boost/cpp/server/attribute.cpp
+++ b/src/boost/cpp/server/attribute.cpp
@@ -87,36 +87,6 @@ namespace PyAttribute
}
/**
- * ATTENTION: this template specialization is done to close a memory leak
- * that exists up to tango 7.1.1 for string read_write attributes
- *
- * Tango Attribute set_value wrapper for scalar string attributes
- *
- * @param att attribute reference
- * @param value new attribute value
- */
- /*
- template<>
- inline void __set_value_scalar<Tango::DEV_STRING>(Tango::Attribute &att,
- bopy::object &value)
- {
- Tango::DevString *v = new Tango::DevString;
-
- if (TANGO_VERSION_HEX < 0x07020000 && att.get_writable() != Tango::READ)
- { // MEMORY LEAK: use the python string directly instead of creating a
- // string
- v[0] = PyString_AsString(value.ptr());
- att.set_value(v, 1, 0);
- }
- else
- { // No memory leak here. Do the standard thing
- from_py<Tango::DEV_STRING>::convert(value, *v);
- att.set_value(v, 1, 0, true);
- }
- }
- */
-
- /**
* Tango Attribute set_value wrapper for DevEncoded attributes
*
* @param att attribute reference
@@ -143,6 +113,35 @@ namespace PyAttribute
att.set_value(&val_str_real, (Tango::DevUChar*)val_real, (long)len(data));
}
+ /**
+ * Tango Attribute set_value wrapper for DevEncoded attributes
+ *
+ * @param att attribute reference
+ * @param data_str new attribute data string
+ * @param data new attribute data
+ */
+ inline void __set_value(Tango::Attribute &att,
+ bopy::str &data_str,
+ bopy::object &data)
+ {
+ extract<Tango::DevString> val_str(data_str.ptr());
+ if (!val_str.check())
+ {
+ throw_wrong_python_data_type(att.get_name(), "set_value()");
+ }
+
+ PyObject* data_ptr = data.ptr();
+ Py_buffer view;
+
+ if (PyObject_GetBuffer(data_ptr, &view, PyBUF_FULL_RO) < 0)
+ {
+ throw_wrong_python_data_type(att.get_name(), "set_value()");
+ }
+
+ Tango::DevString val_str_real = val_str;
+ att.set_value(&val_str_real, (Tango::DevUChar*)view.buf, (long)view.len);
+ PyBuffer_Release(&view);
+ }
/**
* Tango Attribute set_value_date_quality wrapper for scalar attributes
@@ -175,38 +174,37 @@ namespace PyAttribute
att.set_value_date_quality(cpp_val.release(), tv, quality, 1, 0, true);
}
-
/**
- * ATTENTION: this template specialization is done to close a memory leak
- * that exists up to tango 7.1.1 for string read_write attributes
+ * Tango Attribute set_value_date_quality wrapper for DevEncoded attributes
*
- * Tango Attribute set_value_date_quality wrapper for scalar string attributes
- *
* @param att attribute reference
- * @param value new attribute value
+ * @param data_str new attribute data string
+ * @param data new attribute data
* @param t timestamp
* @param quality attribute quality
*/
- /*
- template<>
- inline void __set_value_date_quality_scalar<Tango::DEV_STRING>(Tango::Attribute &att,
- bopy::object &value,
- double t, Tango::AttrQuality quality)
+ inline void __set_value_date_quality(Tango::Attribute &att,
+ bopy::str &data_str,
+ bopy::str &data,
+ double t, Tango::AttrQuality quality)
{
- PYTG_NEW_TIME_FROM_DOUBLE(t, tv);
-
- Tango::DevString *v = new Tango::DevString;
- if (att.get_writable() == Tango::READ)
- { // No memory leak here. Do the standard thing
- from_py<Tango::DEV_STRING>::convert(value, *v);
+ extract<Tango::DevString> val_str(data_str.ptr());
+ if (!val_str.check())
+ {
+ throw_wrong_python_data_type(att.get_name(), "set_value1()");
}
- else
- { // MEMORY LEAK: use the python string directly instead of creating a string
- v[0] = PyString_AsString(value.ptr());
+ extract<Tango::DevString> val(data.ptr());
+ if (!val.check())
+ {
+ throw_wrong_python_data_type(att.get_name(), "set_value2()");
}
- att.set_value_date_quality(v, tv, quality, 1, 0, true);
+
+ PYTG_NEW_TIME_FROM_DOUBLE(t, tv);
+ Tango::DevString val_str_real = val_str;
+ Tango::DevString val_real = val;
+ att.set_value_date_quality(&val_str_real, (Tango::DevUChar*)val_real,
+ (long)len(data), tv, quality);
}
- */
/**
* Tango Attribute set_value_date_quality wrapper for DevEncoded attributes
@@ -219,7 +217,7 @@ namespace PyAttribute
*/
inline void __set_value_date_quality(Tango::Attribute &att,
bopy::str &data_str,
- bopy::str &data,
+ bopy::object &data,
double t, Tango::AttrQuality quality)
{
extract<Tango::DevString> val_str(data_str.ptr());
@@ -227,17 +225,21 @@ namespace PyAttribute
{
throw_wrong_python_data_type(att.get_name(), "set_value1()");
}
- extract<Tango::DevString> val(data.ptr());
- if (!val.check())
- {
- throw_wrong_python_data_type(att.get_name(), "set_value2()");
- }
+
+ PyObject* data_ptr = data.ptr();
+ Py_buffer view;
+
+ if (PyObject_GetBuffer(data_ptr, &view, PyBUF_FULL_RO) < 0)
+ {
+ throw_wrong_python_data_type(att.get_name(), "set_value()");
+ }
PYTG_NEW_TIME_FROM_DOUBLE(t, tv);
- Tango::DevString val_str_real = val_str;
- Tango::DevString val_real = val;
- att.set_value_date_quality(&val_str_real, (Tango::DevUChar*)val_real,
- (long)len(data), tv, quality);
+ Tango::DevString val_str_real = val_str;
+ att.set_value(&val_str_real, (Tango::DevUChar*)view.buf, (long)view.len);
+ att.set_value_date_quality(&val_str_real, (Tango::DevUChar*)view.buf,
+ (long)view.len, tv, quality);
+ PyBuffer_Release(&view);
}
template<long tangoTypeConst>
@@ -287,8 +289,6 @@ namespace PyAttribute
}
}
-
-
inline void __set_value(const std::string & fname, Tango::Attribute &att, bopy::object &value, long* x, long *y, double t = 0.0, Tango::AttrQuality* quality = 0)
{
long type = att.get_data_type();
@@ -336,6 +336,14 @@ namespace PyAttribute
__set_value(att, data_str, data);
}
+ inline void __set_value(const std::string & fname, Tango::Attribute &att, bopy::str &data_str, bopy::object &data, double t = 0.0, Tango::AttrQuality* quality = 0)
+ {
+ if (quality)
+ __set_value_date_quality(att, data_str, data, t, *quality);
+ else
+ __set_value(att, data_str, data);
+ }
+
inline void set_value(Tango::Attribute &att, bopy::object &value)
{ __set_value("set_value", att, value, 0, 0); }
@@ -345,6 +353,9 @@ namespace PyAttribute
inline void set_value(Tango::Attribute &att, bopy::str &data_str, bopy::str &data)
{ __set_value("set_value", att, data_str, data); }
+ inline void set_value(Tango::Attribute &att, bopy::str &data_str, bopy::object &data)
+ { __set_value("set_value", att, data_str, data); }
+
inline void set_value(Tango::Attribute &att, bopy::object &value, long x)
{ __set_value("set_value", att, value, &x, 0); }
@@ -364,6 +375,13 @@ namespace PyAttribute
{ __set_value("set_value_date_quality", att, data_str, data, t, &quality); }
inline void set_value_date_quality(Tango::Attribute &att,
+ bopy::str &data_str,
+ bopy::object &data,
+ double t,
+ Tango::AttrQuality quality)
+ { __set_value("set_value_date_quality", att, data_str, data, t, &quality); }
+
+ inline void set_value_date_quality(Tango::Attribute &att,
bopy::object &value,
double t, Tango::AttrQuality quality,
long x)
@@ -892,6 +910,9 @@ void export_attribute()
(void (*) (Tango::Attribute &, bopy::object &))
&PyAttribute::set_value)
.def("set_value",
+ (void (*) (Tango::Attribute &, bopy::str &, bopy::object &))
+ &PyAttribute::set_value)
+ .def("set_value",
(void (*) (Tango::Attribute &, bopy::str &, bopy::str &))
&PyAttribute::set_value)
.def("set_value",
@@ -910,6 +931,9 @@ void export_attribute()
(void (*) (Tango::Attribute &, bopy::str &, bopy::str &, double t, Tango::AttrQuality quality))
&PyAttribute::set_value_date_quality)
.def("set_value_date_quality",
+ (void (*) (Tango::Attribute &, bopy::str &, bopy::object &, double t, Tango::AttrQuality quality))
+ &PyAttribute::set_value_date_quality)
+ .def("set_value_date_quality",
(void (*) (Tango::Attribute &, bopy::object &, double t, Tango::AttrQuality quality, long))
&PyAttribute::set_value_date_quality)
.def("set_value_date_quality",
diff --git a/src/boost/cpp/server/attribute.h b/src/boost/cpp/server/attribute.h
index 7c9ef38..0535ff3 100644
--- a/src/boost/cpp/server/attribute.h
+++ b/src/boost/cpp/server/attribute.h
@@ -22,6 +22,9 @@ namespace PyAttribute
void set_value(Tango::Attribute &, boost::python::str &,
boost::python::str &);
+ void set_value(Tango::Attribute &, boost::python::str &,
+ boost::python::object &);
+
void set_value(Tango::Attribute &, boost::python::object &, long);
void set_value(Tango::Attribute &, boost::python::object &, long, long);
@@ -33,6 +36,10 @@ namespace PyAttribute
boost::python::str &, double,
Tango::AttrQuality);
+ void set_value_date_quality(Tango::Attribute &, boost::python::str &,
+ boost::python::object &, double,
+ Tango::AttrQuality);
+
void set_value_date_quality(Tango::Attribute &, boost::python::object &,
double, Tango::AttrQuality , long);
diff --git a/src/boost/cpp/server/device_impl.cpp b/src/boost/cpp/server/device_impl.cpp
index a5472e7..f6e76dc 100644
--- a/src/boost/cpp/server/device_impl.cpp
+++ b/src/boost/cpp/server/device_impl.cpp
@@ -235,6 +235,15 @@ namespace PyDeviceImpl
attr.fire_change_event();
}
+ // Special variantion for encoded data type
+ inline void push_change_event(Tango::DeviceImpl &self, str &name, str &str_data,
+ object &data)
+ {
+ SAFE_PUSH(self, attr, name)
+ PyAttribute::set_value(attr, str_data, data);
+ attr.fire_change_event();
+ }
+
inline void push_change_event(Tango::DeviceImpl &self, str &name, object &data,
long x)
{
@@ -266,6 +275,15 @@ namespace PyDeviceImpl
attr.fire_change_event();
}
+ // Special variantion for encoded data type
+ inline void push_change_event(Tango::DeviceImpl &self, str &name, str &str_data,
+ object &data, double t, Tango::AttrQuality quality)
+ {
+ SAFE_PUSH(self, attr, name)
+ PyAttribute::set_value_date_quality(attr, str_data, data, t, quality);
+ attr.fire_change_event();
+ }
+
inline void push_change_event(Tango::DeviceImpl &self, str &name, object &data,
double t, Tango::AttrQuality quality, long x)
{
@@ -299,7 +317,7 @@ namespace PyDeviceImpl
SAFE_PUSH_ARCHIVE_EVENT(self, name, data);
}
- // Special variantion for encoded data type
+ // Special variation for encoded data type
inline void push_archive_event(Tango::DeviceImpl &self, str &name, str &str_data,
str &data)
{
@@ -308,6 +326,15 @@ namespace PyDeviceImpl
attr.fire_archive_event();
}
+ // Special variation for encoded data type
+ inline void push_archive_event(Tango::DeviceImpl &self, str &name, str &str_data,
+ object &data)
+ {
+ SAFE_PUSH(self, attr, name)
+ PyAttribute::set_value(attr, str_data, data);
+ attr.fire_archive_event();
+ }
+
inline void push_archive_event(Tango::DeviceImpl &self, str &name, object &data,
long x)
{
@@ -339,6 +366,15 @@ namespace PyDeviceImpl
attr.fire_archive_event();
}
+ // Special variantion for encoded data type
+ inline void push_archive_event(Tango::DeviceImpl &self, str &name, str &str_data,
+ object &data, double t, Tango::AttrQuality quality)
+ {
+ SAFE_PUSH(self, attr, name)
+ PyAttribute::set_value_date_quality(attr, str_data, data, t, quality);
+ attr.fire_archive_event();
+ }
+
inline void push_archive_event(Tango::DeviceImpl &self, str &name, object &data,
double t, Tango::AttrQuality quality, long x)
{
@@ -377,6 +413,16 @@ namespace PyDeviceImpl
attr.fire_event(filt_names_, filt_vals_);
}
+ // Special variantion for encoded data type
+ inline void push_event(Tango::DeviceImpl &self, str &name,
+ object &filt_names, object &filt_vals,
+ str &str_data, object &data)
+ {
+ AUX_SAFE_PUSH_EVENT(self, name, filt_names, filt_vals)
+ PyAttribute::set_value(attr, str_data, data);
+ attr.fire_event(filt_names_, filt_vals_);
+ }
+
inline void push_event(Tango::DeviceImpl &self, str &name,
object &filt_names, object &filt_vals, object &data,
long x)
@@ -413,6 +459,17 @@ namespace PyDeviceImpl
attr.fire_event(filt_names_, filt_vals_);
}
+ // Special variantion for encoded data type
+ inline void push_event(Tango::DeviceImpl &self, str &name,
+ object &filt_names, object &filt_vals,
+ str &str_data, object &data,
+ double t, Tango::AttrQuality quality)
+ {
+ AUX_SAFE_PUSH_EVENT(self, name, filt_names, filt_vals)
+ PyAttribute::set_value_date_quality(attr, str_data, data, t, quality);
+ attr.fire_event(filt_names_, filt_vals_);
+ }
+
inline void push_event(Tango::DeviceImpl &self, str &name,
object &filt_names, object &filt_vals, object &data,
double t, Tango::AttrQuality quality, long x)
@@ -1255,6 +1312,10 @@ void export_device_impl()
&PyDeviceImpl::push_change_event)
.def("push_change_event",
+ (void (*) (Tango::DeviceImpl &, str &, str &, object &))
+ &PyDeviceImpl::push_change_event)
+
+ .def("push_change_event",
(void (*) (Tango::DeviceImpl &, str &, object &, long))
&PyDeviceImpl::push_change_event)
@@ -1271,6 +1332,10 @@ void export_device_impl()
&PyDeviceImpl::push_change_event)
.def("push_change_event",
+ (void (*) (Tango::DeviceImpl &, str &, str &, object &, double, Tango::AttrQuality))
+ &PyDeviceImpl::push_change_event)
+
+ .def("push_change_event",
(void (*) (Tango::DeviceImpl &, str &, object &, double, Tango::AttrQuality, long))
&PyDeviceImpl::push_change_event)
@@ -1292,6 +1357,10 @@ void export_device_impl()
&PyDeviceImpl::push_archive_event)
.def("push_archive_event",
+ (void (*) (Tango::DeviceImpl &, str &, str &, object &))
+ &PyDeviceImpl::push_archive_event)
+
+ .def("push_archive_event",
(void (*) (Tango::DeviceImpl &, str &, object &, long))
&PyDeviceImpl::push_archive_event)
@@ -1308,6 +1377,10 @@ void export_device_impl()
&PyDeviceImpl::push_archive_event)
.def("push_archive_event",
+ (void (*) (Tango::DeviceImpl &, str &, str &, object &, double, Tango::AttrQuality))
+ &PyDeviceImpl::push_archive_event)
+
+ .def("push_archive_event",
(void (*) (Tango::DeviceImpl &, str &, object &, double, Tango::AttrQuality, long))
&PyDeviceImpl::push_archive_event)
@@ -1328,6 +1401,10 @@ void export_device_impl()
&PyDeviceImpl::push_event)
.def("push_event",
+ (void (*) (Tango::DeviceImpl &, str &, object &, object &, str &, object &))
+ &PyDeviceImpl::push_event)
+
+ .def("push_event",
(void (*) (Tango::DeviceImpl &, str &, object &, object &, object &, long))
&PyDeviceImpl::push_event)
@@ -1344,6 +1421,10 @@ void export_device_impl()
&PyDeviceImpl::push_event)
.def("push_event",
+ (void (*) (Tango::DeviceImpl &, str &, object &, object &, str &, object &, double, Tango::AttrQuality))
+ &PyDeviceImpl::push_event)
+
+ .def("push_event",
(void (*) (Tango::DeviceImpl &, str &, object &, object &, object &, double, Tango::AttrQuality, long))
&PyDeviceImpl::push_event)
--
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