diff options
Diffstat (limited to 'parameter')
-rw-r--r-- | parameter/Android.mk | 3 | ||||
-rw-r--r-- | parameter/CompoundRule.cpp | 73 | ||||
-rw-r--r-- | parameter/CompoundRule.h | 12 | ||||
-rw-r--r-- | parameter/ConfigurableDomain.cpp | 149 | ||||
-rw-r--r-- | parameter/ConfigurableDomain.h | 20 | ||||
-rw-r--r-- | parameter/ConfigurableDomains.cpp | 144 | ||||
-rw-r--r-- | parameter/ConfigurableDomains.h | 10 | ||||
-rw-r--r-- | parameter/DomainConfiguration.cpp | 75 | ||||
-rw-r--r-- | parameter/DomainConfiguration.h | 11 | ||||
-rw-r--r-- | parameter/ParameterMgr.cpp | 42 | ||||
-rw-r--r-- | parameter/ParameterMgr.h | 6 | ||||
-rw-r--r-- | parameter/Rule.h | 8 | ||||
-rw-r--r-- | parameter/RuleParser.cpp | 252 | ||||
-rw-r--r-- | parameter/RuleParser.h | 94 | ||||
-rw-r--r-- | parameter/SelectionCriterionRule.cpp | 73 | ||||
-rw-r--r-- | parameter/SelectionCriterionRule.h | 9 |
16 files changed, 852 insertions, 129 deletions
diff --git a/parameter/Android.mk b/parameter/Android.mk index 28989a0..eab9430 100644 --- a/parameter/Android.mk +++ b/parameter/Android.mk @@ -91,7 +91,8 @@ LOCAL_SRC_FILES:= \ VirtualSyncer.cpp \ ParameterHandle.cpp \ ParameterAdaptation.cpp \ - LinearParameterAdaptation.cpp + LinearParameterAdaptation.cpp \ + RuleParser.cpp LOCAL_MODULE:= libparameter diff --git a/parameter/CompoundRule.cpp b/parameter/CompoundRule.cpp index 6078a2d..e78a5df 100644 --- a/parameter/CompoundRule.cpp +++ b/parameter/CompoundRule.cpp @@ -29,9 +29,16 @@ * </auto_header> */ #include "CompoundRule.h" +#include "RuleParser.h" #define base CRule +// Types +const char* CCompoundRule::_apcTypes[2] = { + "Any", + "All" +}; + CCompoundRule::CCompoundRule() : _bTypeAll(false) { } @@ -48,6 +55,68 @@ bool CCompoundRule::childrenAreDynamic() const return true; } +// Content dumping +void CCompoundRule::logValue(string& strValue, CErrorContext& errorContext) const +{ + (void)errorContext; + + // Type + strValue = _apcTypes[_bTypeAll]; +} + +// Parse +bool CCompoundRule::parse(CRuleParser& ruleParser, string& strError) +{ + // Get rule type + uint32_t uiType; + + for (uiType = 0; uiType < 2; uiType++) { + + if (ruleParser.getType() == _apcTypes[uiType]) { + + // Set type + _bTypeAll = uiType != 0; + + return true; + } + } + + // Failed + strError = "Unknown compound rule type: "; + strError += ruleParser.getType(); + + return false; +} + +// Dump +void CCompoundRule::dump(string& strResult) const +{ + strResult += _apcTypes[_bTypeAll]; + strResult += "{"; + + // Children + uint32_t uiChild; + uint32_t uiNbChildren = getNbChildren(); + bool bFirst = true; + + for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { + + if (!bFirst) { + + strResult += ", "; + } + + // Dump inner rule + const CRule* pRule = static_cast<const CRule*>(getChild(uiChild)); + + pRule->dump(strResult); + + bFirst = false; + } + + strResult += "}"; +} + // Rule check bool CCompoundRule::matches() const { @@ -70,7 +139,7 @@ bool CCompoundRule::matches() const bool CCompoundRule::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Get type - _bTypeAll = xmlElement.getAttributeBoolean("Type", "All"); + _bTypeAll = xmlElement.getAttributeBoolean("Type", _apcTypes[true]); // Base return base::fromXml(xmlElement, serializingContext); @@ -80,7 +149,7 @@ bool CCompoundRule::fromXml(const CXmlElement& xmlElement, CXmlSerializingContex void CCompoundRule::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Set type - xmlElement.setAttributeString("Type", _bTypeAll ? "All" : "Any"); + xmlElement.setAttributeString("Type", _apcTypes[_bTypeAll]); // Base base::toXml(xmlElement, serializingContext); diff --git a/parameter/CompoundRule.h b/parameter/CompoundRule.h index 9012a05..8d978fc 100644 --- a/parameter/CompoundRule.h +++ b/parameter/CompoundRule.h @@ -37,6 +37,12 @@ class CCompoundRule : public CRule public: CCompoundRule(); + // Parse + virtual bool parse(CRuleParser& ruleParser, string& strError); + + // Dump + virtual void dump(string& strResult) const; + // Rule check virtual bool matches() const; @@ -48,10 +54,16 @@ public: // Class kind virtual string getKind() const; +protected: + // Content dumping + virtual void logValue(string& strValue, CErrorContext& errorContext) const; private: // Returns true if children dynamic creation is to be dealt with virtual bool childrenAreDynamic() const; // Type bool _bTypeAll; + + // Types + static const char* _apcTypes[]; }; diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index 696bbd0..4c6541f 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -73,6 +73,24 @@ bool CConfigurableDomain::childrenAreDynamic() const return true; } +// Content dumping +void CConfigurableDomain::logValue(string& strValue, CErrorContext& errorContext) const +{ + (void)errorContext; + + strValue = "{"; + + // Sequence awareness + strValue += "Sequence aware: "; + strValue += _bSequenceAware ? "yes" : "no"; + + // Last applied configuration + strValue += ", Last applied configuration: "; + strValue += _pLastAppliedConfiguration ? _pLastAppliedConfiguration->getName() : "<none>"; + + strValue += "}"; +} + // Sequence awareness void CConfigurableDomain::setSequenceAwareness(bool bSequenceAware) { @@ -460,25 +478,6 @@ bool CConfigurableDomain::isApplicableConfigurationValid(const CConfigurableElem return pApplicableDomainConfiguration && pApplicableDomainConfiguration->isValid(pConfigurableElement); } -// Presence of application condition on any configuration -bool CConfigurableDomain::hasRules() const -{ - // Delegate to configurations - uint32_t uiNbConfigurations = getNbChildren(); - uint32_t uiChild; - - for (uiChild = 0; uiChild < uiNbConfigurations; uiChild++) { - - const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(getChild(uiChild)); - - if (pDomainConfiguration->hasRule()) { - - return true; - } - } - return false; -} - // In case configurable element was removed void CConfigurableDomain::computeSyncSet() { @@ -541,20 +540,10 @@ bool CConfigurableDomain::createConfiguration(const string& strName, const CPara bool CConfigurableDomain::deleteConfiguration(const string& strName, string& strError) { - CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strName)); + CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); if (!pDomainConfiguration) { - strError = "Configuration not found"; - - return false; - } - - // Check configuration has no rule (prevent accidental loss of data) - if (pDomainConfiguration->hasRule()) { - - strError = "Deletion of configuration containing application rules is not supported to prevent any accitental loss of data.\nPlease consider a direct modification of the XML file."; - return false; } @@ -593,12 +582,10 @@ void CConfigurableDomain::listAssociatedToElements(string& strResult) const bool CConfigurableDomain::renameConfiguration(const string& strName, const string& strNewName, string& strError) { - CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strName)); + CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); if (!pDomainConfiguration) { - strError = "Configuration not found"; - return false; } log("Renaming domain \"%s\"'s configuration \"%s\" to \"%s\"", getName().c_str(), strName.c_str(), strNewName.c_str()); @@ -607,15 +594,12 @@ bool CConfigurableDomain::renameConfiguration(const string& strName, const strin return pDomainConfiguration->rename(strNewName, strError); } -bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError) +bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError) const { - // Find Domain configuration - const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strName)); + const CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); if (!pDomainConfiguration) { - strError = "Domain configuration " + strName + " not found"; - return false; } log("Restoring domain \"%s\"'s configuration \"%s\" to parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); @@ -636,12 +620,10 @@ bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameter bool CConfigurableDomain::saveConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError) { // Find Domain configuration - CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strName)); + CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); if (!pDomainConfiguration) { - strError = "Domain configuration " + strName + " not found"; - return false; } log("Saving domain \"%s\"'s configuration \"%s\" from parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); @@ -652,15 +634,13 @@ bool CConfigurableDomain::saveConfiguration(const string& strName, const CParame return true; } -bool CConfigurableDomain::setElementSequence(const string& strName, const vector<string>& astrNewElementSequence, string& strError) +bool CConfigurableDomain::setElementSequence(const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError) { // Find Domain configuration - CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strName)); + CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); if (!pDomainConfiguration) { - strError = "Domain configuration " + strName + " not found"; - return false; } @@ -668,15 +648,13 @@ bool CConfigurableDomain::setElementSequence(const string& strName, const vector return pDomainConfiguration->setElementSequence(astrNewElementSequence, strError); } -bool CConfigurableDomain::getElementSequence(const string& strName, string& strResult) const +bool CConfigurableDomain::getElementSequence(const string& strConfiguration, string& strResult) const { // Find Domain configuration - const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strName)); + const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult); if (!pDomainConfiguration) { - strResult = "Domain configuration " + strName + " not found"; - return false; } @@ -686,6 +664,52 @@ bool CConfigurableDomain::getElementSequence(const string& strName, string& strR return true; } +bool CConfigurableDomain::setApplicationRule(const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) +{ + // Find Domain configuration + CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); + + if (!pDomainConfiguration) { + + return false; + } + + // Delegate to configuration + return pDomainConfiguration->setApplicationRule(strApplicationRule, pSelectionCriteriaDefinition, strError); +} + +bool CConfigurableDomain::clearApplicationRule(const string& strConfiguration, string& strError) +{ + // Find Domain configuration + CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); + + if (!pDomainConfiguration) { + + return false; + } + + // Delegate to configuration + pDomainConfiguration->clearApplicationRule(); + + return true; +} + +bool CConfigurableDomain::getApplicationRule(const string& strConfiguration, string& strResult) const +{ + // Find Domain configuration + const CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strResult); + + if (!pDomainConfiguration) { + + return false; + } + + // Delegate to configuration + pDomainConfiguration->getApplicationRule(strResult); + + return true; +} + // Last applied configuration string CConfigurableDomain::getLastAppliedConfigurationName() const { @@ -983,3 +1007,30 @@ CSyncerSet* CConfigurableDomain::getSyncerSet(const CConfigurableElement* pConfi return mapIt->second; } + +// Configuration retrieval +CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError) +{ + CDomainConfiguration* pDomainConfiguration = static_cast<CDomainConfiguration*>(findChild(strConfiguration)); + + if (!pDomainConfiguration) { + + strError = "Domain configuration " + strConfiguration + " not found"; + + return NULL; + } + return pDomainConfiguration; +} + +const CDomainConfiguration* CConfigurableDomain::findConfiguration(const string& strConfiguration, string& strError) const +{ + const CDomainConfiguration* pDomainConfiguration = static_cast<const CDomainConfiguration*>(findChild(strConfiguration)); + + if (!pDomainConfiguration) { + + strError = "Domain configuration " + strConfiguration + " not found"; + + return NULL; + } + return pDomainConfiguration; +} diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index 87ed41c..ac3c5c9 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -39,6 +39,7 @@ class CConfigurableElement; class CDomainConfiguration; class CParameterBlackboard; +class CSelectionCriteriaDefinition; class CConfigurableDomain : public CBinarySerializableElement { @@ -56,10 +57,13 @@ public: bool createConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError); bool deleteConfiguration(const string& strName, string& strError); bool renameConfiguration(const string& strName, const string& strNewName, string& strError); - bool restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError); + bool restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError) const; bool saveConfiguration(const string& strName, const CParameterBlackboard* pMainBlackboard, string& strError); - bool setElementSequence(const string& strName, const vector<string>& astrNewElementSequence, string& strError); - bool getElementSequence(const string& strName, string& strResult) const; + bool setElementSequence(const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError); + bool getElementSequence(const string& strConfiguration, string& strResult) const; + bool setApplicationRule(const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError); + bool clearApplicationRule(const string& strConfiguration, string& strError); + bool getApplicationRule(const string& strConfiguration, string& strResult) const; // Last applied configuration string getLastAppliedConfigurationName() const; @@ -84,9 +88,6 @@ public: // Return applicable configuration validity for given configurable element bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const; - // Presence of application condition on any configuration - bool hasRules() const; - // From IXmlSink virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); @@ -95,6 +96,9 @@ public: // Class kind virtual string getKind() const; +protected: + // Content dumping + virtual void logValue(string& strValue, CErrorContext& errorContext) const; private: // Returns true if children dynamic creation is to be dealt with (here, will allow child deletion upon clean) virtual bool childrenAreDynamic() const; @@ -144,6 +148,10 @@ private: // Syncer set retrieval from configurable element CSyncerSet* getSyncerSet(const CConfigurableElement* pConfigurableElement) const; + // Configuration retrieval + CDomainConfiguration* findConfiguration(const string& strConfiguration, string& strError); + const CDomainConfiguration* findConfiguration(const string& strConfiguration, string& strError) const; + // Configurable elements list<CConfigurableElement*> _configurableElementList; diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index d021d8c..28611d3 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -139,20 +139,10 @@ bool CConfigurableDomains::createDomain(const string& strName, string& strError) bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) { - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strName)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); if (!pConfigurableDomain) { - strError = "Configurable domain not found"; - - return false; - } - - // Check domain has no rule (prevent accidental loss of data) - if (pConfigurableDomain->hasRules()) { - - strError = "Deletion of domain containing configurations with application rules is not supported to prevent any accitental loss of data.\nPlease consider a direct modification of the XML file."; - return false; } @@ -169,12 +159,10 @@ bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) bool CConfigurableDomains::renameDomain(const string& strName, const string& strNewName, string& strError) { - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strName)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); if (!pConfigurableDomain) { - strError = "Configurable domain not found"; - return false; } @@ -186,12 +174,10 @@ bool CConfigurableDomains::renameDomain(const string& strName, const string& str bool CConfigurableDomains::setSequenceAwareness(const string& strDomain, bool bSequenceAware, string& strError) { - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain not found"; - return false; } @@ -202,12 +188,10 @@ bool CConfigurableDomains::setSequenceAwareness(const string& strDomain, bool bS bool CConfigurableDomains::getSequenceAwareness(const string& strDomain, bool& bSequenceAware, string& strError) const { - const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain)); + const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain not found"; - return false; } @@ -219,12 +203,10 @@ bool CConfigurableDomains::getSequenceAwareness(const string& strDomain, bool& b /// Configurations bool CConfigurableDomains::listConfigurations(const string& strDomain, string& strResult) const { - const CElement* pConfigurableDomain = findChild(strDomain); + const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); if (!pConfigurableDomain) { - strResult = "Configurable domain not found"; - return false; } // delegate @@ -236,12 +218,10 @@ bool CConfigurableDomains::listConfigurations(const string& strDomain, string& s bool CConfigurableDomains::createConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -251,12 +231,10 @@ bool CConfigurableDomains::createConfiguration(const string& strDomain, const st bool CConfigurableDomains::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -266,12 +244,10 @@ bool CConfigurableDomains::deleteConfiguration(const string& strDomain, const st bool CConfigurableDomains::renameConfiguration(const string& strDomain, const string& strConfigurationName, const string& strNewConfigurationName, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -281,12 +257,10 @@ bool CConfigurableDomains::renameConfiguration(const string& strDomain, const st bool CConfigurableDomains::listDomainElements(const string& strDomain, string& strResult) const { // Find domain - const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain)); + const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); if (!pConfigurableDomain) { - strResult = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -298,12 +272,10 @@ bool CConfigurableDomains::listDomainElements(const string& strDomain, string& s bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -403,15 +375,13 @@ void CConfigurableDomains::gatherAllOwnedConfigurableElements(set<const CConfigu } // Config restore -bool CConfigurableDomains::restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError) +bool CConfigurableDomains::restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError) const { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -422,12 +392,10 @@ bool CConfigurableDomains::restoreConfiguration(const string& strDomain, const s bool CConfigurableDomains::saveConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -437,12 +405,10 @@ bool CConfigurableDomains::saveConfiguration(const string& strDomain, const stri bool CConfigurableDomains::setElementSequence(const string& strDomain, const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } @@ -453,18 +419,55 @@ bool CConfigurableDomains::setElementSequence(const string& strDomain, const str bool CConfigurableDomains::getElementSequence(const string& strDomain, const string& strConfiguration, string& strResult) const { // Find domain - const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain)); + const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); if (!pConfigurableDomain) { - strResult = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate to domain return pConfigurableDomain->getElementSequence(strConfiguration, strResult); } +bool CConfigurableDomains::setApplicationRule(const string& strDomain, const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) +{ + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + + if (!pConfigurableDomain) { + + return false; + } + + // Delegate to domain + return pConfigurableDomain->setApplicationRule(strConfiguration, strApplicationRule, pSelectionCriteriaDefinition, strError); +} + +bool CConfigurableDomains::clearApplicationRule(const string& strDomain, const string& strConfiguration, string& strError) +{ + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + + if (!pConfigurableDomain) { + + return false; + } + + // Delegate to domain + return pConfigurableDomain->clearApplicationRule(strConfiguration, strError); +} + +bool CConfigurableDomains::getApplicationRule(const string& strDomain, const string& strConfiguration, string& strResult) const +{ + const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strResult); + + if (!pConfigurableDomain) { + + return false; + } + + // Delegate to domain + return pConfigurableDomain->getApplicationRule(strConfiguration, strResult); +} + // Last applied configurations void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) const { @@ -484,12 +487,10 @@ void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) cons bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -499,12 +500,10 @@ bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomai bool CConfigurableDomains::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) { // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); if (!pConfigurableDomain) { - strError = "Configurable domain " + strDomain + " not found"; - return false; } // Delegate @@ -533,3 +532,34 @@ bool CConfigurableDomains::serializeSettings(const string& strBinarySettingsFile return true; } + +// Domain retrieval +CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) +{ + // Find domain + CConfigurableDomain* pConfigurableDomain = static_cast<CConfigurableDomain*>(findChild(strDomain)); + + if (!pConfigurableDomain) { + + strError = "Configurable domain " + strDomain + " not found"; + + return NULL; + } + + return pConfigurableDomain; +} + +const CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) const +{ + // Find domain + const CConfigurableDomain* pConfigurableDomain = static_cast<const CConfigurableDomain*>(findChild(strDomain)); + + if (!pConfigurableDomain) { + + strError = "Configurable domain " + strDomain + " not found"; + + return NULL; + } + + return pConfigurableDomain; +} diff --git a/parameter/ConfigurableDomains.h b/parameter/ConfigurableDomains.h index 8b62d0f..262d900 100644 --- a/parameter/ConfigurableDomains.h +++ b/parameter/ConfigurableDomains.h @@ -36,6 +36,8 @@ class CParameterBlackboard; class CConfigurableElement; class CSyncerSet; +class CConfigurableDomain; +class CSelectionCriteriaDefinition; class CConfigurableDomains : public CBinarySerializableElement { @@ -59,10 +61,13 @@ public: bool createConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError); bool deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError); bool renameConfiguration(const string& strDomain, const string& strConfigurationName, const string& strNewConfigurationName, string& strError); - bool restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError); + bool restoreConfiguration(const string& strDomain, const string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, string& strError) const; bool saveConfiguration(const string& strDomain, const string& strConfiguration, const CParameterBlackboard* pMainBlackboard, string& strError); bool setElementSequence(const string& strDomain, const string& strConfiguration, const vector<string>& astrNewElementSequence, string& strError); bool getElementSequence(const string& strDomain, const string& strConfiguration, string& strResult) const; + bool setApplicationRule(const string& strDomain, const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError); + bool clearApplicationRule(const string& strDomain, const string& strConfiguration, string& strError); + bool getApplicationRule(const string& strDomain, const string& strConfiguration, string& strResult) const; // Last applied configurations void listLastAppliedConfigurations(string& strResult) const; @@ -90,5 +95,8 @@ private: virtual bool childrenAreDynamic() const; // Gather owned configurable elements owned by any domain void gatherAllOwnedConfigurableElements(set<const CConfigurableElement*>& configurableElementSet) const; + // Domain retrieval + CConfigurableDomain* findConfigurableDomain(const string& strDomain, string& strError); + const CConfigurableDomain* findConfigurableDomain(const string& strDomain, string& strError) const; }; diff --git a/parameter/DomainConfiguration.cpp b/parameter/DomainConfiguration.cpp index b30c8e3..f746be9 100644 --- a/parameter/DomainConfiguration.cpp +++ b/parameter/DomainConfiguration.cpp @@ -36,6 +36,7 @@ #include "XmlDomainSerializingContext.h" #include "ConfigurationAccessContext.h" #include <assert.h> +#include "RuleParser.h" #define base CBinarySerializableElement @@ -282,6 +283,47 @@ void CDomainConfiguration::getElementSequence(string& strResult) const } } +// Application rule +bool CDomainConfiguration::setApplicationRule(const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) +{ + // Parser + CRuleParser ruleParser(strApplicationRule, pSelectionCriteriaDefinition); + + // Attempt to parse it + if (!ruleParser.parse(NULL, strError)) { + + return false; + } + // Replace compound rule + setRule(ruleParser.grabRootRule()); + + return true; +} + +void CDomainConfiguration::clearApplicationRule() +{ + // Replace compound rule + setRule(NULL); +} + +void CDomainConfiguration::getApplicationRule(string& strResult) const +{ + // Rule + const CCompoundRule* pRule = getRule(); + + if (pRule) { + // Start clear + strResult.clear(); + + // Dump rule + pRule->dump(strResult); + + } else { + + strResult = "<none>"; + } +} + // Save data from current void CDomainConfiguration::save(const CParameterBlackboard* pMainBlackboard) { @@ -518,12 +560,6 @@ CAreaConfiguration* CDomainConfiguration::getAreaConfiguration(uint32_t uiAreaCo return NULL; } -// Presence of application condition -bool CDomainConfiguration::hasRule() const -{ - return !!getRule(); -} - // Rule const CCompoundRule* CDomainConfiguration::getRule() const { @@ -534,6 +570,33 @@ const CCompoundRule* CDomainConfiguration::getRule() const return NULL; } +CCompoundRule* CDomainConfiguration::getRule() +{ + if (getNbChildren()) { + // Rule created + return static_cast<CCompoundRule*>(getChild(ECompoundRule)); + } + return NULL; +} + +void CDomainConfiguration::setRule(CCompoundRule* pRule) +{ + CCompoundRule* pOldRule = getRule(); + + if (pOldRule) { + // Remove previous rule + removeChild(pOldRule); + + delete pOldRule; + } + + // Set new one + if (pRule) { + // Chain + addChild(pRule); + } +} + // Serialization void CDomainConfiguration::binarySerialize(CBinaryStream& binaryStream) { diff --git a/parameter/DomainConfiguration.h b/parameter/DomainConfiguration.h index 981ef77..40e1d4a 100644 --- a/parameter/DomainConfiguration.h +++ b/parameter/DomainConfiguration.h @@ -39,6 +39,7 @@ class CParameterBlackboard; class CConfigurationAccessContext; class CCompoundRule; class CSyncerSet; +class CSelectionCriteriaDefinition; class CDomainConfiguration : public CBinarySerializableElement { @@ -58,6 +59,11 @@ public: bool setElementSequence(const vector<string>& astrNewElementSequence, string& strError); void getElementSequence(string& strResult) const; + // Application rule + bool setApplicationRule(const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError); + void clearApplicationRule(); + void getApplicationRule(string& strResult) const; + // Save data from current void save(const CParameterBlackboard* pMainBlackboard); // Apply data to current @@ -83,9 +89,6 @@ public: bool parseSettings(CXmlElement& xmlConfigurationSettingsElement, CXmlSerializingContext& serializingContext); void composeSettings(CXmlElement& xmlConfigurationSettingsElement, CXmlSerializingContext& serializingContext) const; - // Presence of application condition - bool hasRule() const; - // Serialization virtual void binarySerialize(CBinaryStream& binaryStream); @@ -114,6 +117,8 @@ private: // Rule const CCompoundRule* getRule() const; + CCompoundRule* getRule(); + void setRule(CCompoundRule* pRule); // AreaConfigurations list<CAreaConfiguration*> _areaConfigurationList; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 66c8d9e..9a180fa 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -126,6 +126,7 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, "", "List selection criteria" }, /// Domains { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" }, + { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0, "", "Show all domains and configurations, including applicability conditions" }, { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" }, { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" }, { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" }, @@ -142,8 +143,11 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" }, { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" }, { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" }, - { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 2, "<domain> <configuration> <elem path list>", "Set element application order for configuration" }, + { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3, "<domain> <configuration> <elem path list>", "Set element application order for configuration" }, { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, "<domain> <configuration>", "Get element application order for configuration" }, + { "setRule", &CParameterMgr::setRuleCommmandProcess, 3, "<domain> <configuration> <rule>", "Set configuration application rule" }, + { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2, "<domain> <configuration>", "Clear configuration application rule" }, + { "getRule", &CParameterMgr::getRuleCommmandProcess, 2, "<domain> <configuration>", "Get configuration application rule" }, /// Elements/Parameters { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" }, { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, "<elem path>|/", "List parameters under element at given path or root" }, @@ -951,7 +955,21 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmand /// Configurations CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - return getConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; + return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; +} + +CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) +{ + (void)remoteCommand; + + // Dummy error context + string strError; + CErrorContext errorContext(strError); + + // Dump + getConstConfigurableDomains()->dumpContent(strResult, errorContext); + + return CCommandHandler::ESucceeded; } CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) @@ -1007,6 +1025,24 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceC return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; } +CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) +{ + // Delegate to configurable domains + return getConfigurableDomains()->setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), getConstSelectionCriteria()->getSelectionCriteriaDefinition(), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; +} + +CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) +{ + // Delegate to configurable domains + return getConfigurableDomains()->clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; +} + +CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) +{ + // Delegate to configurable domains + return getConfigurableDomains()->getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; +} + /// Elements/Parameters CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { @@ -1451,7 +1487,7 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& } // Delegate to configurable domains - return getConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError); + return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError); } bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError) diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 08c777b..da4e43f 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -82,7 +82,7 @@ class CParameterMgr : private CElement }; // Version static const uint32_t guiEditionMajor = 0x2; - static const uint32_t guiEditionMinor = 0x0; + static const uint32_t guiEditionMinor = 0x1; static const uint32_t guiRevision = 0x0; // Parameter handle friendship @@ -210,6 +210,7 @@ private: CCommandHandler::CommandStatus splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); /// Configurations CCommandHandler::CommandStatus listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); + CCommandHandler::CommandStatus dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); CCommandHandler::CommandStatus createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); CCommandHandler::CommandStatus deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); CCommandHandler::CommandStatus renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); @@ -217,6 +218,9 @@ private: CCommandHandler::CommandStatus restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); CCommandHandler::CommandStatus setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); CCommandHandler::CommandStatus getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); + CCommandHandler::CommandStatus setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); + CCommandHandler::CommandStatus clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); + CCommandHandler::CommandStatus getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); /// Elements/Parameters CCommandHandler::CommandStatus listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); CCommandHandler::CommandStatus listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult); diff --git a/parameter/Rule.h b/parameter/Rule.h index 95b9de3..de3d007 100644 --- a/parameter/Rule.h +++ b/parameter/Rule.h @@ -32,12 +32,20 @@ #include "Element.h" +class CRuleParser; + class CRule : public CElement { public: CRule(); + // Parse + virtual bool parse(CRuleParser& ruleParser, string& strError) = 0; + + // Dump + virtual void dump(string& strResult) const = 0; + // Rule check virtual bool matches() const = 0; }; diff --git a/parameter/RuleParser.cpp b/parameter/RuleParser.cpp new file mode 100644 index 0000000..b72556b --- /dev/null +++ b/parameter/RuleParser.cpp @@ -0,0 +1,252 @@ +/* <auto_header> + * <FILENAME> + * + * INTEL CONFIDENTIAL + * Copyright © 2011 Intel + * Corporation All Rights Reserved. + * + * The source code contained or described herein and all documents related to + * the source code ("Material") are owned by Intel Corporation or its suppliers + * or licensors. Title to the Material remains with Intel Corporation or its + * suppliers and licensors. The Material contains trade secrets and proprietary + * and confidential information of Intel or its suppliers and licensors. The + * Material is protected by worldwide copyright and trade secret laws and + * treaty provisions. No part of the Material may be used, copied, reproduced, + * modified, published, uploaded, posted, transmitted, distributed, or + * disclosed in any way without Intel’s prior express written permission. + * + * No license under any patent, copyright, trade secret or other intellectual + * property right is granted to or conferred upon you by disclosure or delivery + * of the Materials, either expressly, by implication, inducement, estoppel or + * otherwise. Any license under such intellectual property rights must be + * express and approved by Intel in writing. + * + * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) + * CREATED: 2011-06-01 + * UPDATED: 2011-07-27 + * + * + * </auto_header> + */ +#include "RuleParser.h" +#include "CompoundRule.h" +#include "SelectionCriterionRule.h" +#include <assert.h> + +// Matches +const char* CRuleParser::_acDelimiters[CRuleParser::ENbStatuses] = { + "{", // EInit + "{} ", // EBeginCompoundRule + ",}", // EEndCompoundRule + ",}", // ECriterionRule + "{ ", // EContinue + "" // EDone +}; + +CRuleParser::CRuleParser(const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition) : + _strApplicationRule(strApplicationRule), + _pSelectionCriteriaDefinition(pSelectionCriteriaDefinition), + _uiCurrentPos(0), + _uiCurrentDeepness(0), + _eStatus(CRuleParser::EInit), + _pRootRule(NULL) +{ +} + +CRuleParser::~CRuleParser() +{ + delete _pRootRule; +} + +// Parse +bool CRuleParser::parse(CCompoundRule* pParentRule, string& strError) +{ + while (true) { + // Iterate till next relevant delimiter + if (!iterate(strError)) { + + return false; + } + switch(_eStatus) { + case EBeginCompoundRule: { + + // Create new compound rule + CCompoundRule* pCompoundRule = new CCompoundRule; + + // Parse + if (!pCompoundRule->parse(*this, strError)) { + + delete pCompoundRule; + + return false; + } + // Parent rule creation context? + if (pParentRule) { + + // Chain + pParentRule->addChild(pCompoundRule); + } else { + // Root rule + delete _pRootRule; + _pRootRule = pCompoundRule; + } + // Parse + if (!parse(pCompoundRule, strError)) { + + return false; + } + // Go on + break; + } + case EEndCompoundRule: + return true; + case EContinue: + // Seek for new rule + break; + case ECriterionRule: { + // Create new criterion rule + CSelectionCriterionRule* pCriterionRule = new CSelectionCriterionRule; + + // Parse + if (!pCriterionRule->parse(*this, strError)) { + + delete pCriterionRule; + + return false; + } + + // Chain + pParentRule->addChild(pCriterionRule); + + // Go on + break; + } + case EDone: + return true; + default: + assert(0); + return false; + } + } + + return true; +} + +// Iterate +bool CRuleParser::iterate(string& strError) +{ + string::size_type iDelimiter; + + assert(_uiCurrentPos <= _strApplicationRule.length()); + + // Consume spaces + if ((iDelimiter = _strApplicationRule.find_first_not_of(" ", _uiCurrentPos)) != string::npos) { + + // New pos + _uiCurrentPos = iDelimiter; + } + + // Parse + if ((_uiCurrentPos != _strApplicationRule.length()) && ((iDelimiter = _strApplicationRule.find_first_of(_acDelimiters[_eStatus], _uiCurrentPos)) != string::npos)) { + + switch(_strApplicationRule[iDelimiter]) { + + case '{': + _eStatus = EBeginCompoundRule; + // Extract type + _strRuleType = _strApplicationRule.substr(_uiCurrentPos, iDelimiter - _uiCurrentPos); + _uiCurrentDeepness++; + break; + case '}': + _eStatus = EEndCompoundRule; + + if (!_uiCurrentDeepness--) { + + strError = "Missing opening brace"; + + return false; + } + break; + case ' ': + _eStatus = ECriterionRule; + // Extract type + _strRuleType = _strApplicationRule.substr(_uiCurrentPos, iDelimiter - _uiCurrentPos); + break; + case ',': + _eStatus = EContinue; + break; + } + // New pos + _uiCurrentPos = iDelimiter + 1; + } else { + + if (_uiCurrentDeepness) { + + strError = "Missing closing brace"; + + return false; + } + + // Remaining characters + if (_uiCurrentPos != _strApplicationRule.length()) { + + strError = "Syntax error"; + + return false; + } + // Done + _eStatus = EDone; + } + return true; +} + +// Rule type +const string& CRuleParser::getType() const +{ + return _strRuleType; +} + +// Criteria defintion +const CSelectionCriteriaDefinition* CRuleParser::getSelectionCriteriaDefinition() const +{ + return _pSelectionCriteriaDefinition; +} + +// Root rule +CCompoundRule* CRuleParser::grabRootRule() +{ + CCompoundRule* pRootRule = _pRootRule; + + assert(pRootRule); + + _pRootRule = NULL; + + return pRootRule; +} + +// Next word +bool CRuleParser::next(string& strNext, string& strError) +{ + string::size_type iDelimiter; + + // Consume spaces + if ((iDelimiter = _strApplicationRule.find_first_not_of(" ", _uiCurrentPos)) != string::npos) { + + // New pos + _uiCurrentPos = iDelimiter; + } + + if ((iDelimiter = _strApplicationRule.find_first_of("{} ,", _uiCurrentPos)) == string::npos) { + + strError = "Syntax error"; + + return false; + } + + strNext = _strApplicationRule.substr(_uiCurrentPos, iDelimiter - _uiCurrentPos); + + // New pos + _uiCurrentPos = iDelimiter; + + return true; +} diff --git a/parameter/RuleParser.h b/parameter/RuleParser.h new file mode 100644 index 0000000..c946c94 --- /dev/null +++ b/parameter/RuleParser.h @@ -0,0 +1,94 @@ +/* <auto_header> + * <FILENAME> + * + * INTEL CONFIDENTIAL + * Copyright © 2011 Intel + * Corporation All Rights Reserved. + * + * The source code contained or described herein and all documents related to + * the source code ("Material") are owned by Intel Corporation or its suppliers + * or licensors. Title to the Material remains with Intel Corporation or its + * suppliers and licensors. The Material contains trade secrets and proprietary + * and confidential information of Intel or its suppliers and licensors. The + * Material is protected by worldwide copyright and trade secret laws and + * treaty provisions. No part of the Material may be used, copied, reproduced, + * modified, published, uploaded, posted, transmitted, distributed, or + * disclosed in any way without Intel’s prior express written permission. + * + * No license under any patent, copyright, trade secret or other intellectual + * property right is granted to or conferred upon you by disclosure or delivery + * of the Materials, either expressly, by implication, inducement, estoppel or + * otherwise. Any license under such intellectual property rights must be + * express and approved by Intel in writing. + * + * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) + * CREATED: 2011-06-01 + * UPDATED: 2011-07-27 + * + * + * </auto_header> + */ +#pragma once + +#include <string> +#include <stdint.h> + +using namespace std; + +class CCompoundRule; +class CSelectionCriteriaDefinition; + +class CRuleParser +{ +public: + enum Status { + EInit, + EBeginCompoundRule, + EEndCompoundRule, + ECriterionRule, + EContinue, + EDone, + + ENbStatuses + }; + + CRuleParser(const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition); + ~CRuleParser(); + + // Parse + bool parse(CCompoundRule* pParentRule, string& strError); + + // Iterate + bool iterate(string& strError); + + // Next word + bool next(string& strNext, string& strError); + + // Rule type + const string& getType() const; + + // Criteria defintion + const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const; + + // Root rule + CCompoundRule* grabRootRule(); +private: + + // Rule definition + string _strApplicationRule; + // Criteria defintion + const CSelectionCriteriaDefinition* _pSelectionCriteriaDefinition; + // Iterator + uint32_t _uiCurrentPos; + // Deepness + uint32_t _uiCurrentDeepness; + // Current Type + string _strRuleType; + // Status + Status _eStatus; + // Root rule + CCompoundRule* _pRootRule; + // Matches + static const char* _acDelimiters[ENbStatuses]; +}; + diff --git a/parameter/SelectionCriterionRule.cpp b/parameter/SelectionCriterionRule.cpp index bb353bd..e25cc07 100644 --- a/parameter/SelectionCriterionRule.cpp +++ b/parameter/SelectionCriterionRule.cpp @@ -33,6 +33,7 @@ #include "XmlDomainSerializingContext.h" #include "SelectionCriteriaDefinition.h" #include "SelectionCriterionTypeInterface.h" +#include "RuleParser.h" #include <assert.h> #define base CRule @@ -54,6 +55,78 @@ string CSelectionCriterionRule::getKind() const return "SelectionCriterionRule"; } +// Content dumping +void CSelectionCriterionRule::logValue(string& strValue, CErrorContext& errorContext) const +{ + (void)errorContext; + + // Dump rule + dump(strValue); +} + +// Parse +bool CSelectionCriterionRule::parse(CRuleParser& ruleParser, string& strError) +{ + // Criterion + _pSelectionCriterion = ruleParser.getSelectionCriteriaDefinition()->getSelectionCriterion(ruleParser.getType()); + + // Check existence + if (!_pSelectionCriterion) { + + strError = "Couldn't find selection criterion " + ruleParser.getType(); + + return false; + } + + // Verb + string strMatchesWhen; + + if (!ruleParser.next(strMatchesWhen, strError)) { + + return false; + } + // Value + string strValue; + + if (!ruleParser.next(strValue, strError)) { + + return false; + } + + // Matches when + if (!setMatchesWhen(strMatchesWhen, strError)) { + + strError = "Verb error: " + strError; + + return false; + } + + // Value + if (!_pSelectionCriterion->getCriterionType()->getNumericalValue(strValue, _iMatchValue)) { + + strError = "Value error: " + strError; + + return false; + } + + return true; +} + +// Dump +void CSelectionCriterionRule::dump(string& strResult) const +{ + // Criterion + strResult += _pSelectionCriterion->getName(); + strResult += " "; + // Verb + strResult += _astMatchesWhen[_eMatchesWhen].pcMatchesWhen; + strResult += " "; + // Value + string strValue; + _pSelectionCriterion->getCriterionType()->getLiteralValue(_iMatchValue, strValue); + strResult += strValue; +} + // Rule check bool CSelectionCriterionRule::matches() const { diff --git a/parameter/SelectionCriterionRule.h b/parameter/SelectionCriterionRule.h index 0efa89d..07dd022 100644 --- a/parameter/SelectionCriterionRule.h +++ b/parameter/SelectionCriterionRule.h @@ -55,6 +55,12 @@ class CSelectionCriterionRule : public CRule public: CSelectionCriterionRule(); + // Parse + virtual bool parse(CRuleParser& ruleParser, string& strError); + + // Dump + virtual void dump(string& strResult) const; + // Rule check virtual bool matches() const; @@ -66,6 +72,9 @@ public: // Class kind virtual string getKind() const; +protected: + // Content dumping + virtual void logValue(string& strValue, CErrorContext& errorContext) const; private: // XML MatchesWhen attribute parsing bool setMatchesWhen(const string& strMatchesWhen, string& strError); |