Setting enum property from ACI

I have a component that has a property that is of type enum:

<Property name='window_type' type='enum' initial='true' enums='none,hann,hamming,blackman' default='none'>
    <Description> The type of window to apply to the input data. </Description>
</Property>

According to the component development guide page 39, the underlying value for an enum is a uint32 and it is specified within an application xml using its string representation.

I want to set this property from the ACI. I have an OCPI::API::Property object for the specific property and have attempted property.setULongValue() and property.setStringValue() which both throw a std::string error:
Access error for property "window_type": incorrect type for this property

So I just threw a test together quickly, and both of the following work in ~June 2023 develop:

app.setProperty("<instance-name>.<property-name>", "<enum-name>")
app.setProperty("<instance-name>.<property-name>", "<enum-value>")

I encountered the same error trying to use the Property object with the setULongValue method.

All of those access methods on Property objects are meant to be used solely when the type of the property is the type in the method name. I’d expect the string one to fail, but I don’t see a reason why the ULong one should fail.

I’ll have a deeper look at that.

Had a bit of a mess around. The offending type check is on line 49 of runtime/container/src/ContainerProperty.cc:

else if (ctype != m.m_baseType)
  err = "incorrect type for this property";

In your instance, ctype is OCPI_ULong and m_baseType is OCPI_Enum, which indeed don’t match.

I did the following patch which then allowed me to use setULongValue on enum types:

diff --git a/runtime/container/src/ContainerProperty.cc b/runtime/container/src/ContainerProperty.cc
index 9dbfb4cbb..648b3426e 100644
--- a/runtime/container/src/ContainerProperty.cc
+++ b/runtime/container/src/ContainerProperty.cc
@@ -46,7 +46,7 @@ namespace OCPI {
 #endif
       else if (m.m_baseType == OCPI_Struct)
        err = "struct type used as scalar type";
-      else if (ctype != m.m_baseType)
+      else if (m.m_baseType != ctype && !(m.m_baseType == OCPI_Enum && ctype == OCPI_ULong))
        err = "incorrect type for this property";
       else if (n && m.m_isSequence) {
        if (n % m.m_nItems)

Basically just adds an exclusion in the case that a property is an enum and you are using a ulong to set it.

I’ll defer to others as to whether this is an appropriate modification to mainline, or whether there is a more appropriate solution to this.

Thanks, I will make the same modification for now