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

Commit 7115111

Browse files
committed
Use attribute name when restoring events state (#496)
Backport of 1a07976. A new struct and a set of overloads are added to keep backward compatibility with 9.3 release.
1 parent 8712a7a commit 7115111

File tree

6 files changed

+260
-12
lines changed

6 files changed

+260
-12
lines changed

cppapi/server/device.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6148,6 +6148,25 @@ void DeviceImpl::get_event_param(vector<EventPar> &eve)
61486148
}
61496149
}
61506150

6151+
void DeviceImpl::get_event_param(vector<EventSubscriptionState> &eve)
6152+
{
6153+
ZmqEventSupplier *event_supplier_zmq = Util::instance()->get_zmq_event_supplier();
6154+
6155+
if (event_supplier_zmq->any_dev_intr_client(this) == true)
6156+
{
6157+
EventSubscriptionState ep;
6158+
6159+
ep.notifd = false;
6160+
ep.zmq = true;
6161+
ep.attribute_name = "";
6162+
ep.quality = false;
6163+
ep.data_ready = false;
6164+
ep.dev_intr_change = true;
6165+
6166+
eve.push_back(ep);
6167+
}
6168+
}
6169+
61516170
//+-----------------------------------------------------------------------------------------------------------------
61526171
//
61536172
// method :
@@ -6177,6 +6196,21 @@ void DeviceImpl::set_event_param(vector<EventPar> &eve)
61776196
}
61786197
}
61796198

6199+
void DeviceImpl::set_event_param(vector<EventSubscriptionState> &eve)
6200+
{
6201+
for (size_t loop = 0; loop < eve.size(); loop++)
6202+
{
6203+
if (eve[loop].attribute_name.empty())
6204+
{
6205+
if (eve[loop].dev_intr_change == true)
6206+
{
6207+
set_event_intr_change_subscription(time(NULL));
6208+
}
6209+
break;
6210+
}
6211+
}
6212+
}
6213+
61806214
//+-----------------------------------------------------------------------------------------------------------------
61816215
//
61826216
// method :

cppapi/server/device.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,8 +3414,10 @@ class DeviceImpl : public virtual POA_Tango::Device
34143414
void disable_intr_change_ev() {intr_change_ev = false;}
34153415
bool is_intr_change_ev_enable() {return intr_change_ev;}
34163416

3417-
void get_event_param(vector<EventPar> &);
3418-
void set_event_param(vector<EventPar> &);
3417+
void get_event_param(vector<EventPar> &); // Deprecated, use EventSubscriptionState overload
3418+
void set_event_param(vector<EventPar> &); // Deprecated, use EventSubscriptionState overload
3419+
void get_event_param(vector<EventSubscriptionState>&);
3420+
void set_event_param(vector<EventSubscriptionState>&);
34193421

34203422
void set_client_lib(int _l) {if (count(client_lib.begin(),client_lib.end(),_l)==0)client_lib.push_back(_l);}
34213423

cppapi/server/dserver.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ void DServer::restart(string &d_name)
861861

862862
vector<PollObj *> &p_obj = dev_to_del->get_poll_obj_list();
863863
vector<Pol> dev_pol;
864-
vector<EventPar> eve;
864+
vector<EventSubscriptionState> eve;
865865

