Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
93 changes: 93 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright (c) 2015, 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.

---
# The extra indent or outdent of access modifiers
AccessModifierOffset: -4

# Align parameters on the open bracket
AlignAfterOpenBracket: Align

# Disallows contracting simple braced statements to a single line
AllowShortBlocksOnASingleLine: 'false'

# Short case labels wont't be contracted to a single line
AllowShortCaseLabelsOnASingleLine: 'false'

# Merge all inline functions fitting on a single line
AllowShortFunctionsOnASingleLine: 'Inline'

# If (a) return; cannot be put on a single line
AllowShortIfStatementsOnASingleLine: 'false'

# While (true) continue; cannot be put on a single line
AllowShortLoopsOnASingleLine: 'false'

# Break after the template<...> of a template declaration.
AlwaysBreakTemplateDeclarations: 'true'

# Configure each individual brace in BraceWrapping
BreakBeforeBraces: 'Custom'

# Control of individual brace wrapping cases
BraceWrapping: {
AfterClass: 'true'
AfterControlStatement: 'false'
AfterEnum : 'true'
AfterFunction : 'true'
AfterNamespace : 'true'
AfterStruct : 'true'
AfterUnion : 'true'
BeforeCatch : 'false'
BeforeElse : 'false'
IndentBraces : 'false'
}

# The column limit
ColumnLimit: '100'

# The number of columns to use for indentation.
IndentWidth: '4'

# Targeted language
Language: Cpp

# No indentation for namespaces.
NamespaceIndentation: None

# Pointer is aligned to right side
PointerAlignment: Right

# High penalty to avoid line break just after return type
PenaltyReturnTypeOnItsOwnLine: 10000

# Treat 'catch' BDD macros as control instructions
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, GIVEN, WHEN, AND_WHEN, THEN, AND_THEN,
SECTION ]

...
64 changes: 38 additions & 26 deletions bindings/c/ParameterFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ using std::string;
/** Rename long pfw types to short ones in pfw namespace. */
namespace pfw
{
typedef ISelectionCriterionInterface Criterion;
typedef std::map<string, Criterion *> Criteria;
typedef CParameterMgrPlatformConnector Pfw;
typedef ISelectionCriterionInterface Criterion;
typedef std::map<string, Criterion *> Criteria;
typedef CParameterMgrPlatformConnector Pfw;
}

/** Class to abstract the boolean+string status api. */
Expand All @@ -59,16 +59,27 @@ class Status
/** Fail without an instance of status. */
static bool failure() { return false; }
/** Fail with the given error msg. */
bool failure(const string &msg) { mMsg = msg; return false; }
bool failure(const string &msg)
{
mMsg = msg;
return false;
}
/** Success (no error message). */
bool success() { mMsg.clear(); return true; }
bool success()
{
mMsg.clear();
return true;
}

