[pytango] 05/483: first part of implementating Attribute.get/set_properties
Sandor Bodo-Merle
sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:19 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 c5aa67b831e4e4ccd35b7be2786312e968ed1cad
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date: Fri Mar 11 14:53:55 2011 +0000
first part of implementating Attribute.get/set_properties
git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@16021 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
PyTango/device_proxy.py | 7 ++-
PyTango/device_server.py | 83 ++++++++++++++++++++++++++++----
doc/_templates/layout.html | 21 +++++++-
setup.py | 3 ++
src/server/attribute.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++
src/server/attribute.h | 12 +++++
src/server/tango_util.cpp | 116 +++++++++++++++++++++++++++++++++++++--------
7 files changed, 323 insertions(+), 30 deletions(-)
diff --git a/PyTango/device_proxy.py b/PyTango/device_proxy.py
index 346bc57..44efe74 100644
--- a/PyTango/device_proxy.py
+++ b/PyTango/device_proxy.py
@@ -28,7 +28,11 @@ __all__ = []
__docformat__ = "restructuredtext"
-import operator, types
+import sys
+import operator
+import types
+import threading
+import traceback
from _PyTango import StdStringVector
from _PyTango import DbData, DbDatum
@@ -687,6 +691,7 @@ def __DeviceProxy__subscribe_event ( self, attr_name, event_type, cb_or_queuesiz
All other parameters are similar to the descriptions given in the
other subscribe_event() version.
"""
+
if callable(cb_or_queuesize):
cb = __CallBackPushEvent()
cb.push_event = cb_or_queuesize
diff --git a/PyTango/device_server.py b/PyTango/device_server.py
index e835884..f76f5e6 100644
--- a/PyTango/device_server.py
+++ b/PyTango/device_server.py
@@ -40,6 +40,7 @@ from _PyTango import DeviceImpl, Device_3Impl, Device_4Impl
from _PyTango import Attribute, WAttribute, MultiAttribute
from _PyTango import Attr
from _PyTango import Logger
+from _PyTango import AttrWriteType, AttrDataFormat, DispLevel
from _PyTango import UserDefaultAttrProp
from utils import seq_2_StdStringVector, seq_2_StdDoubleVector
@@ -100,12 +101,12 @@ class EventProperties(object):
def _init_attr_config(attr_cfg):
"""Helper function to initialize attribute config objects"""
attr_cfg.name = ''
- attr_cfg.writable = -1
- attr_cfg.data_format = -1
- attr_cfg.data_type = -1
- attr_cfg.max_dim_x = -1
- attr_cfg.max_dim_y = -1
- attr_cfg.description = -1
+ attr_cfg.writable = AttrWriteType.READ
+ attr_cfg.data_format = AttrDataFormat.SCALAR
+ attr_cfg.data_type = 0
+ attr_cfg.max_dim_x = 0
+ attr_cfg.max_dim_y = 0
+ attr_cfg.description = ''
attr_cfg.label = ''
attr_cfg.unit = ''
attr_cfg.standard_unit = ''
@@ -131,7 +132,7 @@ class AttributeConfig_2(object):
def __init__(self):
_init_attr_config(self)
- self.level = -1
+ self.level = DispLevel.OPERATOR
self.min_alarm = ''
self.max_alarm = ''
@@ -146,6 +147,69 @@ class AttributeConfig_3(object):
self.event_prop = EventProperties()
self.sys_extensions = []
+def __Attribute__get_properties(self, attr_cfg = None):
+ """get_properties(self, attr_cfg = None) -> None
+
+ Get attribute properties.
+
+ Parameters :
+ - conf : (AttributeConfig) the config object to be filled with
+ the attribute configuration. Default is None meaning the
+ method will create internally a new AttributeConfig
+ and return it
+
+ Return : (AttributeConfig) the config object filled with
+ attribute configuration information
+
+ New in PyTango 7.2.0
+ """
+
+ if attr_cfg is None:
+ attr_cfg = AttributeConfig()
+ return self._get_properties(attr_cfg)
+
+def __Attribute__get_properties_2(self, attr_cfg = None):
+ """get_properties_2(self, attr_cfg = None) -> None
+
+ Get attribute properties.
+
+ Parameters :
+ - conf : (AttributeConfig_2) the config object to be filled with
+ the attribute configuration. Default is None meaning the
+ method will create internally a new AttributeConfig
+ and return it
+
+ Return : (AttributeConfig_2) the config object filled with
+ attribute configuration information
+
+ New in PyTango 7.2.0
+ """
+
+ if attr_cfg is None:
+ attr_cfg = AttributeConfig_2()
+ return self._get_properties_2(attr_cfg)
+
+def __Attribute__get_properties_3(self, attr_cfg = None):
+ """get_properties_3(self, attr_cfg = None) -> None
+
+ Get attribute properties.
+
+ Parameters :
+ - conf : (AttributeConfig_3) the config object to be filled with
+ the attribute configuration. Default is None meaning the
+ method will create internally a new AttributeConfig
+ and return it
+
+ Return : (AttributeConfig_3) the config object filled with
+ attribute configuration information
+
+ New in PyTango 7.2.0
+ """
+
+ if attr_cfg is None:
+ attr_cfg = AttributeConfig_2()
+ return self._get_properties_2(attr_cfg)
+
def __DeviceImpl__get_device_class(self):
try:
return self._device_class_instance
@@ -519,7 +583,10 @@ def __Attribute__str(self):
def __init_Attribute():
Attribute.__str__ = __Attribute__str
Attribute.__repr__ = __Attribute__str
-
+ Attribute.get_properties = __Attribute__get_properties
+ Attribute.get_properties_2 = __Attribute__get_properties_2
+ Attribute.get_properties_3 = __Attribute__get_properties_3
+
def __init_Logger():
Logger.log = __Logger__log
Logger.log_unconditionally = __Logger__log_unconditionally
diff --git a/doc/_templates/layout.html b/doc/_templates/layout.html
index ed3d08e..30d38e0 100644
--- a/doc/_templates/layout.html
+++ b/doc/_templates/layout.html
@@ -1,4 +1,20 @@
-{% extends "sphinxdoc/layout.html" %}
+{% extends "!layout.html" %}
+
+{% block extrahead %}
+ <script src="{{ pathto('_static/js/jquery.min.js',1) }}"></script>
+ <script src="{{ pathto('_static/js/jquery.mousewheel.min.js',1) }}"></script>
+ <script src="{{ pathto('_static/js/jquery.terminal.min.js',1) }}"></script>
+ <link href="{{ pathto('_static/css/jquery.terminal.css',1) }}" rel="stylesheet"/>
+
+ <link href="{{ pathto('_static/css/start/jquery-ui-1.8.10.custom.css',1) }}" rel="stylesheet"/>
+ <link href="{{ pathto('_static/css/pytango.css',1) }}" rel="stylesheet"/>
+ <link href="{{ pathto('_static/css/pytango_terminal.css',1) }}" rel="stylesheet"/>
+ <script src="{{ pathto('_static/js/jquery-ui-1.8.10.custom.min.js',1) }}"></script>
+
+ <script src="{{ pathto('_static/js/dterm.js',1) }}"></script>
+ <script src="{{ pathto('_static/js/pytango.js',1) }}"></script>
+
+{% endblock %}
{% block rootrellink %}
<li><a href="{{ pathto('index') }}">home</a>| </li>
@@ -8,3 +24,6 @@
{% endblock %}
+{% block relbaritems %}
+ <li>:: <a id="open_terminal" href="">open terminal</a> ::<div id="dialog"/></li>
+{% endblock %}
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 55167ee..ac054c6 100644
--- a/setup.py
+++ b/setup.py
@@ -142,6 +142,9 @@ include_dirs = [ os.path.abspath('src') ]
_tango_root_inc = os.path.join(TANGO_ROOT, 'include')
include_dirs.append(_tango_root_inc)
+_tango_root_inc = os.path.join(_tango_root_inc, 'tango')
+if os.path.isdir(_tango_root_inc):
+ include_dirs.append(_tango_root_inc)
include_dirs.extend([
os.path.join(OMNI_ROOT, 'include'),
diff --git a/src/server/attribute.cpp b/src/server/attribute.cpp
index fd4329f..8a9479e 100644
--- a/src/server/attribute.cpp
+++ b/src/server/attribute.cpp
@@ -361,6 +361,111 @@ namespace PyAttribute
double t, Tango::AttrQuality quality,
long x, long y)
{ __set_value("set_value_date_quality", att, value, &x, &y, t, &quality); }
+
+ inline boost::python::object get_properties(Tango::Attribute &att,
+ boost::python::object &attr_cfg)
+ {
+ Tango::AttributeConfig tg_attr_cfg;
+ att.get_properties(tg_attr_cfg);
+ attr_cfg.attr("writable") = tg_attr_cfg.writable;
+ attr_cfg.attr("data_format") = tg_attr_cfg.data_format;
+ attr_cfg.attr("max_dim_x") = tg_attr_cfg.max_dim_x;
+ attr_cfg.attr("max_dim_y") = tg_attr_cfg.max_dim_y;
+ attr_cfg.attr("data_type") = tg_attr_cfg.data_type;
+ attr_cfg.attr("name") = tg_attr_cfg.name;
+ attr_cfg.attr("label") = tg_attr_cfg.label;
+ attr_cfg.attr("description") = tg_attr_cfg.description;
+ attr_cfg.attr("unit") = tg_attr_cfg.unit;
+ attr_cfg.attr("standard_unit") = tg_attr_cfg.standard_unit;
+ attr_cfg.attr("display_unit") = tg_attr_cfg.display_unit;
+ attr_cfg.attr("format") = tg_attr_cfg.format;
+ attr_cfg.attr("writable_attr_name") = tg_attr_cfg.writable_attr_name;
+ attr_cfg.attr("min_alarm") = tg_attr_cfg.min_alarm;
+ attr_cfg.attr("max_alarm") = tg_attr_cfg.max_alarm;
+ attr_cfg.attr("min_value") = tg_attr_cfg.min_value;
+ attr_cfg.attr("max_value") = tg_attr_cfg.max_value;
+
+ return attr_cfg;
+ }
+
+ inline boost::python::object get_properties_2(Tango::Attribute &att,
+ boost::python::object &attr_cfg)
+ {
+ Tango::AttributeConfig_2 tg_attr_cfg;
+ att.get_properties_2(tg_attr_cfg);
+ attr_cfg.attr("writable") = tg_attr_cfg.writable;
+ attr_cfg.attr("data_format") = tg_attr_cfg.data_format;
+ attr_cfg.attr("max_dim_x") = tg_attr_cfg.max_dim_x;
+ attr_cfg.attr("max_dim_y") = tg_attr_cfg.max_dim_y;
+ attr_cfg.attr("data_type") = tg_attr_cfg.data_type;
+ attr_cfg.attr("name") = tg_attr_cfg.name;
+ attr_cfg.attr("label") = tg_attr_cfg.label;
+ attr_cfg.attr("description") = tg_attr_cfg.description;
+ attr_cfg.attr("unit") = tg_attr_cfg.unit;
+ attr_cfg.attr("standard_unit") = tg_attr_cfg.standard_unit;
+ attr_cfg.attr("display_unit") = tg_attr_cfg.display_unit;
+ attr_cfg.attr("format") = tg_attr_cfg.format;
+ attr_cfg.attr("writable_attr_name") = tg_attr_cfg.writable_attr_name;
+ attr_cfg.attr("min_alarm") = tg_attr_cfg.min_alarm;
+ attr_cfg.attr("max_alarm") = tg_attr_cfg.max_alarm;
+ attr_cfg.attr("min_value") = tg_attr_cfg.min_value;
+ attr_cfg.attr("max_value") = tg_attr_cfg.max_value;
+ attr_cfg.attr("level") = tg_attr_cfg.level;
+
+ return attr_cfg;
+ }
+
+ inline boost::python::object get_properties_3(Tango::Attribute &att,
+ boost::python::object &attr_cfg)
+ {
+ Tango::AttributeConfig_3 tg_attr_cfg;
+ att.get_properties_3(tg_attr_cfg);
+ attr_cfg.attr("writable") = tg_attr_cfg.writable;
+ attr_cfg.attr("data_format") = tg_attr_cfg.data_format;
+ attr_cfg.attr("max_dim_x") = tg_attr_cfg.max_dim_x;
+ attr_cfg.attr("max_dim_y") = tg_attr_cfg.max_dim_y;
+ attr_cfg.attr("data_type") = tg_attr_cfg.data_type;
+ attr_cfg.attr("name") = tg_attr_cfg.name;
+ attr_cfg.attr("label") = tg_attr_cfg.label;
+ attr_cfg.attr("description") = tg_attr_cfg.description;
+ attr_cfg.attr("unit") = tg_attr_cfg.unit;
+ attr_cfg.attr("standard_unit") = tg_attr_cfg.standard_unit;
+ attr_cfg.attr("display_unit") = tg_attr_cfg.display_unit;
+ attr_cfg.attr("format") = tg_attr_cfg.format;
+ attr_cfg.attr("writable_attr_name") = tg_attr_cfg.writable_attr_name;
+ attr_cfg.attr("min_value") = tg_attr_cfg.min_value;
+ attr_cfg.attr("max_value") = tg_attr_cfg.max_value;
+ attr_cfg.attr("level") = tg_attr_cfg.level;
+
+ // Copy alarm properties
+ object att_alarm = attr_cfg.attr("att_alarm");
+ att_alarm.attr("min_alarm") = tg_attr_cfg.att_alarm.min_alarm;
+ att_alarm.attr("max_alarm") = tg_attr_cfg.att_alarm.max_alarm;
+ att_alarm.attr("min_warning") = tg_attr_cfg.att_alarm.min_warning;
+ att_alarm.attr("max_warning") = tg_attr_cfg.att_alarm.max_warning;
+ att_alarm.attr("delta_t") = tg_attr_cfg.att_alarm.delta_t;
+ att_alarm.attr("delta_val") = tg_attr_cfg.att_alarm.delta_val;
+
+ object event_prop = attr_cfg.attr("event_prop");
+
+ // Copy periodic event property
+ object per_event = event_prop.attr("per_event");
+ per_event.attr("period") = tg_attr_cfg.event_prop.per_event.period;
+
+ // Copy change event properties
+ object ch_event = event_prop.attr("ch_event");
+ ch_event.attr("rel_change") = tg_attr_cfg.event_prop.ch_event.rel_change;
+ ch_event.attr("abs_change") = tg_attr_cfg.event_prop.ch_event.abs_change;
+
+ // Copy archive event properties
+ object arch_event = event_prop.attr("arch_event");
+ arch_event.attr("rel_change") = tg_attr_cfg.event_prop.arch_event.rel_change;
+ arch_event.attr("abs_change") = tg_attr_cfg.event_prop.arch_event.abs_change;
+ arch_event.attr("period") = tg_attr_cfg.event_prop.arch_event.period;
+ arch_event.attr("period") = tg_attr_cfg.event_prop.arch_event.period;
+
+ return attr_cfg;
+ }
};
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_quality_overloads,
@@ -457,5 +562,11 @@ void export_attribute()
.def("is_archive_event", &Tango::Attribute::is_archive_event)
.def("is_check_archive_criteria", &Tango::Attribute::is_check_archive_criteria)
.def("remove_configuration", &Tango::Attribute::remove_configuration)
+
+ .def("_get_properties", &PyAttribute::get_properties)
+ .def("_get_properties_2", &PyAttribute::get_properties_2)
+ .def("_get_properties_3", &PyAttribute::get_properties_3)
+
+
;
}
diff --git a/src/server/attribute.h b/src/server/attribute.h
index de05479..0c2ef3f 100644
--- a/src/server/attribute.h
+++ b/src/server/attribute.h
@@ -27,6 +27,18 @@ namespace PyAttribute
void set_value_date_quality(Tango::Attribute &, boost::python::object &,
double, Tango::AttrQuality , long, long);
+
+ boost::python::object get_properties(Tango::Attribute &,
+ boost::python::object &);
+
+ boost::python::object get_properties_2(Tango::Attribute &,
+ boost::python::object &);
+
+ boost::python::object get_properties_3(Tango::Attribute &,
+ boost::python::object &);
+
+ boost::python::object set_properties(Tango::Attribute &,
+ boost::python::object &);
};
diff --git a/src/server/tango_util.cpp b/src/server/tango_util.cpp
index e35353d..67d80ef 100644
--- a/src/server/tango_util.cpp
+++ b/src/server/tango_util.cpp
@@ -33,21 +33,104 @@
using namespace boost::python;
-/// @todo GET RID OF THIS!! I HATE "HERE_OLD_TANGO___"
-#ifndef WIN32
-//# define HERE_OLD_TANGO___
-#endif
+#define __OLD_TANGO__
+
+#ifdef __OLD_TANGO__
+
+#ifdef _TG_WINDOWS_
-#ifdef HERE_OLD_TANGO___
- void Tango::DServer::class_factory()
- {
- Tango::DServer* dserver = this;
#else
+#include <dlfcn.h>
+#endif /* _TG_WINDOWS_ */
+
+#endif /* __OLD_TANGO__ */
+
namespace PyUtil
{
+
+#ifdef __OLD_TANGO__
+ void create_cpp_class(Tango::DServer *dserver, const char *cl_name,
+ const char *par_name)
+ {
+ std::string class_name(cl_name);
+ std::string lib_name = class_name;
+
+#ifdef _TG_WINDOWS_
+ HMODULE mod;
+
+ if ((mod = LoadLibrary(lib_name.c_str())) == NULL)
+ {
+ char *str = 0;
+
+ DWORD l_err = GetLastError();
+ ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,
+ l_err,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(char *)&str,0,NULL);
+
+ cerr << "Error: " << str << endl;
+
+ TangoSys_OMemStream o;
+ o << "Trying to load shared library " << lib_name << " failed. It returns error: " << str << ends;
+ ::LocalFree((HLOCAL)str);
+
+ Tango::Except::throw_exception("API_ClassNotFound",o.str(),
+ "DServer::create_cpp_class");
+ }
+
+ std::string sym_name("_create_");
+ sym_name = sym_name + class_name;
+ sym_name = sym_name + "_class";
+
+ FARPROC proc;
+
+ if ((proc = GetProcAddress(mod,sym_name.c_str())) == NULL)
+ {
+ TangoSys_OMemStream o;
+ o << "Class " << cl_name << " does not have the C creator function (_create_<Class name>_class)" << ends;
+
+ Tango::Except::throw_exception("API_ClassNotFound",o.str(),
+ "DServer::create_cpp_class");
+ }
+
+ Cpp_creator_ptr mt = (Cpp_creator_ptr)proc;
+#else
+ void *lib_ptr;
+ lib_name = lib_name + ".so";
+
+ lib_ptr = dlopen(lib_name.c_str(),RTLD_NOW);
+ if (lib_ptr == NULL)
+ {
+ TangoSys_OMemStream o;
+ o << "Trying to load shared library " << lib_name << " failed. It returns error: " << dlerror() << ends;
+
+ Tango::Except::throw_exception("API_ClassNotFound",o.str(),
+ "DServer::create_cpp_class");
+ }
+
+ void *sym;
+
+ std::string sym_name("_create_");
+ sym_name = sym_name + class_name;
+ sym_name = sym_name + "_class";
+
+ sym = dlsym(lib_ptr,sym_name.c_str());
+ if (sym == NULL)
+ {
+ TangoSys_OMemStream o;
+ o << "Class " << cl_name << " does not have the C creator function (_create_<Class name>_class)" << ends;
+
+ Tango::Except::throw_exception("API_ClassNotFound",o.str(),
+ "DServer::create_cpp_class");
+ }
+
+ Tango::Cpp_creator_ptr mt = (Tango::Cpp_creator_ptr)sym;
+#endif /* _TG_WINDOWS_ */
+ Tango::DeviceClass *dc = (*mt)(par_name);
+ dserver->_add_class(dc);
+ }
+#endif /* __OLD_TANGO__ */
+
void _class_factory(Tango::DServer* dserver)
{
-#endif
AutoPythonGIL guard;
PYTANGO_MOD
@@ -62,7 +145,11 @@ namespace PyUtil
tuple class_info = extract<tuple>(cpp_class_list[i]);
const char *class_name = extract<const char *>(class_info[0]);
const char *par_name = extract<const char *>(class_info[1]);
+#ifdef __OLD_TANGO__
+ create_cpp_class(dserver, class_name, par_name);
+#else
dserver->_create_cpp_class(class_name, par_name);
+#endif /* __OLD_TANGO__ */
}
//
@@ -82,23 +169,12 @@ namespace PyUtil
}
}
-#ifdef HERE_OLD_TANGO___
-namespace PyUtil
-{
- void server_init(Tango::Util & instance, bool with_window = false)
- {
- AutoPythonAllowThreads guard;
- instance.server_init(with_window);
- }
-#else
void server_init(Tango::Util & instance, bool with_window = false)
{
AutoPythonAllowThreads guard;
Tango::DServer::register_class_factory(_class_factory);
- //instance.set_class_factory_cb(_class_factory);
instance.server_init(with_window);
}
-#endif
void server_run(Tango::Util & instance)
{
--
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