866866
for (i = 0;i < p_obj.size();i++)
867867
{
@@ -1172,7 +1172,7 @@ void ServRestartThread::run(void *ptr)
11721172
// Memorize event parameters and devices interface
11731173
//
11741174

1175-
map<string,vector<EventPar> > map_events;
1175+
map<string,vector<EventSubscriptionState> > map_events;
11761176
map<string,DevIntr> map_dev_inter;
11771177

11781178
dev->mem_event_par(map_events);
@@ -1204,22 +1204,22 @@ void ServRestartThread::run(void *ptr)
12041204
dev->set_poll_th_pool_size(DEFAULT_POLLING_THREADS_POOL_SIZE);
12051205

12061206
tg->set_svr_starting(true);
1207-
1207+
12081208
vector<DeviceClass *> empty_class;
12091209
tg->set_class_list(&empty_class);
1210-
1210+
12111211
{
12121212
AutoPyLock PyLo;
12131213
dev->init_device();
12141214
}
1215-
1215+
12161216
//
12171217
// Set the class list pointer in the Util class and add the DServer object class
12181218
//
12191219

12201220
tg->set_class_list(&(dev->get_class_list()));
12211221
tg->add_class_to_list(dev->get_device_class());
1222-
1222+
12231223
tg->set_svr_starting(false);
12241224

12251225
//
@@ -1975,6 +1975,25 @@ void DServer::mem_event_par(map<string,vector<EventPar> > &_map)
19751975
}
19761976
}
19771977

1978+
void DServer::mem_event_par(map<string,vector<EventSubscriptionState> > &_map)
1979+
{
1980+
for (size_t i = 0;i < class_list.size();i++)
1981+
{
1982+
vector<DeviceImpl *> &dev_list = class_list[i]->get_device_list();
1983+
for (size_t j = 0;j < dev_list.size();j++)
1984+
{
1985+
vector<EventSubscriptionState> eve;
1986+
dev_list[j]->get_device_attr()->get_event_param(eve);
1987+
dev_list[j]->get_event_param(eve);
1988+
1989+
if (eve.size() != 0)
1990+
{
1991+
_map.insert(make_pair(dev_list[j]->get_name(),eve));
1992+
}
1993+
}
1994+
}
1995+
}
1996+
19781997
//+-----------------------------------------------------------------------------------------------------------------
19791998
//
19801999
// method :
@@ -2009,6 +2028,26 @@ void DServer::apply_event_par(map<string,vector<EventPar> > &_map)
20092028
}
20102029
}
20112030

2031+
void DServer::apply_event_par(map<string,vector<EventSubscriptionState> > &_map)
2032+
{
2033+
for (size_t i = 0;i < class_list.size();i++)
2034+
{
2035+
vector<DeviceImpl *> &dev_list = class_list[i]->get_device_list();
2036+
for (size_t j = 0;j < dev_list.size();j++)
2037+
{
2038+
string &dev_name = dev_list[j]->get_name();
2039+
map<string,vector<EventSubscriptionState> >::iterator ite;
2040+
ite = _map.find(dev_name);
2041+
2042+
if (ite != _map.end())
2043+
{
2044+
dev_list[j]->get_device_attr()->set_event_param(ite->second);
2045+
dev_list[j]->set_event_param(ite->second);
2046+
}
2047+
}
2048+
}
2049+
}
2050+
20122051
//+-----------------------------------------------------------------------------------------------------------------
20132052
//
20142053
// method :

cppapi/server/dserver.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ public :
127127
void _create_cpp_class(const char *c1,const char *c2) {this->create_cpp_class(c1,c2);}
128128

129129
void mcast_event_for_att(string &,string &,vector<string> &);
130-
void mem_event_par(map<string, vector<EventPar> > &);
131-
void apply_event_par(map<string,vector<EventPar> > &);
130+
void mem_event_par(map<string, vector<EventPar> > &); // Deprecated, use EventSubscriptionState overload
131+
void apply_event_par(map<string,vector<EventPar> > &); // Deprecated, use EventSubscriptionState overload
132+
void mem_event_par(map<string, vector<EventSubscriptionState> >&);
133+
void apply_event_par(map<string,vector<EventSubscriptionState> >&);
132134

133135
void mem_devices_interface(map<string,DevIntr> &);
134136
void changed_devices_interface(map<string,DevIntr> &);
@@ -158,6 +160,7 @@ protected :
158160
static ClassFactoryFuncPtr class_factory_func_ptr;
159161

