Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #305 from dawagner/component-arrays
Browse files Browse the repository at this point in the history
Add "array" capability to Components

Numerical parameters as well as ParameterBlocks can have an "ArrayLength"
attribute that instantiate as many identical parameters or parameter blocks.

This is now also possible for Component instances (not types).

The Semantic of this feature is very unclear, even now... use with caution and
see 416f784.
  • Loading branch information
dawagner committed Nov 20, 2015
2 parents 67fd096 + 416f784 commit 0ba8ce6
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 31 deletions.
7 changes: 0 additions & 7 deletions parameter/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,5 @@ class CComponent : public CInstanceConfigurableElement
{
return EComponent;
}

std::string getXmlElementName() const override
{
// Once instantiated components are reflected as parameter blocks
// in XML documents
return "ParameterBlock";
}
};

37 changes: 33 additions & 4 deletions parameter/ComponentInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ComponentLibrary.h"
#include "ComponentType.h"
#include "Component.h"
#include "ParameterBlock.h" // for "array" instantiation
#include "XmlParameterSerializingContext.h"

#define base CTypeElement
Expand All @@ -41,7 +42,14 @@ CComponentInstance::CComponentInstance(const std::string& strName) : base(strNam

std::string CComponentInstance::getKind() const
{
return "Component";
return "ComponentInstance";
}

std::string CComponentInstance::getXmlElementName() const
{
// Once instantiated components are reflected as parameter blocks
// in XML documents
return "ParameterBlock";
}

bool CComponentInstance::childrenAreDynamic() const
Expand Down Expand Up @@ -103,12 +111,33 @@ bool CComponentInstance::fromXml(const CXmlElement& xmlElement, CXmlSerializingC

CInstanceConfigurableElement* CComponentInstance::doInstantiate() const
{
return new CComponent(getName(), this);
if (isScalar()) {
return new CComponent(getName(), this);
} else {
return new CParameterBlock(getName(), this);
}
}

void CComponentInstance::populate(CElement* pElement) const
{
base::populate(pElement);
size_t arrayLength = getArrayLength();

if (arrayLength != 0) {

// Create child elements
for (size_t child = 0; child < arrayLength; child++) {

_pComponentType->populate(static_cast<CComponent*>(pElement));
CComponent* pChildComponent = new CComponent(std::to_string(child), this);

pElement->addChild(pChildComponent);

base::populate(pChildComponent);

_pComponentType->populate(pChildComponent);
}
} else {
base::populate(pElement);

_pComponentType->populate(static_cast<CComponent*>(pElement));
}
}
1 change: 1 addition & 0 deletions parameter/ComponentInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CComponentInstance : public CTypeElement

// CElement
virtual std::string getKind() const;
std::string getXmlElementName() const override;
private:
virtual bool childrenAreDynamic() const;
virtual CInstanceConfigurableElement* doInstantiate() const;
Expand Down
6 changes: 6 additions & 0 deletions parameter/InstanceConfigurableElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ std::string CInstanceConfigurableElement::getKind() const
return _pTypeElement->getKind();
}

std::string CInstanceConfigurableElement::getXmlElementName() const
{
// Delegate
return _pTypeElement->getXmlElementName();
}

// Type element
const CTypeElement* CInstanceConfigurableElement::getTypeElement() const
{
Expand Down
1 change: 1 addition & 0 deletions parameter/InstanceConfigurableElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PARAMETER_EXPORT CInstanceConfigurableElement : public CConfigurableElemen

// From CElement
virtual std::string getKind() const;
std::string getXmlElementName() const override;

// Syncer to/from HW
void setSyncer(ISyncer* pSyncer);
Expand Down
11 changes: 2 additions & 9 deletions parameter/MappingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ using std::string;
// Item access
bool CMappingContext::setItem(size_t itemType, const string* pStrKey, const string* pStrItem)
{
// Assert that the key hasn't been set before
assert(find_if(begin(mItems), end(mItems), [pStrKey](SItem &item)
{ return item.strKey == pStrKey; }
) == end(mItems));

if (mItems[itemType].bSet) {
if (iSet(itemType)) {
// Already set!
return false;
}
Expand All @@ -53,8 +48,6 @@ bool CMappingContext::setItem(size_t itemType, const string* pStrKey, const stri
// Set item value
mItems[itemType].strItem = pStrItem;

// Now is set
mItems[itemType].bSet = true;
return true;
}

Expand Down Expand Up @@ -83,5 +76,5 @@ const string* CMappingContext::getItem(const string& strKey) const

bool CMappingContext::iSet(size_t itemType) const
{
return mItems[itemType].bSet;
return mItems[itemType].strItem != nullptr;
}
5 changes: 2 additions & 3 deletions parameter/MappingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ class PARAMETER_EXPORT CMappingContext
private:
// Item structure
struct SItem {
const std::string* strKey;
const std::string* strItem;
bool bSet;
const std::string* strKey{nullptr};
const std::string* strItem{nullptr};
};

public:
Expand Down
1 change: 1 addition & 0 deletions schemas/Parameter.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</xs:attributeGroup>
<xs:complexType name="ComponentInstance">
<xs:attributeGroup ref="TypedNameable"/>
<xs:attributeGroup ref="ArrayLengthAttribute"/>
<xs:attribute name="Mapping" use="optional"/>
</xs:complexType>
<xs:simpleType name="SizeType">
Expand Down
26 changes: 18 additions & 8 deletions test/functional-tests/Handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ struct AllParamsPF : public ParameterFramework
nodeDesc("ParameterBlock", "parameter_block_array",
getBasicParams(), "ArrayLength='2'") +
nodeDesc("Component", "component_scalar", "", "Type='component_type'") +
// Test that ArrayLength have no effect on components
nodeDesc("Component", "component_array", "",
"Type='component_type' ArrayLength='2'");
return config;
Expand Down Expand Up @@ -220,10 +219,12 @@ SCENARIO_METHOD(AllParamsPF, "Export component", "[handler][structure][xml]")

SCENARIO_METHOD(AllParamsPF, "Export component array", "[handler][structure][xml]")
{
string expected = rootNode("ParameterBlock", "Name='component_array' "
"Description='description_component_array'",
// component array are the same as non array for now
getBasicParams());
string expected = rootNode("ParameterBlock",
"Name='component_array' Description='description_component_array'",
nodeDesc("ParameterBlock", "0", getBasicParams(), "",
"description_component_array") +
nodeDesc("ParameterBlock", "1", getBasicParams(), "",
"description_component_array"));
checkStructure("/test/test/component_array", expected);
}

Expand All @@ -239,7 +240,12 @@ SCENARIO_METHOD(AllParamsPF, "Export all parameters", "[handler][structure][xml]
"description_parameter_block_array")) +
// Components should be exported as parameterBlock
nodeDesc("ParameterBlock", "component_scalar", getBasicParams()) +
nodeDesc("ParameterBlock", "component_array", getBasicParams());
nodeDesc("ParameterBlock", "component_array",
nodeDesc("ParameterBlock", "0", getBasicParams(), "",
// description is inherited from array
"description_component_array") +
nodeDesc("ParameterBlock", "1", getBasicParams(), "",
"description_component_array"));

WHEN("Exporting subsystem") {
string expected = rootNode("Subsystem", "Name='test'", paramExpected);
Expand Down Expand Up @@ -274,7 +280,9 @@ struct SettingsTestPF : public AllParamsPF
parameterBlockNode("0", settings) +
parameterBlockNode("1", settings)) +
parameterBlockNode("component_scalar", settings) +
parameterBlockNode("component_array", settings);
parameterBlockNode("component_array",
parameterBlockNode("0", settings) +
parameterBlockNode("1", settings));

return rootNode("SystemClass", "Name='test'" ,
node("Subsystem", "test", settings, ""));
Expand All @@ -283,7 +291,9 @@ struct SettingsTestPF : public AllParamsPF
static string fullBytesSettings(const string &basicSettings)
{
string fullSettings;
for (size_t i = 0; i < 6; ++i) {
// We have the "basic params" repeated 7 times across the test
// structure
for (size_t i = 0; i < 7; ++i) {
fullSettings += basicSettings;
}
return fullSettings;
Expand Down

0 comments on commit 0ba8ce6

Please sign in to comment.