[pytango] 28/98: Initial pipe version
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 83a9229282489c8dfcb26f6d27f28322d8143479
Author: Jose Tiago Coutinho Macara <tiago.coutinho at esrf.fr>
Date: Tue Feb 2 12:43:11 2016 +0100
Initial pipe version
---
Makefile | 3 +-
src/boost/cpp/device_pipe.cpp | 226 +++++++++++++++++++++++++++++-----
src/boost/cpp/device_proxy.cpp | 22 +---
src/boost/cpp/enums.cpp | 8 ++
src/boost/cpp/server/device_class.cpp | 2 +-
src/boost/python/__init__.py | 3 +-
src/boost/python/device_proxy.py | 3 +-
src/boost/python/device_server.py | 17 +--
src/boost/python/pytango_init.py | 2 +
src/boost/python/server.py | 42 +++----
10 files changed, 239 insertions(+), 89 deletions(-)
diff --git a/Makefile b/Makefile
index 5f43395..208825e 100644
--- a/Makefile
+++ b/Makefile
@@ -207,7 +207,8 @@ $(OBJS_DIR)/subdev.o \
$(OBJS_DIR)/tango_util.o \
$(OBJS_DIR)/user_default_attr_prop.o \
$(OBJS_DIR)/user_default_pipe_prop.o \
-$(OBJS_DIR)/wattribute.o
+$(OBJS_DIR)/wattribute.o \
+$(OBJS_DIR)/auto_monitor.o
INC := callback.h \
defs.h \
diff --git a/src/boost/cpp/device_pipe.cpp b/src/boost/cpp/device_pipe.cpp
index b6ba64d..80da617 100644
--- a/src/boost/cpp/device_pipe.cpp
+++ b/src/boost/cpp/device_pipe.cpp
@@ -24,6 +24,8 @@ 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)
@@ -63,8 +65,7 @@ namespace PyTango
__update_scalar_values<Tango::DEV_PIPE_BLOB>(Tango::DevicePipe& self,
size_t elt_idx)
{
- typedef std::string TangoScalarType;
- TangoScalarType val;
+ Tango::DevicePipeBlob val;
bopy::str name(self.get_data_elt_name(elt_idx));
self >> val;
bopy::object data(val);
@@ -80,7 +81,6 @@ namespace PyTango
TangoArrayType tmp_arr;
self >> (&tmp_arr);
- bopy::list result;
bopy::object data;
switch (extract_as)
{
@@ -104,11 +104,8 @@ namespace PyTango
break;
}
-// bopy::str name(self.get_data_elt_name(elt_idx));
-// result.append(name);
-// result.append(data);
-// return result;
- return data;
+ bopy::str name(self.get_data_elt_name(elt_idx));
+ return bopy::make_tuple(name, data);
}
template <>
@@ -146,27 +143,7 @@ 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*/)
@@ -184,7 +161,192 @@ 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()
@@ -216,5 +378,9 @@ 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 c2d93fa..28f0689 100644
--- a/src/boost/cpp/device_proxy.cpp
+++ b/src/boost/cpp/device_proxy.cpp
@@ -82,20 +82,11 @@ namespace PyDeviceProxy
}
}
- static bopy::object
- read_pipe(Tango::DeviceProxy& self, const std::string & pipe_name,
- PyTango::ExtractAs extract_as)
+ Tango::DevicePipe
+ read_pipe(Tango::DeviceProxy& self, const std::string & 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);
+ AutoPythonAllowThreads guard;
+ return self.read_pipe(pipe_name);
}
static bopy::object read_attribute(Tango::DeviceProxy& self, const std::string & attr_name, PyTango::ExtractAs extract_as)
@@ -595,9 +586,8 @@ 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 ) )
+ .def("__read_pipe", &PyDeviceProxy::read_pipe,
+ ( arg_("self"), arg_("pipe_name") ) )
//
// attribute methods
diff --git a/src/boost/cpp/enums.cpp b/src/boost/cpp/enums.cpp
index c86ddff..0f80c13 100644
--- a/src/boost/cpp/enums.cpp
+++ b/src/boost/cpp/enums.cpp
@@ -226,6 +226,14 @@ void export_enums()
.value("PIPE_WT_UNKNOWN", Tango::PIPE_WT_UNKNOWN)
;
+ enum_<Tango::PipeSerialModel>("PipeSerialModel")
+ .value("PIPE_NO_SYNC", Tango::PIPE_NO_SYNC)
+ .value("PIPE_BY_KERNEL", Tango::PIPE_BY_KERNEL)
+ .value("PIPE_BY_USER", Tango::PIPE_BY_USER)
+ ;
+
+ scope().attr("PipeReqType") = scope().attr("AttReqType");
+
enum_<Tango::AttrMemorizedType>("AttrMemorizedType")
.value("NOT_KNOWN", Tango::NOT_KNOWN)
.value("NONE", Tango::NONE)
diff --git a/src/boost/cpp/server/device_class.cpp b/src/boost/cpp/server/device_class.cpp
index fc4b046..4616ed5 100644
--- a/src/boost/cpp/server/device_class.cpp
+++ b/src/boost/cpp/server/device_class.cpp
@@ -426,7 +426,7 @@ void export_device_class()
.def("get_cvs_location",&Tango::DeviceClass::get_cvs_location,
return_value_policy<copy_non_const_reference>())
.def("get_device_list",&PyDeviceClass::get_device_list)
- .def("get_command_list",&PyDeviceClass::get_command_list)
+ .def("get_command_list",&PyDeviceClass::get_device_list)
.def("get_pipe_list",&PyDeviceClass::get_pipe_list)
.def("get_cmd_by_name",&Tango::DeviceClass::get_cmd_by_name,
return_internal_reference<>())
diff --git a/src/boost/python/__init__.py b/src/boost/python/__init__.py
index 0e21e17..70f229a 100644
--- a/src/boost/python/__init__.py
+++ b/src/boost/python/__init__.py
@@ -156,7 +156,8 @@ from ._PyTango import (AccessControlType, ApiUtil, ArchiveEventInfo,
StdNamedDevFailedVector, StdStringVector, SubDevDiag, TimeVal,
UserDefaultAttrProp, UserDefaultPipeProp, WAttribute, WRITE, WrongData,
WrongNameSyntax, alarm_flags, asyn_req_type, cb_sub_model, constants,
- raise_asynch_exception, Interceptors)
+ raise_asynch_exception, Interceptors,
+ AutoTangoMonitor, AutoTangoAllowThreads)
ArgType = CmdArgType
diff --git a/src/boost/python/device_proxy.py b/src/boost/python/device_proxy.py
index 0257289..00f954a 100644
--- a/src/boost/python/device_proxy.py
+++ b/src/boost/python/device_proxy.py
@@ -1183,7 +1183,8 @@ def __DeviceProxy__str(self):
return "%s(%s)" % (info.dev_class, self.dev_name())
def __DeviceProxy__read_pipe(self, pipe_name, extract_as=ExtractAs.Numpy):
- return self._read_pipe(pipe_name, extract_as)
+ r = self.__read_pipe(pipe_name)
+ return r.extract(extract_as)
def __DeviceProxy__read_attributes(self, *args, **kwargs):
return self._read_attributes(*args, **kwargs)
diff --git a/src/boost/python/device_server.py b/src/boost/python/device_server.py
index 442b777..aa40a94 100644
--- a/src/boost/python/device_server.py
+++ b/src/boost/python/device_server.py
@@ -18,9 +18,8 @@ from __future__ import print_function
__all__ = [ "ChangeEventProp", "PeriodicEventProp",
"ArchiveEventProp","AttributeAlarm", "EventProperties",
"AttributeConfig", "AttributeConfig_2",
- "AttributeConfig_3", "AttributeConfig_5", "PipeConfig",
- "MultiAttrProp",
- "device_server_init"]
+ "AttributeConfig_3", "AttributeConfig_5",
+ "MultiAttrProp", "device_server_init"]
__docformat__ = "restructuredtext"
@@ -29,7 +28,7 @@ import copy
from ._PyTango import DeviceImpl, Device_3Impl, Device_4Impl, Device_5Impl, \
DevFailed, Attribute, WAttribute, \
MultiAttribute, MultiClassAttribute, \
- Attr, Logger, AttrWriteType, PipeWriteType, AttrDataFormat, \
+ Attr, Logger, AttrWriteType, AttrDataFormat, CmdArgType, \
DispLevel, UserDefaultAttrProp, StdStringVector
from .utils import document_method as __document_method
@@ -177,17 +176,7 @@ class AttributeConfig_5(object):
self.event_prop = EventProperties()
self.sys_extensions = []
-class PipeConfig(object):
- """
- This class represents the python interface for the Tango IDL
- object PipeConfig."""
- def __init__(self):
- self.name = ''
- self.description = ''
- self.label = ''
- self.level = PipeWriteType.PIPE_READ
- self.extensions = []
def __Attribute__get_properties(self, attr_cfg = None):
"""get_properties(self, attr_cfg = None) -> AttributeConfig
diff --git a/src/boost/python/pytango_init.py b/src/boost/python/pytango_init.py
index 018554e..6bdb820 100644
--- a/src/boost/python/pytango_init.py
+++ b/src/boost/python/pytango_init.py
@@ -36,6 +36,7 @@ from .group_reply_list import group_reply_list_init
from .pytango_pprint import pytango_pprint_init
from .pyutil import pyutil_init
from .time_val import time_val_init
+from .auto_monitor import auto_monitor_init
from .pipe import pipe_init
from ._PyTango import constants
from ._PyTango import _get_tango_lib_release
@@ -112,6 +113,7 @@ def init():
pytango_pprint_init(doc=doc)
pyutil_init(doc=doc)
time_val_init(doc=doc)
+ auto_monitor_init(doc=doc)
pipe_init(doc=doc)
# must come last: depends on device_proxy.init()
diff --git a/src/boost/python/server.py b/src/boost/python/server.py
index 5b604b4..6892b50 100644
--- a/src/boost/python/server.py
+++ b/src/boost/python/server.py
@@ -878,14 +878,9 @@ class attribute(AttrData):
class pipe(PipeData):
'''
Declares a new tango pipe in a :class:`Device`. To be used
- like the python native :obj:`property` function.
-
- Checkout the :ref:`pipe data types <pytango-pipe-data-types>`
- to see what you should return on a pipe read request and what
- to expect as argument on a pipe write request.
-
- For example, to declare a read-only pipe called *ROI*
- (for Region Of Interest), in a *Detector* :class:`Device` do::
+ like the python native :obj:`property` function. For example, to
+ declare a read-only pipe called *ROI* (for Region Of Interest), in a
+ *Detector* :class:`Device` do::
class Detector(Device):
__metaclass__ = DeviceMeta
@@ -893,20 +888,16 @@ class pipe(PipeData):
ROI = pipe()
def read_ROI(self):
- return ('ROI', ({'name': 'x', 'value': 0},
- {'name': 'y', 'value': 10},
- {'name': 'width', 'value': 100},
- {'name': 'height', 'value': 200}))
+ return dict(x=0, y=10, width=100, height=200)
- The same can be achieved with (also showing that a dict can be used
- to pass blob data)::
+ The same can be achieved with::
class Detector(Device):
__metaclass__ = DeviceMeta
@pipe
def ROI(self):
- return 'ROI', dict(x=0, y=10, width=100, height=200)
+ return dict(x=0, y=10, width=100, height=200)
It receives multiple keyword arguments.
@@ -927,7 +918,7 @@ class pipe(PipeData):
write_green_mode :obj:`~PyTango.GreenMode` None green mode for write. None means use server green mode.
===================== ================================ ======================================= =======================================================================================
- The same example with a read-write ROI, a customized label and description::
+ The same example with a read-write ROI, a customized label and description and::
class Detector(Device):
__metaclass__ = DeviceMeta
@@ -937,13 +928,13 @@ class pipe(PipeData):
def init_device(self):
Device.init_device(self)
- self.__roi = 'ROI', dict(x=0, y=10, width=100, height=200)
+ self.__roi = dict(x=0, y=10, width=100, height=200)
def read_ROI(self):
return self.__roi
def write_ROI(self, roi):
- self.__roi = roi
+ self.__roi = dict(roi)
The same, but using pipe as a decorator::
@@ -953,7 +944,7 @@ class pipe(PipeData):
def init_device(self):
Device.init_device(self)
- self.__roi = 'ROI', dict(x=0, y=10, width=100, height=200)
+ self.__roi = dict(x=0, y=10, width=100, height=200)
@pipe(label="Region Of Interest")
def ROI(self):
@@ -962,12 +953,12 @@ class pipe(PipeData):
@ROI.write
def ROI(self, roi):
- self.__roi = roi
+ self.__roi = dict(roi)
In this second format, defining the `write` / `setter` implicitly sets
the pipe access to READ_WRITE.
- .. versionadded:: 9.2.0
+ .. versionadded:: 9.1.0
'''
def __init__(self, fget=None, **kwargs):
@@ -988,8 +979,6 @@ class pipe(PipeData):
super(pipe, self).__init__(name, class_name)
self.build_from_dict(kwargs)
- if self.pipe_write == PipeWriteType.PIPE_READ_WRITE:
- raise NotImplementedError('writtable pipes not implemented in 9.2.0a')
def get_pipe(self, obj):
dclass = obj.get_device_class()
@@ -1011,9 +1000,12 @@ class pipe(PipeData):
To be used as a decorator. Will define the decorated method
as a write pipe method to be called when client writes to the pipe
"""
- raise NotImplementedError('writtable pipes not implemented in 9.2.0a')
self.fset = fset
- self.pipe_write = PipeWriteType.PIPE_READ_WRITE
+ if self.attr_write == AttrWriteType.READ:
+ if getattr(self, 'fget', None):
+ self.attr_write = AttrWriteType.READ_WRITE
+ else:
+ self.attr_write = AttrWriteType.WRITE
return self
def write(self, fset):
--
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