1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
|
/*
* SPDX-FileCopyrightText: All Contributors to the PyTango project
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "common_header.h"
#include "pyutils.h"
#include "convertors/type_casters.h"
#include "client/device_attribute.h"
#include "client/callback.h"
namespace PyDeviceProxy {
static inline void pylist_to_devattrs(Tango::DeviceProxy &self,
py::object &py_list,
std::vector<Tango::DeviceAttribute> &dev_attrs) {
unsigned long u_size = len(py_list);
std::vector<py::object> py_values;
py_values.reserve(u_size);
// This will hold the final, complete list of attribute configurations.
std::vector<Tango::AttributeInfoEx> attr_infos(u_size);
// These store the names we need to fetch and their original indices.
std::vector<std::string> attr_names_to_fetch;
std::vector<unsigned long> indices_to_fill;
// 1. First pass: sort items into those we have info for and those we need to fetch.
for(unsigned long n = 0; n < u_size; ++n) {
// Use py::tuple for safer and cleaner element access
py::tuple tup = py_list.attr("__getitem__")(n);
py::object first_item = tup[0];
py_values.push_back(tup[1]); // The value is always the second item
try {
// Try to cast the first item to Tango::AttributeInfoEx.
// If it succeeds, we have the info directly.
attr_infos[n] = first_item.cast<Tango::AttributeInfoEx>();
} catch(const py::cast_error &) {
// If casting fails, assume it's an attribute name (std::string).
// Store the name and the original index `n` for later processing.
attr_names_to_fetch.push_back(first_item.cast<std::string>());
indices_to_fill.push_back(n);
}
}
// 2. If we collected any names, fetch their configuration in a single batch call.
if(!attr_names_to_fetch.empty()) {
std::unique_ptr<Tango::AttributeInfoListEx> fetched_info_list;
{
py::gil_scoped_release no_gil;
fetched_info_list.reset(self.get_attribute_config_ex(attr_names_to_fetch));
}
// 3. With the results, fill the gaps in our main attr_infos vector.
for(size_t i = 0; i < fetched_info_list->size(); ++i) {
unsigned long original_index = indices_to_fill[i];
attr_infos[original_index] = (*fetched_info_list)[i];
}
}
// 4. Now that attr_infos is complete, prepare the final dev_attrs vector.
dev_attrs.resize(u_size);
for(unsigned long n = 0; n < u_size; ++n) {
PyDeviceAttribute::reset(dev_attrs[n], attr_infos[n], py_values[n]);
}
}
static py::object read_attribute(Tango::DeviceProxy &self,
const std::string &attr_name,
PyTango::ExtractAs extract_as) {
// Even if there's an exception in convert_to_python, the
// DeviceAttribute will be deleted there, so we don't need to worry.
Tango::DeviceAttribute *dev_attr = nullptr;
{
py::gil_scoped_release no_gil;
dev_attr = new Tango::DeviceAttribute(self.read_attribute(attr_name.c_str()));
}
return PyDeviceAttribute::convert_to_python(dev_attr, self, extract_as);
}
static inline py::object read_attributes(Tango::DeviceProxy &self,
py::object py_attr_names,
PyTango::ExtractAs extract_as) {
StdStringVector attr_names = py_attr_names.cast<StdStringVector>();
PyDeviceAttribute::AutoDevAttrVector dev_attr_vec;
{
py::gil_scoped_release no_gil;
dev_attr_vec.reset(self.read_attributes(attr_names));
}
return PyDeviceAttribute::convert_to_python(dev_attr_vec, self, extract_as);
}
static inline void write_attribute(Tango::DeviceProxy &self,
const Tango::AttributeInfo &attr_info,
py::object py_value) {
Tango::DeviceAttribute da;
PyDeviceAttribute::reset(da, attr_info, py_value);
py::gil_scoped_release no_gil;
self.write_attribute(da);
}
static inline void write_attribute(Tango::DeviceProxy &self,
const std::string &attr_name,
py::object py_value) {
Tango::DeviceAttribute dev_attr;
PyDeviceAttribute::reset(dev_attr, attr_name, self, py_value);
py::gil_scoped_release no_gil;
self.write_attribute(dev_attr);
}
static inline void write_attributes(Tango::DeviceProxy &self,
py::object py_list) {
std::vector<Tango::DeviceAttribute> dev_attrs;
pylist_to_devattrs(self, py_list, dev_attrs);
py::gil_scoped_release no_gil;
self.write_attributes(dev_attrs);
}
static inline py::object write_read_attribute(Tango::DeviceProxy &self,
const std::string &attr_name,
py::object py_value,
PyTango::ExtractAs extract_as) {
Tango::DeviceAttribute w_dev_attr;
std::unique_ptr<Tango::DeviceAttribute> r_dev_attr;
// Prepare dev_attr structure
PyDeviceAttribute::reset(w_dev_attr, attr_name, self, py_value);
// Do the actual write_read_attribute thing...
{
py::gil_scoped_release no_gil;
Tango::DeviceAttribute da = self.write_read_attribute(w_dev_attr);
r_dev_attr = std::make_unique<Tango::DeviceAttribute>(da);
}
// Convert the result back to python
return PyDeviceAttribute::convert_to_python(r_dev_attr.release(), self, extract_as);
}
static py::object write_read_attributes(Tango::DeviceProxy &self,
py::object py_name_val_list,
py::object py_attr_names,
PyTango::ExtractAs extract_as) {
// Convert write
std::vector<Tango::DeviceAttribute> dev_attrs;
pylist_to_devattrs(self, py_name_val_list, dev_attrs);
// Convert read
StdStringVector attr_names = py_attr_names.cast<StdStringVector>();
PyDeviceAttribute::AutoDevAttrVector dev_attr_vec;
// Do the actual write_read_attributes thing...
{
py::gil_scoped_release no_gil;
dev_attr_vec.reset(self.write_read_attributes(dev_attrs, attr_names));
}
// Convert the result back to python
return PyDeviceAttribute::convert_to_python(dev_attr_vec, self, extract_as);
}
static py::object command_history(Tango::DeviceProxy &self,
const std::string &cmd_name,
int depth) {
std::vector<Tango::DeviceDataHistory> *device_data_hist = nullptr;
py::list ret;
{
py::gil_scoped_release no_gil;
device_data_hist = self.command_history(const_cast<std::string &>(cmd_name), depth);
}
auto it = device_data_hist->begin();
for(; it != device_data_hist->end(); ++it) {
Tango::DeviceDataHistory &hist = *it;
ret.append(hist);
}
delete device_data_hist;
return ret;
}
static inline py::object attribute_history(Tango::DeviceProxy &self,
const std::string &attr_name,
int depth,
PyTango::ExtractAs extract_as) {
std::unique_ptr<std::vector<Tango::DeviceAttributeHistory>> att_hist;
{
py::gil_scoped_release no_gil;
att_hist.reset(self.attribute_history(const_cast<std::string &>(attr_name), depth));
}
return PyDeviceAttribute::convert_to_python(att_hist, self, extract_as);
}
static inline void read_attributes_asynch(Tango::DeviceProxy &self,
py::object py_attr_names,
py::object py_cb,
PyTango::ExtractAs extract_as) {
StdStringVector attr_names = py_attr_names.cast<StdStringVector>();
PyCallBackAutoDie *cb = py_cb.cast<PyCallBackAutoDie *>();
cb->set_extract_as(extract_as);
py::gil_scoped_release no_gil;
try {
self.read_attributes_asynch(attr_names, *cb);
} catch(...) {
cb->delete_me();
throw;
}
}
static inline py::object read_attributes_reply(Tango::DeviceProxy &self,
long id,
PyTango::ExtractAs extract_as) {
PyDeviceAttribute::AutoDevAttrVector dev_attr_vec;
{
py::gil_scoped_release no_gil;
dev_attr_vec.reset(self.read_attributes_reply(id));
}
return PyDeviceAttribute::convert_to_python(dev_attr_vec, self, extract_as);
}
static inline py::object read_attributes_reply(Tango::DeviceProxy &self,
long id,
long timeout,
PyTango::ExtractAs extract_as) {
PyDeviceAttribute::AutoDevAttrVector dev_attr_vec;
{
py::gil_scoped_release no_gil;
dev_attr_vec.reset(self.read_attributes_reply(id, timeout));
}
return PyDeviceAttribute::convert_to_python(dev_attr_vec, self, extract_as);
}
static inline long write_attributes_asynch(Tango::DeviceProxy &self,
py::object py_list) {
std::vector<Tango::DeviceAttribute> dev_attrs;
pylist_to_devattrs(self, py_list, dev_attrs);
py::gil_scoped_release no_gil;
return self.write_attributes_asynch(dev_attrs);
}
static inline void write_attributes_asynch(Tango::DeviceProxy &self,
py::object py_list,
py::object py_cb) {
std::vector<Tango::DeviceAttribute> dev_attrs;
pylist_to_devattrs(self, py_list, dev_attrs);
PyCallBackAutoDie *cb = py_cb.cast<PyCallBackAutoDie *>();
py::gil_scoped_release no_gil;
try {
self.write_attributes_asynch(dev_attrs, *cb);
} catch(...) {
cb->delete_me();
throw;
}
}
static inline void write_attributes_reply(Tango::DeviceProxy &self,
long id,
long timestamp) {
py::gil_scoped_release no_gil;
self.write_attributes_reply(id, timestamp);
}
static inline void write_attributes_reply(Tango::DeviceProxy &self,
long id) {
py::gil_scoped_release no_gil;
self.write_attributes_reply(id);
}
// Overload for the "old" case with stateless flag
static int subscribe_event_global_with_stateless_flag(py::object py_self,
Tango::EventType event,
py::object py_cb,
bool stateless) {
Tango::DeviceProxy &self = py_self.cast<Tango::DeviceProxy &>();
PyEventCallBack *cb = nullptr;
try {
cb = py_cb.cast<PyEventCallBack *>();
} catch(const py::cast_error &) {
Tango::Except::throw_exception("PyDs_CastError",
"Cannot cast callback to PyEventCallBack",
"subscribe_event");
}
{
py::gil_scoped_release no_gil;
return self.subscribe_event(event, cb, stateless);
}
}
// Overload for the "new" case if EventSubMode is specified
static int subscribe_event_global_with_sub_mode(py::object py_self,
Tango::EventType event,
py::object py_cb,
Tango::EventSubMode event_sub_mode) {
Tango::DeviceProxy &self = py_self.cast<Tango::DeviceProxy &>();
PyEventCallBack *cb = nullptr;
try {
cb = py_cb.cast<PyEventCallBack *>();
} catch(const py::cast_error &) {
Tango::Except::throw_exception("PyDs_CastError",
"Cannot cast callback to PyEventCallBack",
"subscribe_event");
}
{
py::gil_scoped_release no_gil;
return self.subscribe_event(event, cb, event_sub_mode);
}
}
// Overload for the "old" case with stateless flag
static int subscribe_event_attrib_with_stateless_flag(py::object py_self,
const std::string &attr_name,
Tango::EventType event,
py::object py_cb_or_queuesize,
bool stateless,
PyTango::ExtractAs extract_as,
py::object &py_filters) {
Tango::DeviceProxy &self = py_self.cast<Tango::DeviceProxy &>();
StdStringVector filters = py_filters.cast<StdStringVector>();
PyEventCallBack *cb = nullptr;
int event_queue_size = 0;
try {
cb = py_cb_or_queuesize.cast<PyEventCallBack *>();
cb->set_extract_as(extract_as);
{
py::gil_scoped_release no_gil;
return self.subscribe_event(attr_name, event, cb, filters, stateless);
}
} catch(const py::cast_error &) {
event_queue_size = py_cb_or_queuesize.cast<int>();
{
py::gil_scoped_release no_gil;
return self.subscribe_event(attr_name, event, event_queue_size, filters, stateless);
}
}
}
// Overload for the "new" case if EventSubMode is specified
static int subscribe_event_attrib_with_sub_mode(py::object py_self,
const std::string &attr_name,
Tango::EventType event,
py::object py_cb_or_queuesize,
Tango::EventSubMode event_sub_mode,
PyTango::ExtractAs extract_as) {
Tango::DeviceProxy &self = py_self.cast<Tango::DeviceProxy &>();
PyEventCallBack *cb = nullptr;
int event_queue_size = 0;
try {
cb = py_cb_or_queuesize.cast<PyEventCallBack *>();
cb->set_extract_as(extract_as);
{
py::gil_scoped_release no_gil;
return self.subscribe_event(attr_name, event, cb, event_sub_mode);
}
} catch(const py::cast_error &) {
event_queue_size = py_cb_or_queuesize.cast<int>();
{
py::gil_scoped_release no_gil;
return self.subscribe_event(attr_name, event, event_queue_size, event_sub_mode);
}
}
}
template <typename ED, typename EDList>
static py::object get_events__aux(py::object py_self,
int event_id,
PyTango::ExtractAs extract_as = PyTango::ExtractAsNumpy) {
Tango::DeviceProxy &self = py_self.cast<Tango::DeviceProxy &>();
EDList event_list;
self.get_events(event_id, event_list);
py::list r;
for(size_t i = 0; i < event_list.size(); ++i) {
ED *event_data = event_list[i];
py::object py_ev = py::cast(event_data, py::return_value_policy::take_ownership);
// EventDataList deletes EventData's on destructor, so once
// we are handling it somewhere else (as an py::object) we must
// unset the reference
event_list[i] = nullptr;
PyEventCallBack::fill_py_event(event_data, py_ev, extract_as);
r.append(py_ev);
}
return r;
}
static void get_events__callback(py::object py_self,
int event_id,
PyEventCallBack *cb,
PyTango::ExtractAs extract_as) {
Tango::DeviceProxy &self = py_self.cast<Tango::DeviceProxy &>();
cb->set_extract_as(extract_as);
self.get_events(event_id, cb);
}
static py::object get_events__attr_conf(py::object py_self,
int event_id) {
return get_events__aux<Tango::AttrConfEventData, Tango::AttrConfEventDataList>(py_self, event_id);
}
static py::object get_events__data(py::object py_self,
int event_id,
PyTango::ExtractAs extract_as) {
return get_events__aux<Tango::EventData, Tango::EventDataList>(py_self, event_id, extract_as);
}
static py::object get_events__data_ready(py::object py_self,
int event_id) {
return get_events__aux<Tango::DataReadyEventData, Tango::DataReadyEventDataList>(py_self, event_id);
}
static py::object get_events__devintr_change_data(py::object py_self,
int event_id,
PyTango::ExtractAs extract_as) {
return get_events__aux<Tango::DevIntrChangeEventData, Tango::DevIntrChangeEventDataList>(py_self, event_id, extract_as);
}
std::shared_ptr<Tango::DeviceProxy> device_proxy_init() {
py::gil_scoped_release no_gil;
return std::shared_ptr<Tango::DeviceProxy>(
new Tango::DeviceProxy(),
DeleterWithoutGIL());
}
std::shared_ptr<Tango::DeviceProxy> device_proxy_init(const std::string &name) {
py::gil_scoped_release no_gil;
return std::shared_ptr<Tango::DeviceProxy>(
new Tango::DeviceProxy(name.c_str()),
DeleterWithoutGIL());
}
std::shared_ptr<Tango::DeviceProxy> device_proxy_init(const std::string &name, bool ch_acc) {
py::gil_scoped_release no_gil;
return std::shared_ptr<Tango::DeviceProxy>(
new Tango::DeviceProxy(name.c_str(), ch_acc),
DeleterWithoutGIL());
}
std::shared_ptr<Tango::DeviceProxy> device_proxy_init(const Tango::DeviceProxy &device) {
py::gil_scoped_release no_gil;
return std::shared_ptr<Tango::DeviceProxy>(
new Tango::DeviceProxy(device),
DeleterWithoutGIL());
}
} // namespace PyDeviceProxy
void export_device_proxy(py::module &m) {
py::class_<Tango::DeviceProxy,
std::shared_ptr<Tango::DeviceProxy>,
Tango::Connection>(m,
"DeviceProxy",
py::dynamic_attr(),
R"doc(
DeviceProxy is the high level Tango object which provides the client with
an easy-to-use interface to TANGO devices. DeviceProxy provides interfaces
to all TANGO Device interfaces.The DeviceProxy manages timeouts, stateless
connections and reconnection if the device server is restarted. To create
a DeviceProxy, a Tango Device name must be set in the object constructor.
Example :
dev = tango.DeviceProxy("sys/tg_test/1")
DeviceProxy(dev_name, green_mode=None, wait=True, timeout=True) -> DeviceProxy
DeviceProxy(self, dev_name, need_check_acc, green_mode=None, wait=True, timeout=True) -> DeviceProxy
Creates a new :class:`~tango.DeviceProxy`.
:param dev_name: the device name or alias
:type dev_name: str
:param need_check_acc: in first version of the function it defaults to True.
Determines if at creation time of DeviceProxy it should check
for channel access (rarely used)
:type need_check_acc: bool
:param green_mode: determines the mode of execution of the device (including.
the way it is created). Defaults to the current global
green_mode (check :func:`~tango.get_green_mode` and
:func:`~tango.set_green_mode`)
:type green_mode: :obj:`~tango.GreenMode`
:param wait: whether or not to wait for result. If green_mode
Ignored when green_mode is Synchronous (always waits).
:type wait: bool
:param timeout: The number of seconds to wait for the result.
If None, then there is no limit on the wait time.
Ignored when green_mode is Synchronous or wait is False.
:type timeout: float
:returns:
if green_mode is Synchronous or wait is True:
:class:`~tango.DeviceProxy`
elif green_mode is Futures:
:class:`concurrent.futures.Future`
elif green_mode is Gevent:
:class:`gevent.event.AsynchResult`
elif green_mode is Asyncio:
:class:`asyncio.Future`
:throws:
* :class:`~tango.DevFailed` if green_mode is Synchronous or wait is True
and there is an error creating the device.
* :class:`concurrent.futures.TimeoutError` if green_mode is Futures,
wait is False, timeout is not None and the time to create the device
has expired.
* :class:`gevent.timeout.Timeout` if green_mode is Gevent, wait is False,
timeout is not None and the time to create the device has expired.
* :class:`asyncio.TimeoutError`` if green_mode is Asyncio,
wait is False, timeout is not None and the time to create the device
has expired.
.. versionadded:: 8.1.0
*green_mode* parameter.
*wait* parameter.
*timeout* parameter.
)doc")
.def(py::init([]() {
return PyDeviceProxy::device_proxy_init();
}))
.def(py::init([](const std::string &name) {
return PyDeviceProxy::device_proxy_init(name);
}),
py::arg("name"))
.def(py::init([](const std::string &name, bool ch_acc) {
return PyDeviceProxy::device_proxy_init(name, ch_acc);
}),
py::arg("name"),
py::arg("ch_acc"))
.def(py::init([](const Tango::DeviceProxy &device) {
return PyDeviceProxy::device_proxy_init(device);
}),
py::arg("device"))
.def(py::pickle(
[](Tango::DeviceProxy &self) { // __getstate__
std::string ret = self.get_db_host() + ":" + self.get_db_port() + "/" + self.dev_name();
return py::make_tuple(ret);
},
[](py::tuple py_tuple) { // __setstate__
if(py_tuple.size() != 1) {
throw std::runtime_error("Invalid state!");
}
std::string trl = py_tuple[0].cast<std::string>();
return Tango::DeviceProxy(trl.c_str());
}))
//
// general methods
//
.def("dev_name", &Tango::DeviceProxy::dev_name)
.def("info",
&Tango::DeviceProxy::info,
py::return_value_policy::reference_internal,
py::call_guard<py::gil_scoped_release>(),
R"doc(
info(self) -> DeviceInfo
A method which returns information on the device
Parameters : None
Return : (DeviceInfo) object
Example :
dev_info = dev.info()
print(dev_info.dev_class)
print(dev_info.server_id)
print(dev_info.server_host)
print(dev_info.server_version)
print(dev_info.doc_url)
print(dev_info.dev_type)
print(dev_info.version_info))doc")
.def("get_device_db",
&Tango::DeviceProxy::get_device_db,
py::return_value_policy::reference,
R"doc(
get_device_db(self) -> Database
Returns the internal database reference
Parameters : None
Return : (Database) object
New in PyTango 7.0.0)doc")
.def("_status", &Tango::DeviceProxy::status, py::return_value_policy::reference_internal, py::call_guard<py::gil_scoped_release>())
.def("_state", &Tango::DeviceProxy::state, py::call_guard<py::gil_scoped_release>())
.def("adm_name",
&Tango::DeviceProxy::adm_name,
py::call_guard<py::gil_scoped_release>(),
R"doc(
adm_name(self) -> str
Return the name of the corresponding administrator device. This is
useful if you need to send an administration command to the device
server, e.g restart it
New in PyTango 3.0.4)doc")
.def("description",
&Tango::DeviceProxy::description,
py::call_guard<py::gil_scoped_release>(),
R"doc(
description(self) -> str
Get device description.
Parameters : None
Return : (str) describing the device)doc")
.def("name",
&Tango::DeviceProxy::name,
py::call_guard<py::gil_scoped_release>(),
R"doc(
name(self) -> str
Return the device name from the device itself.
Return: (str) device name)doc")
.def("alias",
&Tango::DeviceProxy::alias,
py::call_guard<py::gil_scoped_release>(),
R"doc(
alias(self) -> str
Return the device alias if one is defined.
Otherwise, throws exception.
Return: (str) device alias)doc")
.def("get_tango_lib_version",
&Tango::DeviceProxy::get_tango_lib_version,
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_tango_lib_version(self) -> int
Returns the Tango lib version number used by the remote device
Otherwise, throws exception.
Return : (int) The device Tango lib version as a 3 or 4 digits number.
Possible return value are: 100,200,500,520,700,800,810,...
New in PyTango 8.1.0)doc")
.def("_ping", &Tango::DeviceProxy::ping, py::call_guard<py::gil_scoped_release>())
.def("black_box",
&Tango::DeviceProxy::black_box,
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>(),
R"doc(
black_box(self, n) -> sequence<str>
Get the last commands executed on the device server
Parameters :
- n : n number of commands to get
Return : (sequence<str>) sequence of strings containing the date, time,
command and from which client computer the command
was executed
Example :
print(black_box(4)))doc",
py::arg("n"))
//
// command methods
//
.def("get_command_list",
&Tango::DeviceProxy::get_command_list,
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_command_list(self) -> sequence<str>
Return the names of all commands implemented for this device.
Parameters : None
Return : sequence<str>
Throws : ConnectionFailed, CommunicationFailed,
DevFailed from device)doc")
.def("_get_command_config",
py::overload_cast<StdStringVector &>(&Tango::DeviceProxy::get_command_config),
py::arg("attr_names"),
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>())
.def("_get_command_config",
py::overload_cast<const std::string &>(&Tango::DeviceProxy::get_command_config),
py::arg("attr_name"),
py::call_guard<py::gil_scoped_release>())
.def("command_query",
&Tango::DeviceProxy::command_query,
py::call_guard<py::gil_scoped_release>(),
R"doc(
command_query(self, command) -> CommandInfo
Query the device for information about a single command.
Parameters :
- command : (str) command name
Return : (CommandInfo) object
Throws : ConnectionFailed, CommunicationFailed, DevFailed from device
Example :
com_info = dev.command_query("DevString")
print(com_info.cmd_name)
print(com_info.cmd_tag)
print(com_info.in_type)
print(com_info.out_type)
print(com_info.in_type_desc)
print(com_info.out_type_desc)
print(com_info.disp_level)
See CommandInfo documentation string form more detail)doc",
py::arg("command"))
.def("command_list_query",
&Tango::DeviceProxy::command_list_query,
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>(),
R"doc(
command_list_query(self) -> sequence<CommandInfo>
Query the device for information on all commands.
Parameters : None
Return : (CommandInfoList) Sequence of CommandInfo objects)doc")
.def("import_info",
&Tango::DeviceProxy::import_info,
py::call_guard<py::gil_scoped_release>(),
R"doc(
import_info(self) -> DbDevImportInfo
Query the device for import info from the database.
Parameters : None
Return : (DbDevImportInfo)
Example :
dev_import = dev.import_info()
print(dev_import.name)
print(dev_import.exported)
print(dev_ior.ior)
print(dev_version.version)
All DbDevImportInfo fields are strings except for exported which
is an integer")doc")
//
// property methods
//
.def("_get_property",
py::overload_cast<const std::string &, Tango::DbData &>(&Tango::DeviceProxy::get_property),
py::arg("propname"),
py::arg("propdata"),
py::call_guard<py::gil_scoped_release>())
.def("_get_property",
py::overload_cast<const std::vector<std::string> &, Tango::DbData &>(&Tango::DeviceProxy::get_property),
py::arg("propnames"),
py::arg("propdata"),
py::call_guard<py::gil_scoped_release>())
.def("_get_property",
py::overload_cast<Tango::DbData &>(&Tango::DeviceProxy::get_property),
py::arg("propdata"),
py::call_guard<py::gil_scoped_release>())
.def("_put_property",
&Tango::DeviceProxy::put_property,
py::arg("propdata"),
py::call_guard<py::gil_scoped_release>())
.def("_delete_property",
py::overload_cast<const Tango::DbData &>(&Tango::DeviceProxy::delete_property),
py::arg("propname"),
py::call_guard<py::gil_scoped_release>())
.def("_get_property_list",
&Tango::DeviceProxy::get_property_list,
py::arg("filter"),
py::arg("array"),
py::call_guard<py::gil_scoped_release>())
//
// attribute methods
//
.def("get_attribute_list",
&Tango::DeviceProxy::get_attribute_list,
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_attribute_list(self) -> sequence<str>
Return the names of all attributes implemented for this device.
Parameters : None
Return : sequence<str>
Throws : ConnectionFailed, CommunicationFailed,
DevFailed from device)doc")
.def("_get_attribute_config",
py::overload_cast<const StdStringVector &>(&Tango::DeviceProxy::get_attribute_config),
py::arg("attr_names"),
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>())
.def("_get_attribute_config",
py::overload_cast<const std::string &>(&Tango::DeviceProxy::get_attribute_config),
py::arg("attr_name"),
py::call_guard<py::gil_scoped_release>())
.def("_get_attribute_config_ex",
&Tango::DeviceProxy::get_attribute_config_ex,
py::arg("attr_names"),
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>())
.def("attribute_query",
&Tango::DeviceProxy::attribute_query,
py::call_guard<py::gil_scoped_release>(),
R"doc(
attribute_query(self, attr_name) -> AttributeInfoEx
Query the device for information about a single attribute.
Parameters :
- attr_name :(str) the attribute name
Return : (AttributeInfoEx) containing the attribute
configuration
Throws : ConnectionFailed, CommunicationFailed,
DevFailed from device)doc",
py::arg("attr_name"))
.def("attribute_list_query",
&Tango::DeviceProxy::attribute_list_query,
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>(),
R"doc(
attribute_list_query(self) -> sequence<AttributeInfo>
Query the device for info on all attributes. This method returns
a sequence of tango.AttributeInfo.
Parameters : None
Return : (sequence<AttributeInfo>) containing the
attributes configuration
Throws : ConnectionFailed, CommunicationFailed,
DevFailed from device)doc")
.def("attribute_list_query_ex",
&Tango::DeviceProxy::attribute_list_query_ex,
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>(),
R"doc(
attribute_list_query_ex(self) -> sequence<AttributeInfoEx>
Query the device for info on all attributes. This method returns
a sequence of tango.AttributeInfoEx.
Parameters : None
Return : (sequence<AttributeInfoEx>) containing the
attributes configuration
Throws : ConnectionFailed, CommunicationFailed,
DevFailed from device)doc")
.def("_set_attribute_config",
py::overload_cast<const Tango::AttributeInfoList &>(&Tango::DeviceProxy::set_attribute_config),
py::call_guard<py::gil_scoped_release>(),
py::arg("seq"))
.def("_set_attribute_config",
py::overload_cast<const Tango::AttributeInfoListEx &>(&Tango::DeviceProxy::set_attribute_config),
py::call_guard<py::gil_scoped_release>(),
py::arg("seq"))
.def("_read_attribute",
&PyDeviceProxy::read_attribute,
py::arg("attr_name"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("_read_attributes",
&PyDeviceProxy::read_attributes,
py::arg("attr_names"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("_write_attribute",
py::overload_cast<Tango::DeviceProxy &, const std::string &, py::object>(&PyDeviceProxy::write_attribute),
py::arg("attr_name"),
py::arg("value"))
.def("_write_attribute",
py::overload_cast<Tango::DeviceProxy &, const Tango::AttributeInfo &, py::object>(&PyDeviceProxy::write_attribute),
py::arg("attr_info"),
py::arg("value"))
.def("_write_attributes", &PyDeviceProxy::write_attributes, py::arg("name_val"))
.def("_write_read_attribute",
&PyDeviceProxy::write_read_attribute,
py::arg("attr_name"),
py::arg("value"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("_write_read_attributes",
&PyDeviceProxy::write_read_attributes,
py::arg("attr_in"),
py::arg("attr_read_names"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
//
// history methods
//
.def("command_history",
&PyDeviceProxy::command_history,
R"doc(
command_history(self, cmd_name, depth) -> sequence<DeviceDataHistory>
Retrieve command history from the command polling buffer. See
chapter on Advanced Feature for all details regarding polling
Parameters :
- cmd_name : (str) Command name.
- depth : (int) The wanted history depth.
Return : This method returns a vector of DeviceDataHistory types.
Throws : NonSupportedFeature, ConnectionFailed,
CommunicationFailed, DevFailed from device)doc",
py::arg("cmd_name"),
py::arg("depth"))
.def("attribute_history",
&PyDeviceProxy::attribute_history,
R"doc(
attribute_history(self, attr_name, depth, extract_as=ExtractAs.Numpy) -> sequence<DeviceAttributeHistory>
Retrieve attribute history from the attribute polling buffer. See
chapter on Advanced Feature for all details regarding polling
Parameters :
- attr_name : (str) Attribute name.
- depth : (int) The wanted history depth.
- extract_as : (ExtractAs)
Return : This method returns a vector of DeviceAttributeHistory types.
Throws : NonSupportedFeature, ConnectionFailed,
CommunicationFailed, DevFailed from device)doc",
py::arg("attr_name"),
py::arg("depth"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
//
// Polling administration methods
//
.def("polling_status",
&Tango::DeviceProxy::polling_status,
py::return_value_policy::take_ownership,
py::call_guard<py::gil_scoped_release>(),
R"doc(
polling_status(self) -> sequence<str>
Return the device polling status.
Parameters : None
Return : (sequence<str>) One string for each polled command/attribute.
Each string is multi-line string with:
- attribute/command name
- attribute/command polling period in milliseconds
- attribute/command polling ring buffer
- time needed for last attribute/command execution in milliseconds
- time since data in the ring buffer has not been updated
- delta time between the last records in the ring buffer
- exception parameters in case of the last execution failed)doc")
.def("poll_command",
py::overload_cast<const char *, int>(&Tango::DeviceProxy::poll_command),
py::call_guard<py::gil_scoped_release>(),
R"doc(
poll_command(self, cmd_name, period) -> None
Add a command to the list of polled commands.
Parameters :
- cmd_name : (str) command name
- period : (int) polling period in milliseconds
Return : None)doc",
py::arg("cmd_name"),
py::arg("period"))
.def("poll_attribute",
py::overload_cast<const char *, int>(&Tango::DeviceProxy::poll_attribute),
py::call_guard<py::gil_scoped_release>(),
R"doc(
poll_attribute(self, attr_name, period) -> None
Add an attribute to the list of polled attributes.
Parameters :
- attr_name : (str) attribute name
- period : (int) polling period in milliseconds
Return : None)doc",
py::arg("attr_name"),
py::arg("period"))
.def("get_command_poll_period",
py::overload_cast<const char *>(&Tango::DeviceProxy::get_command_poll_period),
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_command_poll_period(self, cmd_name) -> int
Return the command polling period.
Parameters :
- cmd_name : (str) command name
Return : polling period in milliseconds)doc",
py::arg("cmd_name"))
.def("get_attribute_poll_period",
py::overload_cast<const char *>(&Tango::DeviceProxy::get_attribute_poll_period),
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_attribute_poll_period(self, attr_name) -> int
Return the attribute polling period.
Parameters :
- attr_name : (str) attribute name
Return : polling period in milliseconds)doc",
py::arg("attr_name"))
.def("is_command_polled",
py::overload_cast<const char *>(&Tango::DeviceProxy::is_command_polled),
py::call_guard<py::gil_scoped_release>(),
R"doc(
is_command_polled(self, cmd_name) -> bool
True if the command is polled.
:param str cmd_name: command name
:returns: boolean value
:rtype: bool)doc",
py::arg("cmd_name"))
.def("is_attribute_polled",
py::overload_cast<const char *>(&Tango::DeviceProxy::is_attribute_polled),
py::call_guard<py::gil_scoped_release>(),
R"doc(
is_attribute_polled(self, attr_name) -> bool
True if the attribute is polled.
:param str attr_name: attribute name
:returns: boolean value
:rtype: bool)doc",
py::arg("attr_name"))
.def("stop_poll_command",
py::overload_cast<const char *>(&Tango::DeviceProxy::stop_poll_command),
py::call_guard<py::gil_scoped_release>(),
R"doc(
stop_poll_command(self, cmd_name) -> None
Remove a command from the list of polled commands.
Parameters :
- cmd_name : (str) command name
Return : None)doc",
py::arg("cmd_name"))
.def("stop_poll_attribute",
py::overload_cast<const char *>(&Tango::DeviceProxy::stop_poll_attribute),
py::call_guard<py::gil_scoped_release>(),
R"doc(
stop_poll_attribute(self, attr_name) -> None
Remove an attribute from the list of polled attributes.
Parameters :
- attr_name : (str) attribute name
Return : None)doc",
py::arg("attr_name"))
//
// Asynchronous methods
//
.def("__read_attributes_asynch",
py::overload_cast<const StdStringVector &>(&Tango::DeviceProxy::read_attributes_asynch),
py::call_guard<py::gil_scoped_release>())
.def("__read_attributes_asynch",
py::overload_cast<Tango::DeviceProxy &, py::object, py::object, PyTango::ExtractAs>(&PyDeviceProxy::read_attributes_asynch),
py::arg("attr_names"),
py::arg("callback"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("__read_attributes_reply",
py::overload_cast<Tango::DeviceProxy &, long, PyTango::ExtractAs>(&PyDeviceProxy::read_attributes_reply),
py::arg("id"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("__read_attributes_reply",
py::overload_cast<Tango::DeviceProxy &, long, long, PyTango::ExtractAs>(&PyDeviceProxy::read_attributes_reply),
py::arg("id"),
py::arg("timeout"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("pending_asynch_call",
&Tango::DeviceProxy::pending_asynch_call,
R"doc(
pending_asynch_call(self) -> int
Return number of device asynchronous pending requests"
New in PyTango 7.0.0)doc")
.def("__write_attributes_asynch",
py::overload_cast<Tango::DeviceProxy &, py::object>(&PyDeviceProxy::write_attributes_asynch),
py::arg("values"))
.def("__write_attributes_asynch",
py::overload_cast<Tango::DeviceProxy &, py::object, py::object>(&PyDeviceProxy::write_attributes_asynch),
py::arg("values"),
py::arg("callback"))
.def("__write_attributes_reply",
py::overload_cast<Tango::DeviceProxy &, long>(&PyDeviceProxy::write_attributes_reply),
py::arg("id"))
.def("__write_attributes_reply",
py::overload_cast<Tango::DeviceProxy &, long, long>(&PyDeviceProxy::write_attributes_reply),
py::arg("id"),
py::arg("timeout"))
//
// Logging administration methods
//
.def("add_logging_target",
py::overload_cast<const std::string &>(&Tango::DeviceProxy::add_logging_target),
py::call_guard<py::gil_scoped_release>(),
R"doc(
add_logging_target(self, target_type_target_name) -> None
Adds a new logging target to the device.
The target_type_target_name input parameter must follow the
format: target_type::target_name. Supported target types are:
console, file and device. For a device target, the target_name
part of the target_type_target_name parameter must contain the
name of a log consumer device (as defined in A.8). For a file
target, target_name is the full path to the file to log to. If
omitted, the device's name is used to build the file name
(which is something like domain_family_member.log). Finally, the
target_name part of the target_type_target_name input parameter
is ignored in case of a console target and can be omitted.
Parameters :
- target_type_target_name : (str) logging target
Return : None
Throws : DevFailed from device
New in PyTango 7.0.0)doc",
py::arg("target_type_target_name"))
.def("remove_logging_target",
py::overload_cast<const std::string &>(&Tango::DeviceProxy::remove_logging_target),
py::call_guard<py::gil_scoped_release>(),
R"doc(
remove_logging_target(self, target_type_target_name) -> None
Removes a logging target from the device's target list.
The target_type_target_name input parameter must follow the
format: target_type::target_name. Supported target types are:
console, file and device. For a device target, the target_name
part of the target_type_target_name parameter must contain the
name of a log consumer device (as defined in ). For a file
target, target_name is the full path to the file to remove.
If omitted, the default log file is removed. Finally, the
target_name part of the target_type_target_name input parameter
is ignored in case of a console target and can be omitted.
If target_name is set to '*', all targets of the specified
target_type are removed.
Parameters :
- target_type_target_name : (str) logging target
Return : None
New in PyTango 7.0.0)doc",
py::arg("target_type_target_name"))
.def("get_logging_target",
&Tango::DeviceProxy::get_logging_target,
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_logging_target(self) -> sequence<str>
Returns a sequence of string containing the current device's
logging targets. Each vector element has the following format:
target_type::target_name. An empty sequence is returned is the
device has no logging targets.
Parameters : None
Return : a sequence<str> with the logging targets
New in PyTango 7.0.0)doc")
.def("get_logging_level",
&Tango::DeviceProxy::get_logging_level,
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_logging_level(self) -> int
Returns the current device's logging level, where:
- 0=OFF
- 1=FATAL
- 2=ERROR
- 3=WARNING
- 4=INFO
- 5=DEBUG
Parameters :None
Return : (int) representing the current logging level
New in PyTango 7.0.0)doc")
.def("set_logging_level",
&Tango::DeviceProxy::set_logging_level,
py::call_guard<py::gil_scoped_release>(),
R"doc(
set_logging_level(self, level) -> None
Changes the device's logging level, where:
- 0=OFF
- 1=FATAL
- 2=ERROR
- 3=WARNING
- 4=INFO
- 5=DEBUG
Parameters :
- level : (int) logging level
Return : None
New in PyTango 7.0.0)doc",
py::arg("level"))
//
// Event methods
//
.def("__subscribe_event_global_with_stateless_flag",
&PyDeviceProxy::subscribe_event_global_with_stateless_flag,
py::arg("event"),
py::arg("cb"),
py::arg("stateless"))
.def("__subscribe_event_global_with_sub_mode",
&PyDeviceProxy::subscribe_event_global_with_sub_mode,
py::arg("event"),
py::arg("cb"),
py::arg("event_sub_mode"))
.def("__subscribe_event_attrib_with_stateless_flag",
&PyDeviceProxy::subscribe_event_attrib_with_stateless_flag,
py::arg("attr_name"),
py::arg("event"),
py::arg("cb_or_queuesize"),
py::arg("stateless"),
py::arg("extract_as"),
py::arg("filters"))
.def("__subscribe_event_attrib_with_sub_mode",
&PyDeviceProxy::subscribe_event_attrib_with_sub_mode,
py::arg("attr_name"),
py::arg("event"),
py::arg("cb_or_queuesize"),
py::arg("event_sub_mode"),
py::arg("extract_as"))
// If the callback is running, unsubscribe_event will lock
// until it finishes. So we MUST release GIL to avoid a deadlock
.def("__unsubscribe_event",
&Tango::DeviceProxy::unsubscribe_event,
py::call_guard<py::gil_scoped_release>(),
py::arg("event_id"))
.def("__get_callback_events",
PyDeviceProxy::get_events__callback,
py::arg("event_id"),
py::arg("callback"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("__get_attr_conf_events",
PyDeviceProxy::get_events__attr_conf,
py::arg("event_id"))
.def("__get_data_events",
PyDeviceProxy::get_events__data,
py::arg("event_id"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
.def("__get_data_ready_events",
PyDeviceProxy::get_events__data_ready,
py::arg("event_id"))
.def("__get_devintr_change_events",
PyDeviceProxy::get_events__devintr_change_data,
py::arg("event_id"),
py::arg_v("extract_as", PyTango::ExtractAsNumpy, "ExtractAs.Numpy"))
// methods to access data in event queues
.def("event_queue_size",
&Tango::DeviceProxy::event_queue_size,
R"doc(
event_queue_size(self, event_id) -> int
Returns the number of stored events in the event reception
buffer. After every call to DeviceProxy.get_events(), the event
queue size is 0. During event subscription the client must have
chosen the 'pull model' for this event. event_id is the event
identifier returned by the DeviceProxy.subscribe_event() method.
Parameters :
- event_id : (int) event identifier
Return : an integer with the queue size
Throws : EventSystemFailed
New in PyTango 7.0.0)doc",
py::arg("event_id"))
.def("get_last_event_date",
&Tango::DeviceProxy::get_last_event_date,
R"doc(
get_last_event_date(self, event_id) -> TimeVal
Returns the arrival time of the last event stored in the event
reception buffer. After every call to DeviceProxy:get_events(),
the event reception buffer is empty. In this case an exception
will be returned. During event subscription the client must have
chosen the 'pull model' for this event. event_id is the event
identifier returned by the DeviceProxy.subscribe_event() method.
Parameters :
- event_id : (int) event identifier
Return : (tango.TimeVal) representing the arrival time
Throws : EventSystemFailed
New in PyTango 7.0.0)doc",
py::arg("event_id"))
.def("is_event_queue_empty",
&Tango::DeviceProxy::is_event_queue_empty,
R"doc(
is_event_queue_empty(self, event_id) -> bool
Returns true when the event reception buffer is empty. During
event subscription the client must have chosen the 'pull model'
for this event. event_id is the event identifier returned by the
DeviceProxy.subscribe_event() method.
Parameters :
- event_id : (int) event identifier
Return : (bool) True if queue is empty or False otherwise
Throws : EventSystemFailed
New in PyTango 7.0.0)doc",
py::arg("event_id"))
//
// Locking methods
//
.def("lock",
&Tango::DeviceProxy::lock,
py::call_guard<py::gil_scoped_release>(),
R"doc(
lock(self, (int)lock_validity) -> None
Lock a device. The lock_validity is the time (in seconds) the
lock is kept valid after the previous lock call. A default value
of 10 seconds is provided and should be fine in most cases. In
case it is necessary to change the lock validity, it's not
possible to ask for a validity less than a minimum value set to
2 seconds. The library provided an automatic system to
periodically re lock the device until an unlock call. No code is
needed to start/stop this automatic re-locking system. The
locking system is re-entrant. It is then allowed to call this
method on a device already locked by the same process. The
locking system has the following features:
* It is impossible to lock the database device or any device
server process admin device
* Destroying a locked DeviceProxy unlocks the device
* Restarting a locked device keeps the lock
* It is impossible to restart a device locked by someone else
* Restarting a server breaks the lock
A locked device is protected against the following calls when
executed by another client:
* command_inout call except for device state and status
requested via command and for the set of commands defined as
allowed following the definition of allowed command in the
Tango control access schema.
* write_attribute call
* write_read_attribute call
* set_attribute_config call
Parameters :
- lock_validity : (int) lock validity time in seconds
(optional, default value is
tango.constants.DEFAULT_LOCK_VALIDITY)
Return : None
New in PyTango 7.0.0)doc",
py::arg("lock_validity") = Tango::DEFAULT_LOCK_VALIDITY)
.def("unlock",
&Tango::DeviceProxy::unlock,
py::call_guard<py::gil_scoped_release>(),
R"doc(
unlock(self, (bool)force) -> None
Unlock a device. If used, the method argument provides a back
door on the locking system. If this argument is set to true,
the device will be unlocked even if the caller is not the locker.
This feature is provided for administration purpose and should
be used very carefully. If this feature is used, the locker will
receive a DeviceUnlocked during the next call which is normally
protected by the locking Tango system.
Parameters :
- force : (bool) force unlocking even if we are not the
locker (optional, default value is False)
Return : None
New in PyTango 7.0.0)doc",
py::arg("force") = false)
.def("locking_status",
&Tango::DeviceProxy::locking_status,
py::call_guard<py::gil_scoped_release>(),
R"doc(
locking_status(self) -> str
This method returns a plain string describing the device locking
status. This string can be:
* 'Device <device name> is not locked' in case the device is
not locked
* 'Device <device name> is locked by CPP or Python client with
PID <pid> from host <host name>' in case the device is
locked by a CPP client
* 'Device <device name> is locked by JAVA client class
<main class> from host <host name>' in case the device is
locked by a JAVA client
Parameters : None
Return : a string representing the current locking status
New in PyTango 7.0.0)doc")
.def("is_locked",
&Tango::DeviceProxy::is_locked,
py::call_guard<py::gil_scoped_release>(),
R"doc(
is_locked(self) -> bool
Returns True if the device is locked. Otherwise, returns False.
Parameters : None
Return : (bool) True if the device is locked. Otherwise, False
New in PyTango 7.0.0)doc")
.def("is_locked_by_me",
&Tango::DeviceProxy::is_locked_by_me,
py::call_guard<py::gil_scoped_release>(),
R"doc(
is_locked_by_me(self) -> bool
Returns True if the device is locked by the caller. Otherwise,
returns False (device not locked or locked by someone else)
Parameters : None
Return : (bool) True if the device is locked by us.
Otherwise, False
New in PyTango 7.0.0)doc")
.def("get_locker",
&Tango::DeviceProxy::get_locker,
py::call_guard<py::gil_scoped_release>(),
R"doc(
get_locker(self, lockinfo) -> bool
If the device is locked, this method returns True an set some
locker process informations in the structure passed as argument.
If the device is not locked, the method returns False.
Parameters :
- lockinfo [out] : (tango.LockInfo) object that will be filled
with lock information
Return : (bool) True if the device is locked by us.
Otherwise, False
New in PyTango 7.0.0)doc",
py::arg("lockinfo"));
fix_dynamic_attr_dealloc<Tango::DeviceProxy>();
}
|