/** Forward a status operation.
* @param success[in] the operaton status to forward
* or forward a previous failure if omitted
*/
bool forward(bool success = false) {
if (success) { mMsg.clear(); }
bool forward(bool success = false)
{
if (success) {
mMsg.clear();
}
return success;
}
/** Error message accessors.
Expand All @@ -87,7 +98,8 @@ class Status
///////////////////////////////

/** Default log callback. Log to cout or cerr depending on level. */
static void defaultLogCb(void *, PfwLogLevel level, const char *logLine) {
static void defaultLogCb(void *, PfwLogLevel level, const char *logLine)
{
switch (level) {
case pfwLogInfo:
std::cout << logLine << std::endl;
Expand All @@ -98,7 +110,7 @@ static void defaultLogCb(void *, PfwLogLevel level, const char *logLine) {
};
}

static PfwLogger defaultLogger = { NULL, &defaultLogCb };
static PfwLogger defaultLogger = {NULL, &defaultLogCb};

class LogWrapper : public CParameterMgrPlatformConnector::ILogger
{
Expand All @@ -109,7 +121,7 @@ class LogWrapper : public CParameterMgrPlatformConnector::ILogger
private:
void info(const string &msg) override { log(pfwLogInfo, msg); }

void warning(const string &msg) override { log(pfwLogWarning, msg); }
void warning(const string &msg) override { log(pfwLogWarning, msg); }

void log(PfwLogLevel level, const string &strLog)
{
Expand Down Expand Up @@ -137,6 +149,7 @@ struct PfwHandler_ : private utility::NonCopyable
* Is mutable because even a const function can fail.
*/
mutable Status lastStatus;

private:
LogWrapper mLogger;
};
Expand All @@ -161,7 +174,6 @@ void PfwHandler::setLogger(const PfwLogger *logger)
pfw->setLogger(&mLogger);
}


bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t criterionNb)
{
Status &status = lastStatus;
Expand All @@ -176,8 +188,7 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite
}
// Check that the criterion does not exist
if (criteria.find(criterion.name) != criteria.end()) {
return status.failure("Criterion \"" + string(criterion.name) +
"\" already exist");
return status.failure("Criterion \"" + string(criterion.name) + "\" already exist");
}

// Create criterion type
Expand All @@ -189,15 +200,15 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite
int value;
if (criterion.inclusive) {
// Check that (int)1 << valueIndex would not overflow (UB)
if(std::numeric_limits<int>::max() >> valueIndex == 0) {
if (std::numeric_limits<int>::max() >> valueIndex == 0) {
return status.failure("Too many values for criterion " +
string(criterion.name));
}
value = 1 << valueIndex;
} else {
value = static_cast<int>(valueIndex);
}
const char * valueName = criterion.values[valueIndex];
const char *valueName = criterion.values[valueIndex];
string error;
if (not type->addValuePair(value, valueName, error)) {
return status.failure("Could not add value " + string(valueName) +
Expand All @@ -210,10 +221,8 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite
return status.success();
}


bool pfwStart(PfwHandler *handle, const char *configPath,
const PfwCriterion criteria[], size_t criterionNb,
const PfwLogger *logger)
bool pfwStart(PfwHandler *handle, const char *configPath, const PfwCriterion criteria[],
size_t criterionNb, const PfwLogger *logger)
{
// Check that the api is correctly used
Status &status = handle->lastStatus;
Expand All @@ -238,8 +247,7 @@ const char *pfwGetLastError(const PfwHandler *handle)
return handle->lastStatus.msg().c_str();
}

static pfw::Criterion *getCriterion(const pfw::Criteria &criteria,
const string &name)
static pfw::Criterion *getCriterion(const pfw::Criteria &criteria, const string &name)
{
pfw::Criteria::const_iterator it = criteria.find(name);
return it == criteria.end() ? NULL : it->second;
Expand Down Expand Up @@ -300,7 +308,8 @@ PfwParameterHandler *pfwBindParameter(PfwHandler *handle, const char path[])
Status &status = handle->lastStatus;
if (handle->pfw == NULL) {
status.failure("The parameter framework is not started, "
"while trying to bind parameter \"" + string(path) + "\")");
"while trying to bind parameter \"" +
string(path) + "\")");
return NULL;
}

Expand All @@ -321,7 +330,6 @@ void pfwUnbindParameter(PfwParameterHandler *handle)
delete handle;
}


bool pfwGetIntParameter(const PfwParameterHandler *handle, int32_t *value)
{
Status &status = handle->pfw.lastStatus;
Expand All @@ -339,7 +347,9 @@ bool pfwGetStringParameter(const PfwParameterHandler *handle, char *value[])
*value = NULL;
string retValue;
bool success = handle->parameter.getAsString(retValue, status.msg());
if (not success) { return status.forward(); }
if (not success) {
return status.forward();
}

*value = strdup(retValue.c_str());
return status.success();
Expand All @@ -351,5 +361,7 @@ bool pfwSetStringParameter(PfwParameterHandler *handle, const char value[])
return status.forward(handle->parameter.setAsString(value, status.msg()));
}

void pfwFree(void *ptr) { std::free(ptr); }

void pfwFree(void *ptr)
{
std::free(ptr);
}
39 changes: 20 additions & 19 deletions bindings/c/ParameterFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#pragma once


#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -53,17 +52,17 @@ extern "C" {
* Such arguments are marked NONNULL.
*/
#if defined(__clang__) || defined(__GNUC__)
# define NONNULL __attribute__((nonnull))
# define NONNULL_(...) __attribute__((nonnull (__VA_ARGS__)))
# define USERESULT __attribute__((warn_unused_result))
#define NONNULL __attribute__((nonnull))
#define NONNULL_(...) __attribute__((nonnull(__VA_ARGS__)))
#define USERESULT __attribute__((warn_unused_result))
#elif defined(_MSC_VER)
// In visual studio's cl there is no
// equivalent of nonnull
# define NONNULL
# define NONNULL_(...)
# define USERESULT _Check_return_
// In visual studio's cl there is no
// equivalent of nonnull
#define NONNULL
#define NONNULL_(...)
#define USERESULT _Check_return_
#else
# error "Unknown compilator"
#error "Unknown compilator"
#endif

/** Private handle to a parameter framework.
Expand Down Expand Up @@ -99,7 +98,8 @@ typedef enum {
typedef void PfwLogCb(void *userCtx, PfwLogLevel level, const char *logLine);

/** Logger containing a callback method and its context. */
typedef struct {
typedef struct
{
/** User defined arbitrary value that will be provided to all logCb call. */
void *userCtx;
/** Callback that will be called.
Expand All @@ -113,10 +113,12 @@ typedef struct {
///////////////////////////////

/** Structure of a parameter framework criterion. */
typedef struct {
typedef struct
{
/** Name of the criterion in the pfw configuration rules. */
const char *name; //< Must not be null.
bool inclusive; //< True if the criterion is inclusive, false if exclusive.
bool inclusive; //< True if the criterion is inclusive, false if exclusive.

/** Null terminated list of criterion value names.
* @example { "Red", "Green", "Blue", NULL }
*
Expand All @@ -131,7 +133,6 @@ typedef struct {
const char **values; //< Must not be null.
} PfwCriterion;


/** Create a parameter framework instance.
* Can not fail except for memory allocation.
*/
Expand All @@ -153,9 +154,8 @@ void pfwDestroy(PfwHandler *handle) NONNULL;
* @return true on success, false on failure.
*/
CPARAMETER_EXPORT
bool pfwStart(PfwHandler *handle, const char *configPath,
const PfwCriterion criteria[], size_t criterionNb,
const PfwLogger *loggger) NONNULL_(1, 2, 3) USERESULT;
bool pfwStart(PfwHandler *handle, const char *configPath, const PfwCriterion criteria[],
size_t criterionNb, const PfwLogger *loggger) NONNULL_(1, 2, 3) USERESULT;

/** @return a string describing the last call result.
* If the last pfw function call succeeded, return an empty string.
Expand Down Expand Up @@ -190,7 +190,8 @@ CPARAMETER_EXPORT
bool pfwSetCriterion(PfwHandler *handle, const char name[], int value) NONNULL USERESULT;
/** Get a criterion value given its name.
* Same usage as pfwSetCriterion except that value is an out param.
* Get criterion will return the last value setted with pfwSetCriterion independantly of pfwCommitCritenio.
* Get criterion will return the last value setted with pfwSetCriterion independantly of
* pfwCommitCritenio.
*/
CPARAMETER_EXPORT
bool pfwGetCriterion(const PfwHandler *handle, const char name[], int *value) NONNULL USERESULT;
Expand Down Expand Up @@ -244,7 +245,7 @@ void pfwUnbindParameter(PfwParameterHandler *handle) NONNULL;
* return true of success, false on failure.
*/
CPARAMETER_EXPORT
bool pfwGetIntParameter(const PfwParameterHandler *handle, int32_t *value ) NONNULL USERESULT;
bool pfwGetIntParameter(const PfwParameterHandler *handle, int32_t *value) NONNULL USERESULT;

/** Set the value of a previously bind int parameter.
* @param handle[in] Handler to a valid parameter.
Expand Down
Loading