160162
private:
163+
161164
#if ((defined _TG_WINDOWS_) && (defined TANGO_HAS_DLL) && !(defined _TANGO_LIB))
162165
__declspec(dllexport) void class_factory();
163166
#else

cppapi/server/multiattribute.cpp

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,91 @@ void MultiAttribute::get_event_param(vector<EventPar> &eve)
15861586
}
15871587
}
15881588

1589+
void MultiAttribute::get_event_param(vector<EventSubscriptionState> &eve)
1590+
{
1591+
unsigned int i;
1592+
1593+
for (i = 0;i < attr_list.size();i++)
1594+
{
1595+
bool once_more = false;
1596+
vector<int> ch;
1597+
vector<int> ar;
1598+
vector<int> pe;
1599+
vector<int> us;
1600+
vector<int> ac;
1601+
bool dr = false;
1602+
bool qu = false;
1603+
1604+
if (attr_list[i]->change_event_subscribed() == true)
1605+
{
1606+
once_more = true;
1607+
ch = attr_list[i]->get_client_lib(CHANGE_EVENT);
1608+
}
1609+
1610+
if (attr_list[i]->quality_event_subscribed() == true)
1611+
{
1612+
once_more = true;
1613+
qu = true;
1614+
}
1615+
1616+
if (attr_list[i]->periodic_event_subscribed() == true)
1617+
{
1618+
once_more = true;
1619+
pe = attr_list[i]->get_client_lib(PERIODIC_EVENT);
1620+
}
1621+
1622+
if (attr_list[i]->archive_event_subscribed() == true)
1623+
{
1624+
once_more = true;
1625+
ar = attr_list[i]->get_client_lib(ARCHIVE_EVENT);
1626+
}
1627+
1628+
if (attr_list[i]->user_event_subscribed() == true)
1629+
{
1630+
once_more = true;
1631+
us = attr_list[i]->get_client_lib(USER_EVENT);
1632+
}
1633+
1634+
if (attr_list[i]->attr_conf_event_subscribed() == true)
1635+
{
1636+
once_more = true;
1637+
ac = attr_list[i]->get_client_lib(ATTR_CONF_EVENT);
1638+
}
1639+
1640+
if (attr_list[i]->data_ready_event_subscribed() == true)
1641+
{
1642+
once_more = true;
1643+
dr = true;
1644+
}
1645+
1646+
if (once_more == true)
1647+
{
1648+
EventSubscriptionState ep;
1649+
1650+
if (attr_list[i]->use_notifd_event() == true)
1651+
ep.notifd = true;
1652+
else
1653+
ep.notifd = false;
1654+
1655+
if (attr_list[i]->use_zmq_event() == true)
1656+
ep.zmq = true;
1657+
else
1658+
ep.zmq = false;
1659+
1660+
ep.attribute_name = attr_list[i]->get_name();;
1661+
ep.change = ch;
1662+
ep.quality = qu;
1663+
ep.archive = ar;
1664+
ep.periodic = pe;
1665+
ep.user = us;
1666+
ep.att_conf = ac;
1667+
ep.data_ready = dr;
1668+
1669+
eve.push_back(ep);
1670+
}
1671+
}
1672+
}
1673+
15891674
//+-----------------------------------------------------------------------------------------------------------------
15901675
//
15911676
// method :
@@ -1676,6 +1761,82 @@ void MultiAttribute::set_event_param(vector<EventPar> &eve)
16761761
}
16771762
}
16781763

