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

Commit 60f41a6

Browse files
jairomoldesIngvord
authored andcommitted
Forwarded dynamic attributes (#342)
This feature is currently supported only in device servers exporting only one device (without taking into account the admin device). Fix also a bug in multiattribute.cpp which could lead to segmentation fault.
1 parent 06f5419 commit 60f41a6

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

src/server/fwdattrdesc.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ bool FwdAttr::validate_fwd_att(vector<AttrProperty> &prop_list,const string &dev
124124

125125
string root_att_db;
126126
bool root_att_db_defined = false;
127+
bool is_full_root_att_set = false;
127128

128129
Util *tg = Util::instance();
129130
Database *db = tg->get_database();
@@ -178,10 +179,15 @@ bool FwdAttr::validate_fwd_att(vector<AttrProperty> &prop_list,const string &dev
178179
}
179180
catch (...) {}
180181

181-
if (root_att_db_defined == true)
182-
full_root_att = root_att_db;
183-
else
184-
full_root_att = RootAttNotDef;
182+
//check if full_root_att is already set
183+
is_full_root_att_set = full_root_att.size()!=0 && full_root_att.compare(RootAttNotDef)!=0;
184+
185+
if(!is_full_root_att_set) {
186+
if (root_att_db_defined)
187+
full_root_att = root_att_db;
188+
else
189+
full_root_att = RootAttNotDef;
190+
}
185191

186192
//
187193
// Check root att syntax and add TANGO_HOST info in root device name of not given

src/server/multiattribute.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,53 @@ void MultiAttribute::add_fwd_attribute(string &dev_name,DeviceClass *dev_class_p
881881
add_user_default(prop_list,def_user_prop);
882882
add_default(prop_list,dev_name,attr.get_name(),attr.get_type());
883883

884+
//
885+
// Validate and register the root attribute configuration
886+
//
887+
if (new_attr->is_fwd() == true)
888+
{
889+
Tango::FwdAttr *fwd_attr = (Tango::FwdAttr *) new_attr;
890+
// If forwarded attribute is dynamically created and was constructed without specifying
891+
// the root_attribute parameter then we have to get its __root_att property from tango DB
892+
// prior to calling validate_fwd_att()
893+
vector<AttrProperty> dev_prop;
894+
Tango::Util *tg = Tango::Util::instance();
895+
if ((tg->_UseDb==true) && (fwd_attr->get_full_root_att()==RootAttNotDef))
896+
{
897+
Tango::DbData db_list;
898+
db_list.push_back(DbDatum(fwd_attr->get_name()));
899+
tg->get_database()->get_device_attribute_property(dev_name,db_list,tg->get_db_cache());
900+
for (unsigned int ind=0 ; ind<db_list.size() ; ind++)
901+
{
902+
if (db_list[ind].name == RootAttrPropName)
903+
{
904+
dev_prop.push_back(AttrProperty(db_list[ind].name, db_list[ind].value_string[0]));
905+
break;
906+
}
907+
}
908+
}
909+
910+
// Validate the __root_att property of the attribute
911+
fwd_attr->validate_fwd_att(dev_prop, dev_name);
912+
913+
// Register the root attribute configuration
914+
Tango::DeviceImpl *device = tg->get_device_by_name(dev_name);
915+
try
916+
{
917+
fwd_attr->get_root_conf(dev_name,device);
918+
}
919+
catch (...)
920+
{
921+
// If any error add this attribute to the device list of wrong configured attributes
922+
DeviceImpl::FwdWrongConf fwc;
923+
fwc.att_name = fwd_attr->get_name();
924+
fwc.full_root_att_name = fwd_attr->get_full_root_att();
925+
fwc.fae = fwd_attr->get_err_kind();
926+
vector<DeviceImpl::FwdWrongConf> &fwd_att_wrong_conf = device->get_fwd_att_wrong_conf();
927+
fwd_att_wrong_conf.push_back(fwc);
928+
}
929+
}
930+
884931
//
885932
// Create an Attribute instance and insert it in the attribute list. If the device implement IDL 3
886933
// (with state and status as attributes), add it at the end of the list but before state and status.
@@ -913,6 +960,12 @@ void MultiAttribute::add_fwd_attribute(string &dev_name,DeviceClass *dev_class_p
913960
alarm_attr_list.push_back(index);
914961
}
915962

963+
//
964+
// Check if the writable_attr_name property is set and in this case, check if the associated attribute exists and is
965+
// writable
966+
//
967+
check_associated(index,dev_name);
968+
916969
cout4 << "Leaving MultiAttribute::add_fwd_attribute" << endl;
917970
}
918971

0 commit comments

Comments
 (0)