Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions cpp_test_suite/new_tests/cxx_dserver_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#undef SUITE_NAME
#define SUITE_NAME DServerMiscTestSuite

template <typename TEvent>
struct EventCallback : public Tango::CallBack
{
EventCallback()
: num_of_all_events(0)
, num_of_error_events(0)
{}

void push_event(Tango::EventData* event)
void push_event(TEvent* event)
{
num_of_all_events++;
if (event->err)
Expand Down Expand Up @@ -229,7 +230,7 @@ cout << "str = " << str << endl;
*/
void test_event_subscription_recovery_after_device_restart()
{
EventCallback callback{};
EventCallback<Tango::EventData> callback{};

std::string attribute_name = "event_change_tst";

Expand All @@ -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<Tango::AttrConfEventData> 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
79 changes: 1 addition & 78 deletions cppapi/server/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

}
Expand Down
8 changes: 8 additions & 0 deletions cppapi/server/dserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

//+-----------------------------------------------------------------------------------------------------------------
Expand Down