From 92f93b497254ab94be24bb5a01dd58be2deedc13 Mon Sep 17 00:00:00 2001 From: mliszcz Date: Tue, 17 Dec 2019 10:15:37 +0100 Subject: [PATCH 1/3] Remove duplicated push_att_conf_events calls --- cppapi/server/device.cpp | 79 +--------------------------------------- 1 file changed, 1 insertion(+), 78 deletions(-) diff --git a/cppapi/server/device.cpp b/cppapi/server/device.cpp index d0ad011b1..848cf9a9d 100644 --- a/cppapi/server/device.cpp +++ b/cppapi/server/device.cpp @@ -2408,15 +2408,6 @@ void DeviceImpl::set_attribute_config(const Tango::AttributeConfigList &new_conf (const char *) "DeviceImpl::set_attribute_config"); } -// -// Get some event related data -// - - Tango::Util *tg = Tango::Util::instance(); - - EventSupplier *event_supplier_nd = NULL; - EventSupplier *event_supplier_zmq = NULL; - // // Update attribute config first in database, then locally // Finally send attr conf. event @@ -2462,75 +2453,7 @@ void DeviceImpl::set_attribute_config(const Tango::AttributeConfigList &new_conf // Send the event // - if (attr.use_notifd_event() == true) - { - event_supplier_nd = tg->get_notifd_event_supplier(); - } - else - { - event_supplier_nd = NULL; - } - - if (attr.use_zmq_event() == true) - { - event_supplier_zmq = tg->get_zmq_event_supplier(); - } - else - { - event_supplier_zmq = NULL; - } - - if ((event_supplier_nd != NULL) || (event_supplier_zmq != NULL)) - { - std::string tmp_name(new_conf[i].name); - - EventSupplier::SuppliedEventData ad; - ::memset(&ad, 0, sizeof(ad)); - - long vers = get_dev_idl_version(); - if (vers <= 2) - { - Tango::AttributeConfig_2 attr_conf_2; - attr.get_properties(attr_conf_2); - ad.attr_conf_2 = &attr_conf_2; - if (event_supplier_nd != NULL) - { - event_supplier_nd->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name); - } - if (event_supplier_zmq != NULL) - { - event_supplier_zmq->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name); - } - } - else if (vers <= 4) - { - Tango::AttributeConfig_3 attr_conf_3; - attr.get_properties(attr_conf_3); - ad.attr_conf_3 = &attr_conf_3; - if (event_supplier_nd != NULL) - { - event_supplier_nd->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name); - } - if (event_supplier_zmq != NULL) - { - event_supplier_zmq->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name); - } - } - else - { - Tango::AttributeConfig_5 attr_conf_5; - attr.get_properties(attr_conf_5); - ad.attr_conf_5 = &attr_conf_5; - if (event_supplier_nd != NULL) - { - event_supplier_nd->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name); - } - if (event_supplier_zmq != NULL) - { - event_supplier_zmq->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name); - } - } - } + push_att_conf_event(&attr); } } From bad0c604bdabb97b887b2055e30a8ceb79da49dc Mon Sep 17 00:00:00 2001 From: mliszcz Date: Wed, 18 Dec 2019 08:53:29 +0100 Subject: [PATCH 2/3] Test for sending attr conf event after dev restart Add test that verifies if attribute configuration event is sent to all subscribers after device restart (regardless if properties have changed). --- cpp_test_suite/new_tests/cxx_dserver_misc.cpp | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/cpp_test_suite/new_tests/cxx_dserver_misc.cpp b/cpp_test_suite/new_tests/cxx_dserver_misc.cpp index 3cbb353e9..7cfaec42e 100644 --- a/cpp_test_suite/new_tests/cxx_dserver_misc.cpp +++ b/cpp_test_suite/new_tests/cxx_dserver_misc.cpp @@ -6,6 +6,7 @@ #undef SUITE_NAME #define SUITE_NAME DServerMiscTestSuite +template struct EventCallback : public Tango::CallBack { EventCallback() @@ -13,7 +14,7 @@ struct EventCallback : public Tango::CallBack , num_of_error_events(0) {} - void push_event(Tango::EventData* event) + void push_event(TEvent* event) { num_of_all_events++; if (event->err) @@ -229,7 +230,7 @@ cout << "str = " << str << endl; */ void test_event_subscription_recovery_after_device_restart() { - EventCallback callback{}; + EventCallback callback{}; std::string attribute_name = "event_change_tst"; @@ -255,6 +256,37 @@ cout << "str = " << str << endl; TS_ASSERT_EQUALS(0, callback.num_of_error_events); } + /* Tests that attribute configuration change event + * is sent to all subscribers after device restart. + */ + void test_attr_conf_change_event_after_device_restart() + { + EventCallback callback{}; + + const std::string attribute_name = "event_change_tst"; + + int subscription = 0; + TS_ASSERT_THROWS_NOTHING(subscription = device1->subscribe_event( + attribute_name, + Tango::ATTR_CONF_EVENT, + &callback)); + + Tango_sleep(1); + TS_ASSERT_EQUALS(1, callback.num_of_all_events); + TS_ASSERT_EQUALS(0, callback.num_of_error_events); + + { + Tango::DeviceData input{}; + input << device1_name; + TS_ASSERT_THROWS_NOTHING(dserver->command_inout("DevRestart", input)); + } + + Tango_sleep(1); + TS_ASSERT_EQUALS(2, callback.num_of_all_events); + TS_ASSERT_EQUALS(0, callback.num_of_error_events); + + TS_ASSERT_THROWS_NOTHING(device1->unsubscribe_event(subscription)); + } }; #undef cout #endif // DServerMiscTestSuite_h From 773abdbb69e2719e280cfa189632738a0da33297 Mon Sep 17 00:00:00 2001 From: mliszcz Date: Wed, 18 Dec 2019 09:05:02 +0100 Subject: [PATCH 3/3] Push attr conf event to all clients after device restart Attribute properties may have changed during the restart. Push the event to all registered subscribers to ensure that they get updated values. --- cppapi/server/dserver.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cppapi/server/dserver.cpp b/cppapi/server/dserver.cpp index 049684b1c..d12fad183 100644 --- a/cppapi/server/dserver.cpp +++ b/cppapi/server/dserver.cpp @@ -1119,6 +1119,14 @@ void DServer::restart(std::string &d_name) event_supplier_zmq->push_dev_intr_change_event(new_dev,false,cmds_list,atts_list); } } + +// Attribute properties may have changed after the restart. +// Push an attribute configuration event to all registered subscribers. + + for (Attribute* attr : new_dev->get_device_attr()->get_attribute_list()) + { + new_dev->push_att_conf_event(attr); + } } //+-----------------------------------------------------------------------------------------------------------------