Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions parameter/BaseIntegerParameterType.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2016, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <sstream>
#include <iomanip>

#include "BaseIntegerParameterType.h"
#include "ParameterAccessContext.h"
#include "ParameterAdaptation.h"

// Kind
std::string CBaseIntegerParameterType::getKind() const
{
return "IntegerParameter";
}

// Deal with adaption node
bool CBaseIntegerParameterType::childrenAreDynamic() const
{
return true;
}

bool CBaseIntegerParameterType::fromBlackboard(uint32_t &uiUserValue, uint32_t uiValue,
CParameterAccessContext & /*ctx*/) const
{
// Do assign
uiUserValue = uiValue;

return true;
}
bool CBaseIntegerParameterType::fromBlackboard(int32_t &iUserValue, uint32_t uiValue,
CParameterAccessContext & /*ctx*/) const
{
int32_t iValue = uiValue;

// Sign extend
signExtend(iValue);

// Do assign
iUserValue = iValue;

return true;
}
// Adaptation element retrieval
const CParameterAdaptation *CBaseIntegerParameterType::getParameterAdaptation() const
{
return static_cast<const CParameterAdaptation *>(findChildOfKind("Adaptation"));
}
71 changes: 71 additions & 0 deletions parameter/BaseIntegerParameterType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2016, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

#include "ParameterType.h"

#include <string>

class CParameterAdaptation;

/** Base class for CIntegerParameterType
*
* CIntegerParameterType is template - this class Contains the parts that do
* not depend on template arguments in order to make the implementation more
* consise.
*/
class CBaseIntegerParameterType : public CParameterType
{
public:
CBaseIntegerParameterType(const std::string &name) : CParameterType(name){};

// CElement
std::string getKind() const override;

bool fromBlackboard(uint32_t &uiUserValue, uint32_t uiValue,
CParameterAccessContext &parameterAccessContext) const override;
bool fromBlackboard(int32_t &iUserValue, uint32_t uiValue,
CParameterAccessContext &parameterAccessContext) const override;
bool fromBlackboard(double &dUserValue, uint32_t uiValue,
CParameterAccessContext &parameterAccessContext) const override
{
return CParameterType::fromBlackboard(dUserValue, uiValue, parameterAccessContext);
}
bool fromBlackboard(std::string &strValue, const uint32_t &value,
CParameterAccessContext &parameterAccessContext) const override = 0;

protected:
// Adaptation element retrieval
const CParameterAdaptation *getParameterAdaptation() const;

private:
// Returns true if children dynamic creation is to be dealt with
bool childrenAreDynamic() const override;
};
2 changes: 1 addition & 1 deletion parameter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ add_library(parameter SHARED
${parameter_OS_SPECIFIC_SRCS}
AreaConfiguration.cpp
ArrayParameter.cpp
BaseIntegerParameterType.cpp
BaseParameter.cpp
BitParameterBlock.cpp
BitParameterBlockType.cpp
Expand Down Expand Up @@ -66,7 +67,6 @@ add_library(parameter SHARED
HardwareBackSynchronizer.cpp
InstanceConfigurableElement.cpp
InstanceDefinition.cpp
IntegerParameterType.cpp
LinearParameterAdaptation.cpp
LogarithmicParameterAdaptation.cpp
LoggingElementBuilderTemplate.cpp
Expand Down
8 changes: 6 additions & 2 deletions parameter/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "XmlElementSerializingContext.h"
#include "ElementLibrary.h"
#include "ErrorContext.hpp"
#include "PfError.hpp"
#include <algorithm>
#include <assert.h>
#include <stdio.h>
Expand Down Expand Up @@ -140,8 +141,8 @@ string CElement::logValue(utility::ErrorContext & /*ctx*/) const
}

// From IXmlSink
bool CElement::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext)
{
bool CElement::fromXml(const CXmlElement &xmlElement,
CXmlSerializingContext &serializingContext) try {
xmlElement.getAttribute(gDescriptionPropertyName, _strDescription);

// Propagate through children
Expand Down Expand Up @@ -183,6 +184,9 @@ bool CElement::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &se
}

return true;
} catch (const PfError &e) {
serializingContext.appendLineToError(e.what());
return false;
}

void CElement::childrenToXml(CXmlElement &xmlElement,
Expand Down
73 changes: 73 additions & 0 deletions parameter/IntegerParameterBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2016, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

#include "ElementBuilder.h"
#include "IntegerParameterType.h"

/** Specialized element builder for IntegerParameterType
*
* Dispatch to the correct template instance according to the signedness and
* size.
*/
class IntegerParameterBuilder : public CElementBuilder
{
public:
CElement *createElement(const CXmlElement &xmlElement) const override
{
size_t sizeInBits;
sizeInBits = xmlElement.getAttribute("Size", sizeInBits) ? sizeInBits : 32;

bool isSigned = false;
xmlElement.getAttribute("Signed", isSigned);

auto name = xmlElement.getNameAttribute();

switch (sizeInBits) {
case 8:
if (isSigned) {
return new CIntegerParameterType<true, 8>(name);
}
return new CIntegerParameterType<false, 8>(name);
case 16:
if (isSigned) {
return new CIntegerParameterType<true, 16>(name);
}
return new CIntegerParameterType<false, 16>(name);
case 32:
if (isSigned) {
return new CIntegerParameterType<true, 32>(name);
}
return new CIntegerParameterType<false, 32>(name);
default:
return nullptr;
}
}
};
Loading