Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit 8fd3b4d

Browse files
authored
Merge pull request #694 from mliszcz/fix-361-missing-attr_conf-after-reset
Send attribute configuration event to all clients after device restart
2 parents 6fa50bb + 773abdb commit 8fd3b4d

File tree

3 files changed

+43
-80
lines changed

3 files changed

+43
-80
lines changed

cpp_test_suite/new_tests/cxx_dserver_misc.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
#undef SUITE_NAME
77
#define SUITE_NAME DServerMiscTestSuite
88

9+
template <typename TEvent>
910
struct EventCallback : public Tango::CallBack
1011
{
1112
EventCallback()
1213
: num_of_all_events(0)
1314
, num_of_error_events(0)
1415
{}
1516

16-
void push_event(Tango::EventData* event)
17+
void push_event(TEvent* event)
1718
{
1819
num_of_all_events++;
1920
if (event->err)
@@ -229,7 +230,7 @@ cout << "str = " << str << endl;
229230
*/
230231
void test_event_subscription_recovery_after_device_restart()
231232
{
232-
EventCallback callback{};
233+
EventCallback<Tango::EventData> callback{};
233234

234235
std::string attribute_name = "event_change_tst";
235236

@@ -255,6 +256,37 @@ cout << "str = " << str << endl;
255256
TS_ASSERT_EQUALS(0, callback.num_of_error_events);
256257
}
257258

259+
/* Tests that attribute configuration change event
260+
* is sent to all subscribers after device restart.
261+
*/
262+
void test_attr_conf_change_event_after_device_restart()
263+
{
264+
EventCallback<Tango::AttrConfEventData> callback{};
265+
266+
const std::string attribute_name = "event_change_tst";
267+
268+
int subscription = 0;
269+
TS_ASSERT_THROWS_NOTHING(subscription = device1->subscribe_event(
270+
attribute_name,
271+
Tango::ATTR_CONF_EVENT,
272+
&callback));
273+
274+
Tango_sleep(1);
275+
TS_ASSERT_EQUALS(1, callback.num_of_all_events);
276+
TS_ASSERT_EQUALS(0, callback.num_of_error_events);
277+
278+
{
279+
Tango::DeviceData input{};
280+
input << device1_name;
281+
TS_ASSERT_THROWS_NOTHING(dserver->command_inout("DevRestart", input));
282+
}
283+
284+
Tango_sleep(1);
285+
TS_ASSERT_EQUALS(2, callback.num_of_all_events);
286+
TS_ASSERT_EQUALS(0, callback.num_of_error_events);
287+
288+
TS_ASSERT_THROWS_NOTHING(device1->unsubscribe_event(subscription));
289+
}
258290
};
259291
#undef cout
260292
#endif // DServerMiscTestSuite_h

cppapi/server/device.cpp

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,15 +2408,6 @@ void DeviceImpl::set_attribute_config(const Tango::AttributeConfigList &new_conf
24082408
(const char *) "DeviceImpl::set_attribute_config");
24092409
}
24102410

2411-
//
2412-
// Get some event related data
2413-
//
2414-
2415-
Tango::Util *tg = Tango::Util::instance();
2416-
2417-
EventSupplier *event_supplier_nd = NULL;
2418-
EventSupplier *event_supplier_zmq = NULL;
2419-
24202411
//
24212412
// Update attribute config first in database, then locally
24222413
// Finally send attr conf. event
@@ -2462,75 +2453,7 @@ void DeviceImpl::set_attribute_config(const Tango::AttributeConfigList &new_conf
24622453
// Send the event
24632454
//
24642455

2465-
if (attr.use_notifd_event() == true)
2466-
{
2467-
event_supplier_nd = tg->get_notifd_event_supplier();
2468-
}
2469-
else
2470-
{
2471-
event_supplier_nd = NULL;
2472-
}
2473-
2474-
if (attr.use_zmq_event() == true)
2475-
{
2476-
event_supplier_zmq = tg->get_zmq_event_supplier();
2477-
}
2478-
else
2479-
{
2480-
event_supplier_zmq = NULL;
2481-
}
2482-
2483-
if ((event_supplier_nd != NULL) || (event_supplier_zmq != NULL))
2484-
{
2485-
std::string tmp_name(new_conf[i].name);
2486-
2487-
EventSupplier::SuppliedEventData ad;
2488-
::memset(&ad, 0, sizeof(ad));
2489-
2490-
long vers = get_dev_idl_version();
2491-
if (vers <= 2)
2492-
{
2493-
Tango::AttributeConfig_2 attr_conf_2;
2494-
attr.get_properties(attr_conf_2);
2495-
ad.attr_conf_2 = &attr_conf_2;
2496-
if (event_supplier_nd != NULL)
2497-
{
2498-
event_supplier_nd->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name);
2499-
}
2500-
if (event_supplier_zmq != NULL)
2501-
{
2502-
event_supplier_zmq->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name);
2503-
}
2504-
}
2505-
else if (vers <= 4)
2506-
{
2507-
Tango::AttributeConfig_3 attr_conf_3;
2508-
attr.get_properties(attr_conf_3);
2509-
ad.attr_conf_3 = &attr_conf_3;
2510-
if (event_supplier_nd != NULL)
2511-
{
2512-
event_supplier_nd->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name);
2513-
}
2514-
if (event_supplier_zmq != NULL)
2515-
{
2516-
event_supplier_zmq->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name);
2517-
}
2518-
}
2519-
else
2520-
{
2521-
Tango::AttributeConfig_5 attr_conf_5;
2522-
attr.get_properties(attr_conf_5);
2523-
ad.attr_conf_5 = &attr_conf_5;
2524-
if (event_supplier_nd != NULL)
2525-
{
2526-
event_supplier_nd->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name);
2527-
}
2528-
if (event_supplier_zmq != NULL)
2529-
{
2530-
event_supplier_zmq->push_att_conf_events(this, ad, (Tango::DevFailed *) NULL, tmp_name);
2531-
}
2532-
}
2533-
}
2456+
push_att_conf_event(&attr);
25342457
}
25352458

25362459
}

cppapi/server/dserver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,14 @@ void DServer::restart(std::string &d_name)
11191119
event_supplier_zmq->push_dev_intr_change_event(new_dev,false,cmds_list,atts_list);
11201120
}
11211121
}
1122+
1123+
// Attribute properties may have changed after the restart.
1124+
// Push an attribute configuration event to all registered subscribers.
1125+
1126+
for (Attribute* attr : new_dev->get_device_attr()->get_attribute_list())
1127+
{
1128+
new_dev->push_att_conf_event(attr);
1129+
}
11221130
}
11231131

11241132
//+-----------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)