libopae++: Fix fpga_resource::enumerate_tokens
Change logic so that if tests if option_map list is not empty and then
it tries to convert them to filters (fpga_properties). After
iterating over the list of option_map objects, check the resulting list
of filters and if it is empty, then add one filter of the object type.
@@ -118,19 +118,14 @@ bool fpga_resource::enumerate_tokens(fpga_objtype objtype,
vector<shared_token> & tokens)
{
bool result = false;
- uint32_t filter_size = 0;
intel::utils::logger log;
vector<fpga_properties> filters;
vector<fpga_token> real_tokens;
- if (options.empty())
- {
- filter_size = 1;
- filters.resize(1);
- fpgaGetProperties(nullptr, &filters[0]);
- fpgaPropertiesSetObjectType(filters[0], objtype);
- }
- else
+ // if we have a non empty list of option_map objects
+ // iteratve over those objects and try to make an
+ // fpga_properties object from each option_map
+ if (!options.empty())
{
filters.reserve(options.size());
filters.resize(0);
@@ -138,6 +133,7 @@ bool fpga_resource::enumerate_tokens(fpga_objtype objtype,
for (int i = 0; i < options.size(); ++i)
{
fpga_properties props;
+ // make a temporary fpga_properties object
if (fpgaGetProperties(nullptr, &props) == FPGA_OK)
{
fpgaPropertiesSetObjectType(props, objtype);
@@ -148,11 +144,26 @@ bool fpga_resource::enumerate_tokens(fpga_objtype objtype,
}
else
{
+ // Couldn't find at least one key/value in the map
+ // that could be used as a fpga_properties property
+ // Then destoy the temporary props
fpgaDestroyProperties(&props);
}
}
}
}
+
+ // If the filters is empty then it means we couldn't convert at
+ // least one of the option_map objects into an fpga_properties object.
+ // Because we want to use at least one filter that includes the object
+ // type, then let's add it here. This ensures we always filter by object type.
+ if (filters.empty())
+ {
+ filters.resize(1);
+ fpgaGetProperties(nullptr, &filters[0]);
+ fpgaPropertiesSetObjectType(filters[0], objtype);
+ }
+
uint32_t matches = 0;
auto enum_result = fpgaEnumerate(filters.data(), filters.size(), nullptr, 0, &matches);
if (enum_result == FPGA_OK)
