[pytango] 25/98: First implementation of Tango pipe on client side (has memory leak!)
Sandor Bodo-Merle
sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:17:41 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 aa1369c514cf6f79456b6d33ce3bfc0d265ecf6b
Author: Jose Tiago Coutinho Macara <tiago.coutinho at esrf.fr>
Date: Thu Dec 10 08:48:49 2015 +0100
First implementation of Tango pipe on client side (has memory leak!)
---
Makefile | 1 +
src/boost/cpp/base_types.cpp | 2 +
src/boost/cpp/device_pipe.cpp | 226 ++++++---------------------------------
src/boost/cpp/device_proxy.cpp | 21 +++-
src/boost/cpp/tgutils.h | 7 --
src/boost/python/device_proxy.py | 9 +-
6 files changed, 52 insertions(+), 214 deletions(-)
diff --git a/Makefile b/Makefile
index 64133b6..5f43395 100644
--- a/Makefile
+++ b/Makefile
@@ -154,6 +154,7 @@ $(OBJS_DIR)/attribute_dimension.o \
$(OBJS_DIR)/attribute_event_info.o \
$(OBJS_DIR)/attribute_info.o \
$(OBJS_DIR)/attribute_info_ex.o \
+$(OBJS_DIR)/device_pipe.o \
$(OBJS_DIR)/pipe_info.o \
$(OBJS_DIR)/attribute_proxy.o \
$(OBJS_DIR)/base_types.o \
diff --git a/src/boost/cpp/base_types.cpp b/src/boost/cpp/base_types.cpp
index e9f2bf7..35d2d23 100644
--- a/src/boost/cpp/base_types.cpp
+++ b/src/boost/cpp/base_types.cpp
@@ -39,6 +39,7 @@ void export_device_data();
void export_device_attribute();
void export_device_data_history();
void export_device_attribute_history();
+void export_device_pipe();
void export_pipe_info();
void export_dev_error();
@@ -419,6 +420,7 @@ void export_base_types()
export_device_attribute();
export_device_data_history();
export_device_attribute_history();
+ export_device_pipe();
export_pipe_info();
export_dev_error();
diff --git a/src/boost/cpp/device_pipe.cpp b/src/boost/cpp/device_pipe.cpp
index 80da617..b6ba64d 100644
--- a/src/boost/cpp/device_pipe.cpp
+++ b/src/boost/cpp/device_pipe.cpp
@@ -24,8 +24,6 @@ namespace PyTango
{
namespace DevicePipe
{
- bopy::object extract(Tango::DevicePipeBlob&, PyTango::ExtractAs);
-
template<long tangoTypeConst>
bopy::object
__update_scalar_values(Tango::DevicePipe& self, size_t elt_idx)
@@ -65,7 +63,8 @@ namespace PyTango
__update_scalar_values<Tango::DEV_PIPE_BLOB>(Tango::DevicePipe& self,
size_t elt_idx)
{
- Tango::DevicePipeBlob val;
+ typedef std::string TangoScalarType;
+ TangoScalarType val;
bopy::str name(self.get_data_elt_name(elt_idx));
self >> val;
bopy::object data(val);
@@ -81,6 +80,7 @@ namespace PyTango
TangoArrayType tmp_arr;
self >> (&tmp_arr);
+ bopy::list result;
bopy::object data;
switch (extract_as)
{
@@ -104,8 +104,11 @@ namespace PyTango
break;
}
- bopy::str name(self.get_data_elt_name(elt_idx));
- return bopy::make_tuple(name, data);
+// bopy::str name(self.get_data_elt_name(elt_idx));
+// result.append(name);
+// result.append(data);
+// return result;
+ return data;
}
template <>
@@ -143,7 +146,27 @@ namespace PyTango
);
return bopy::object();
}
-
+
+ /*
+ bopy::object
+ extract(bopy::object py_dev_pipe,
+ PyTango::ExtractAs extract_as=PyTango::ExtractAsNumpy)
+ {
+ Tango::DevicePipe &self = \
+ bopy::extract<Tango::DevicePipe &>(py_dev_pipe);
+
+ py_value.attr("name") = self.get_name();
+ bopy::list data;
+ py_value.attr("data") = data;
+
+ size_t elt_nb = self.get_data_elt_nb();
+ for(size_t elt_idx = 0; elt_idx < elt_nb; ++elt_idx)
+ {
+ data.append(__extract(self, elt_idx, extract_as));
+ }
+ }
+ */
+
void
update_values(Tango::DevicePipe& self, bopy::object& py_self,
PyTango::ExtractAs extract_as /*=PyTango::ExtractAsNumpy*/)
@@ -161,192 +184,7 @@ namespace PyTango
data.append(update_value(self, py_self, elt_idx, extract_as));
}
}
-
- ///////////////////////////////////////////////////////////////////////////////////////////
-
- template<typename T, long tangoTypeConst>
- bopy::object
- __extract_scalar(T& obj, size_t elt_idx)
- {
- typedef typename TANGO_const2type(tangoTypeConst) TangoScalarType;
- TangoScalarType val;
- obj >> val;
- return bopy::object(val);
- }
-
- template<>
- bopy::object
- __extract_scalar<Tango::DevicePipe, Tango::DEV_VOID>(Tango::DevicePipe& obj, size_t elt_idx)
- {
- return bopy::object();
- }
-
- template<>
- bopy::object
- __extract_scalar<Tango::DevicePipe, Tango::DEV_STRING>(Tango::DevicePipe& obj, size_t elt_idx)
- {
- std::string val;
- obj >> val;
- return bopy::object(val);
- }
-
- template<>
- bopy::object
- __extract_scalar<Tango::DevicePipe, Tango::DEV_PIPE_BLOB>(Tango::DevicePipe& obj, size_t elt_idx)
- {
- Tango::DevicePipeBlob val;
- obj >> val;
- // TODO: propagate extract_as
- return extract(val, PyTango::ExtractAsNumpy);
- }
-
- template<>
- bopy::object
- __extract_scalar<Tango::DevicePipeBlob, Tango::DEV_VOID>(Tango::DevicePipeBlob& obj, size_t elt_idx)
- {
- return bopy::object();
- }
-
- template<>
- bopy::object
- __extract_scalar<Tango::DevicePipeBlob, Tango::DEV_STRING>(Tango::DevicePipeBlob& obj, size_t elt_idx)
- {
- std::string val;
- obj >> val;
- return bopy::object(val);
- }
-
- template<>
- bopy::object
- __extract_scalar<Tango::DevicePipeBlob, Tango::DEV_PIPE_BLOB>(Tango::DevicePipeBlob& obj, size_t elt_idx)
- {
- Tango::DevicePipeBlob val;
- obj >> val;
- // TODO: propagate extract_as
- return extract(val, PyTango::ExtractAsNumpy);
- }
-
- template<long tangoTypeConst>
- bopy::object
- extract_scalar(Tango::DevicePipe& self, size_t elt_idx)
- {
- return __extract_scalar<Tango::DevicePipe, tangoTypeConst>(self, elt_idx);
- }
-
- template<long tangoTypeConst>
- bopy::object
- extract_scalar(Tango::DevicePipeBlob& self, size_t elt_idx)
- {
- return __extract_scalar<Tango::DevicePipeBlob, tangoTypeConst>(self, elt_idx);
- }
-
- template <typename T, long tangoArrayTypeConst>
- bopy::object
- __extract_array(T& obj, size_t elt_idx, PyTango::ExtractAs extract_as)
- {
- if (tangoArrayTypeConst == Tango::DEVVAR_LONGSTRINGARRAY ||
- tangoArrayTypeConst == Tango::DEVVAR_DOUBLESTRINGARRAY)
- {
- assert(false);
- return bopy::object();
- }
-
- typedef typename TANGO_const2type(tangoArrayTypeConst) TangoArrayType;
-
- TangoArrayType tmp_arr;
- obj >> (&tmp_arr);
- bopy::object data;
- switch (extract_as)
- {
- default:
- case PyTango::ExtractAsNumpy:
-
-# ifndef DISABLE_PYTANGO_NUMPY
- data = to_py_numpy<tangoArrayTypeConst>(&tmp_arr, 1);
- break;
-# endif
-
- case PyTango::ExtractAsList:
- case PyTango::ExtractAsPyTango3:
- data = to_py_list(&tmp_arr);
- break;
- case PyTango::ExtractAsTuple:
- data = to_py_tuple(&tmp_arr);
- break;
- case PyTango::ExtractAsString: /// @todo
- case PyTango::ExtractAsNothing:
- data = bopy::object();
- break;
- }
- return data;
- }
-
- template <long tangoArrayTypeConst>
- bopy::object
- extract_array(Tango::DevicePipe& self, size_t elt_idx,
- PyTango::ExtractAs extract_as)
- {
- return __extract_array<Tango::DevicePipe, tangoArrayTypeConst>(self, elt_idx,
- extract_as);
- }
-
- template <long tangoArrayTypeConst>
- bopy::object
- extract_array(Tango::DevicePipeBlob& self, size_t elt_idx,
- PyTango::ExtractAs extract_as)
- {
- return __extract_array<Tango::DevicePipeBlob, tangoArrayTypeConst>(self, elt_idx,
- extract_as);
- }
-
- template<typename T>
- bopy::object
- __extract_item(T& obj, size_t elt_idx, PyTango::ExtractAs extract_as)
- {
- const int elt_type = obj.get_data_elt_type(elt_idx);
- TANGO_DO_ON_DEVICE_DATA_TYPE_ID(elt_type,
- return extract_scalar<tangoTypeConst>(obj, elt_idx);
- ,
- return extract_array<tangoTypeConst>(obj, elt_idx, extract_as);
- );
- return bopy::object();
- }
-
- template<typename T>
- bopy::object
- __extract(T& obj, PyTango::ExtractAs extract_as)
- {
- bopy::list data;
- size_t elt_nb = obj.get_data_elt_nb();
- for(size_t elt_idx = 0; elt_idx < elt_nb; ++elt_idx)
- {
- bopy::dict elem;
- elem["name"] = obj.get_data_elt_name(elt_idx);
- elem["dtype"] = static_cast<Tango::CmdArgType>(obj.get_data_elt_type(elt_idx));
- elem["value"] = __extract_item(obj, elt_idx, extract_as);
- data.append(elem);
- }
- return data;
- }
-
- bopy::object
- extract(Tango::DevicePipeBlob& blob,
- PyTango::ExtractAs extract_as=PyTango::ExtractAsNumpy)
- {
- bopy::object name = bopy::str(blob.get_name());
- bopy::object value = __extract<Tango::DevicePipeBlob>(blob, extract_as);
- return bopy::make_tuple(name, value);
- }
-
- bopy::object
- extract(Tango::DevicePipe& device_pipe,
- PyTango::ExtractAs extract_as=PyTango::ExtractAsNumpy)
- {
- bopy::object name = bopy::str(device_pipe.get_root_blob_name());
- bopy::object value = __extract<Tango::DevicePipe>(device_pipe, extract_as);
- return bopy::make_tuple(name, value);
- }
- }
+ }
}
void export_device_pipe()
@@ -378,9 +216,5 @@ void export_device_pipe()
&Tango::DevicePipe::set_data_elt_names)
.def("get_data_elt_name", &Tango::DevicePipe::get_data_elt_name)
.def("get_data_elt_type", &Tango::DevicePipe::get_data_elt_type)
-
- .def("extract",
- (bopy::object (*) (Tango::DevicePipe &, PyTango::ExtractAs))
- PyTango::DevicePipe::extract)
;
}
diff --git a/src/boost/cpp/device_proxy.cpp b/src/boost/cpp/device_proxy.cpp
index 6f1b2b2..c2d93fa 100644
--- a/src/boost/cpp/device_proxy.cpp
+++ b/src/boost/cpp/device_proxy.cpp
@@ -82,11 +82,20 @@ namespace PyDeviceProxy
}
}
- Tango::DevicePipe
- read_pipe(Tango::DeviceProxy& self, const std::string & pipe_name)
+ static bopy::object
+ read_pipe(Tango::DeviceProxy& self, const std::string & pipe_name,
+ PyTango::ExtractAs extract_as)
{
- AutoPythonAllowThreads guard;
- return self.read_pipe(pipe_name);
+ Tango::DevicePipe* dev_pipe_result;
+ {
+ AutoPythonAllowThreads guard;
+ Tango::DevicePipe dev_pipe_read = self.read_pipe(pipe_name);
+ dev_pipe_result = new Tango::DevicePipe;
+ (*dev_pipe_result) = std::move(dev_pipe_read);
+
+ }
+
+ return PyTango::DevicePipe::convert_to_python(dev_pipe_result, extract_as);
}
static bopy::object read_attribute(Tango::DeviceProxy& self, const std::string & attr_name, PyTango::ExtractAs extract_as)
@@ -586,6 +595,10 @@ void export_device_proxy()
&Tango::DeviceProxy::set_pipe_config,
( arg_("self"), arg_("seq") ) )
+ .def("_read_pipe", &PyDeviceProxy::read_pipe,
+ ( arg_("self"), arg_("pipe_name"),
+ arg_("extract_as")=PyTango::ExtractAsNumpy ) )
+
//
// attribute methods
//
diff --git a/src/boost/cpp/tgutils.h b/src/boost/cpp/tgutils.h
index ea8d5fd..6746dba 100644
--- a/src/boost/cpp/tgutils.h
+++ b/src/boost/cpp/tgutils.h
@@ -115,11 +115,6 @@ TSD_SIMPLE__( DEV_STATE, Tango::DevState , Tango::DevVarStateAr
TSD_SIMPLE__( DEV_ENCODED, Tango::DevEncoded, Tango::DevVarEncodedArray );
TSD_SIMPLE__( DEV_PIPE_BLOB, Tango::DevPipeBlob, void );
-// since enum type is implemented as a short we cannot use tango_type2name because
-// it will conflict with the DevShort template declaration
-DEF_TANGO_NAME2TYPE__( DEV_ENUM, Tango::DevEnum);
-DEF_TANGO_NAME2ARRAY( DEV_ENUM, Tango::DevVarShortArray, Tango::DevEnum);
-
TSD_SIMPLE__( DEV_VOID, void , void);
TSD_ARRAY__( DEVVAR_CHARARRAY, _CORBA_Octet , Tango::DevVarCharArray);
@@ -264,7 +259,6 @@ DEF_TANGO_SCALAR_ARRAY_NAMES( DEV_STATE, DEVVAR_STATEARRAY );
/* __TANGO_DEPEND_ON_TYPE_AUX_ID(DEV_INT, DOIT_SIMPLE) */\
__TANGO_DEPEND_ON_TYPE_AUX_ID(DEV_ENCODED, DOIT_SIMPLE) \
__TANGO_DEPEND_ON_TYPE_AUX_ID(DEV_PIPE_BLOB, DOIT_SIMPLE) \
- __TANGO_DEPEND_ON_TYPE_AUX_ID(DEV_ENUM, DOIT_SIMPLE) \
default: \
assert(false); \
} } else (void)0
@@ -322,7 +316,6 @@ DEF_TANGO_SCALAR_ARRAY_NAMES( DEV_STATE, DEVVAR_STATEARRAY );
/* __TANGO_DEPEND_ON_TYPE_AUX_NAME(DEV_INT, DOIT_SIMPLE) */\
__TANGO_DEPEND_ON_TYPE_AUX_NAME(DEV_ENCODED, DOIT_SIMPLE) \
__TANGO_DEPEND_ON_TYPE_AUX_NAME(DEV_PIPE_BLOB, DOIT_SIMPLE) \
- __TANGO_DEPEND_ON_TYPE_AUX_NAME(DEV_ENUM, DOIT_SIMPLE) \
default: \
assert(false); \
} } else (void)0
diff --git a/src/boost/python/device_proxy.py b/src/boost/python/device_proxy.py
index b30a6d2..0257289 100644
--- a/src/boost/python/device_proxy.py
+++ b/src/boost/python/device_proxy.py
@@ -1183,11 +1183,7 @@ def __DeviceProxy__str(self):
return "%s(%s)" % (info.dev_class, self.dev_name())
def __DeviceProxy__read_pipe(self, pipe_name, extract_as=ExtractAs.Numpy):
- r = self.__read_pipe(pipe_name)
- return r.extract(extract_as)
-
-def __DeviceProxy__write_pipe(*args, **kwargs):
- raise NotImplementedError('writtable pipes not implemented in 9.2.0a')
+ return self._read_pipe(pipe_name, extract_as)
def __DeviceProxy__read_attributes(self, *args, **kwargs):
return self._read_attributes(*args, **kwargs)
@@ -1302,8 +1298,7 @@ def __init_DeviceProxy():
DeviceProxy.write_attribute_asynch = __DeviceProxy__write_attribute_asynch
DeviceProxy.write_attribute_reply = __DeviceProxy__write_attribute_reply
- DeviceProxy.read_pipe = green(__DeviceProxy__read_pipe)
- DeviceProxy.write_pipe = green(__DeviceProxy__write_pipe)
+ DeviceProxy.read_pipe = __DeviceProxy__read_pipe
DeviceProxy.get_property = __DeviceProxy__get_property
DeviceProxy.put_property = __DeviceProxy__put_property
--
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