Support for device level dynamic attributes
In sardana, there are many different things running under the same Class. For example a "Motor" can be a quite different thing depending on which actual controller it uses. This causes problems sometimes, when two different motors define an attribute with the same name but with different properties.
The first device to be instantiated then creates all the attributes without issues, and they all get added to the Motor class. Lets say it has an attribute MaxCurrent, which can bb both read and written. When a second device then starts, it will try to add its attributes, but since the same ones already exists there might be conflicts. Let's imagine this motor also has MaxCurrent, but for this controller it is read only. Then the attribute cannot be added.
The solution in Sardana currently is that when each device starts, it removes any conflicting attribute from the class. This isn't a good solution as it causes other problems for the other devices.
There appears to be no solution to this on the Sardana level, except the very undesirable one of changing the whole concept of how it uses Classes.
A very nice solution would be if there was an option to make a new attribute on device level. This exists for commands, where there is an option to add them on device level so they never get added to the class.
The modified add_attribute would then be like this:
void Tango::DeviceImpl::add_attribute ( Attr * new_attr, bool device = false )
Add a new attribute to the device attribute list.
Attributes are normally constructed in the DeviceClass::attribute_factory() method. Nevertheless, it is still possible to add a new attribute to a device with this method. Please, note that if you add an attribute to a device at device creation time, this attribute will be added to the device class attribute list. Therefore, all devices belonging to the same class created after this attribute addition will also have this attribute.
Parameters
new_attr Pointer to the new attribute to be added to the list. This pointer must point to "heap" allocated memory (or to static memory) and not to "stack" allocated memory
device Set this flag to true if the attribute must be added for only this device Default is false (attribute added for the device class)
Exceptions
DevFailed Click here to read DevFailed exception specification
Adding this "device" flag, and letting each device keep it's own list of device level attributes would be a very welcome addition.
This is a simple device server for reproducing the problem that Sardana faces: https://github.com/reszelaz/tango-dynattrs It should be run with two devices under the same server instance. It then creates two sets of attributes, where one is conflicting with the other. The result is that the second set isn't created, and that device ends up without it's attributes. See the readme in the repo for details on how to configure it.