1764+
void MultiAttribute::set_event_param(vector<EventSubscriptionState> &eve)
1765+
{
1766+
for (size_t i = 0;i < eve.size();i++)
1767+
{
1768+
if (! eve[i].attribute_name.empty())
1769+
{
1770+
Tango::Attribute &att = get_attr_by_name(eve[i].attribute_name.c_str());
1771+
1772+
{
1773+
omni_mutex_lock oml(EventSupplier::get_event_mutex());
1774+
vector<int>::iterator ite;
1775+
1776+
if (eve[i].change.empty() == false)
1777+
{
1778+
std::string event_name = EventName[CHANGE_EVENT];
1779+
for (ite = eve[i].change.begin();ite != eve[i].change.end();++ite)
1780+
{
1781+
att.set_change_event_sub(*ite);
1782+
att.set_client_lib(*ite, event_name);
1783+
}
1784+
}
1785+
1786+
if (eve[i].periodic.empty() == false)
1787+
{
1788+
std::string event_name = EventName[PERIODIC_EVENT];
1789+
for (ite = eve[i].periodic.begin();ite != eve[i].periodic.end();++ite)
1790+
{
1791+
att.set_periodic_event_sub(*ite);
1792+
att.set_client_lib(*ite, event_name);
1793+
}
1794+
}
1795+
1796+
if (eve[i].archive.empty() == false)
1797+
{
1798+
std::string event_name = EventName[ARCHIVE_EVENT];
1799+
for (ite = eve[i].archive.begin();ite != eve[i].archive.end();++ite)
1800+
{
1801+
att.set_archive_event_sub(*ite);
1802+
att.set_client_lib(*ite, event_name);
1803+
}
1804+
}
1805+
1806+
if (eve[i].att_conf.empty() == false)
1807+
{
1808+
std::string event_name = EventName[ATTR_CONF_EVENT];
1809+
for (ite = eve[i].att_conf.begin();ite != eve[i].att_conf.end();++ite)
1810+
{
1811+
att.set_att_conf_event_sub(*ite);
1812+
att.set_client_lib(*ite, event_name);
1813+
}
1814+
}
1815+
1816+
if (eve[i].user.empty() == false)
1817+
{
1818+
std::string event_name = EventName[USER_EVENT];
1819+
for (ite = eve[i].user.begin();ite != eve[i].user.end();++ite)
1820+
{
1821+
att.set_user_event_sub(*ite);
1822+
att.set_client_lib(*ite, event_name);
1823+
}
1824+
}
1825+
1826+
if (eve[i].quality == true)
1827+
att.set_quality_event_sub();
1828+
if (eve[i].data_ready == true)
1829+
att.set_data_ready_event_sub();
1830+
}
1831+
1832+
if (eve[i].notifd == true)
1833+
att.set_use_notifd_event();
1834+
if (eve[i].zmq == true)
1835+
att.set_use_zmq_event();
1836+
}
1837+
}
1838+
}
1839+
16791840
//+------------------------------------------------------------------------------------------------------------------
16801841
//
16811842
// method :

cppapi/server/multiattribute.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ struct EventPar
6161
bool zmq;
6262
};
6363

64+
// This structure is intended to be used in place of EventPar. Field attribute_name
65+
// replaces attr_id. EventPar is left untouched for backward compatibility with 9.3.
66+
struct EventSubscriptionState : public EventPar
67+
{
68+
std::string attribute_name;
69+
};
70+
6471
//=============================================================================
6572
//
6673
// The MultiAttribute class
@@ -283,8 +290,10 @@ class MultiAttribute
283290
void remove_attribute(string &,bool);
284291
vector<long> &get_w_attr_list() {return writable_attr_list;}
285292
bool is_att_quality_alarmed();
286-
void get_event_param(vector<EventPar> &);
287-
void set_event_param(vector<EventPar> &);
293+
void get_event_param(vector<EventPar> &); // Deprecated, use EventSubscriptionState overload
294+
void set_event_param(vector<EventPar> &); // Deprecated, use EventSubscriptionState overload
295+
void get_event_param(vector<EventSubscriptionState> &);
296+
void set_event_param(vector<EventSubscriptionState> &);
288297
void add_alarmed_quality_factor(string &);
289298
void add_default(vector<AttrProperty> &,string &,string &,long);
290299
void add_attr(Attribute *att);

0 commit comments

Comments
 (0)