Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and du48s03 committed Oct 29, 2021
1 parent 43be5a4 commit acffd1c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 65 deletions.
17 changes: 8 additions & 9 deletions src/app/clusters/mode-select-server/mode-select-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ CHIP_ERROR ModeSelectAttrAccess::Read(const ConcreteAttributePath & aPath, Attri
VerifyOrDie(aPath.mClusterId == ModeSelect::Id);

const ModeSelect::StaticSupportedModesManager & gSupportedModeManager =
ModeSelect::StaticSupportedModesManager::getStaticSupportedModesManagerInstance();
ModeSelect::StaticSupportedModesManager::getStaticSupportedModesManagerInstance();

if (ModeSelect::Attributes::SupportedModes::Id == aPath.mAttributeId)
{
const ModeSelect::StaticSupportedModesManager::IteratorFactory* iteratorFactory =
gSupportedModeManager.getIteratorFactory(aPath.mEndpointId);
const ModeSelect::StaticSupportedModesManager::IteratorFactory * iteratorFactory =
gSupportedModeManager.getIteratorFactory(aPath.mEndpointId);
if (iteratorFactory == nullptr)
{
aEncoder.Encode(DataModel::List<ModeSelect::Structs::ModeOptionStruct::Type>());
Expand All @@ -69,8 +69,8 @@ CHIP_ERROR ModeSelectAttrAccess::Read(const ConcreteAttributePath & aPath, Attri
for (auto it = *(iteratorFactory->begin()); it != end; ++it)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "ModeSelect: dereferencing it");
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "ModeSelect: it= %p", (void*) it.operator->());
auto& modeOption = *it;
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "ModeSelect: it= %p", (void *) it.operator->());
auto & modeOption = *it;
ReturnErrorOnFailure(encoder.Encode(modeOption));
}
return CHIP_NO_ERROR;
Expand All @@ -82,17 +82,16 @@ CHIP_ERROR ModeSelectAttrAccess::Read(const ConcreteAttributePath & aPath, Attri

} // anonymous namespace

bool emberAfModeSelectClusterChangeToModeCallback(
CommandHandler * commandHandler, const ConcreteCommandPath & commandPath,
const ModeSelect::Commands::ChangeToMode::DecodableType & commandData)
bool emberAfModeSelectClusterChangeToModeCallback(CommandHandler * commandHandler, const ConcreteCommandPath & commandPath,
const ModeSelect::Commands::ChangeToMode::DecodableType & commandData)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "ModeSelect: Entering emberAfModeSelectClusterChangeToModeCallback");
EndpointId endpointId = commandPath.mEndpointId;
uint8_t newMode = commandData.newMode;
// Check that the newMode matches one of the supported options
const ModeSelect::Structs::ModeOptionStruct::Type * modeOptionPtr;
const ModeSelect::StaticSupportedModesManager & gSupportedModeManager =
ModeSelect::StaticSupportedModesManager::getStaticSupportedModesManagerInstance();
ModeSelect::StaticSupportedModesManager::getStaticSupportedModesManagerInstance();
EmberAfStatus checkSupportedModeStatus = gSupportedModeManager.getModeOptionByMode(endpointId, newMode, &modeOptionPtr);
if (EMBER_ZCL_STATUS_SUCCESS != checkSupportedModeStatus)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ using namespace chip::app::Clusters::ModeSelect;

using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using storage_value_type = const ModeOptionStructType *;
namespace
{
namespace {
Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode, uint32_t semanticTag)
{
Structs::ModeOptionStruct::Type option;
Expand All @@ -22,7 +21,7 @@ Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_
option.semanticTag = semanticTag;
return option;
}
}
} // namespace

const Structs::ModeOptionStruct::Type StaticSupportedModesManager::blackOption = buildModeOptionStruct("Black", 0, 0);
const Structs::ModeOptionStruct::Type StaticSupportedModesManager::cappuccinoOption = buildModeOptionStruct("Cappuccino", 4, 0);
Expand All @@ -36,18 +35,17 @@ const map<EndpointId, Span<storage_value_type>> StaticSupportedModesManager::opt

const StaticSupportedModesManager StaticSupportedModesManager::instance = StaticSupportedModesManager();

const StaticSupportedModesManager::IteratorFactory *
StaticSupportedModesManager::getIteratorFactory(EndpointId endpointId) const
const StaticSupportedModesManager::IteratorFactory * StaticSupportedModesManager::getIteratorFactory(EndpointId endpointId) const
{
const auto& it = _iteratorFactoriesByEndpoints.find(endpointId);
const auto & it = _iteratorFactoriesByEndpoints.find(endpointId);
return (it == _iteratorFactoriesByEndpoints.end()) ? nullptr : &(it->second);
}

EmberAfStatus StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode,
const ModeOptionStructType ** dataPtr) const
const ModeOptionStructType ** dataPtr) const
{
auto* iteratorFactory = this->getIteratorFactory(endpointId);
if(iteratorFactory == nullptr)
auto * iteratorFactory = this->getIteratorFactory(endpointId);
if (iteratorFactory == nullptr)
{
return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

#pragma once

#include <cstring>
#include <app/clusters/mode-select-server/supported-modes-manager.h>
#include <app/util/af.h>
#include <cstring>
#include <map>
#include <vector>
#include <app/util/af.h>

namespace chip {
namespace app {
Expand All @@ -36,39 +36,41 @@ namespace ModeSelect {
class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::SupportedModesManager
{
using ModeOptionStructType = Structs::ModeOptionStruct::Type;
using storage_value_type = const ModeOptionStructType*;
using storage_value_type = const ModeOptionStructType *;

static const ModeOptionStructType blackOption;
static const ModeOptionStructType cappuccinoOption;
static const ModeOptionStructType espressoOption;

static const ModeOptionStructType* coffeeOptions[];
static const ModeOptionStructType * coffeeOptions[];
static const Span<storage_value_type> coffeeOptionsSpan;
static const std::map<EndpointId, Span<storage_value_type>> optionsByEndpoints;



public:
static const StaticSupportedModesManager instance;

struct Iterator: public chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIterator
struct Iterator : public chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIterator
{
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using pointer = storage_value_type*;
using base_iterator_type= chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIterator;
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using pointer = storage_value_type *;
using base_iterator_type = chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIterator;

Iterator(const pointer aPtr):mPtr(aPtr) {}
Iterator(const pointer aPtr) : mPtr(aPtr) {}
~Iterator() = default;

const ModeOptionStructType& operator*() const override { return **mPtr; }
const ModeOptionStructType* operator->() override { return *mPtr; }
const ModeOptionStructType* operator->() const override { return *mPtr; }
const ModeOptionStructType & operator*() const override { return **mPtr; }
const ModeOptionStructType * operator->() override { return *mPtr; }
const ModeOptionStructType * operator->() const override { return *mPtr; }

// Prefix increment
base_iterator_type& operator++() override { ++mPtr; return *this; }
base_iterator_type & operator++() override
{
++mPtr;
return *this;
}

bool operator== (const base_iterator_type& other) const override
bool operator==(const base_iterator_type & other) const override
{
// Warning: we are not doing type check
// TODO: use of typeid requires -frtti
Expand All @@ -78,31 +80,31 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp
// }
return this->operator->() == other.operator->();
}
bool operator!= (const base_iterator_type& other) const override { return !((*this) == other); }

private:
pointer mPtr;
bool operator!=(const base_iterator_type & other) const override { return !((*this) == other); }

private:
pointer mPtr;
};

struct IteratorFactory: public chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIteratorFactory
struct IteratorFactory : public chip::app::Clusters::ModeSelect::SupportedModesManager::ModeOptionStructIteratorFactory
{
using pointer = Iterator*;
using pointer = Iterator *;
using const_pointer = const pointer;

IteratorFactory(const Span<storage_value_type>& aSupportedOptions): _begin(Iterator(aSupportedOptions.data())), _end(Iterator(aSupportedOptions.data() + aSupportedOptions.size())) { }
IteratorFactory(const Span<storage_value_type> & aSupportedOptions) :
_begin(Iterator(aSupportedOptions.data())), _end(Iterator(aSupportedOptions.data() + aSupportedOptions.size()))
{}
~IteratorFactory() = default;

const Iterator* begin() const override { return &_begin; }
const Iterator* end() const override { return &_end; }

private:
const Iterator _begin;
const Iterator _end;
const Iterator * begin() const override { return &_begin; }
const Iterator * end() const override { return &_end; }

private:
const Iterator _begin;
const Iterator _end;
};

const IteratorFactory* getIteratorFactory(EndpointId endpointId) const override;
const IteratorFactory * getIteratorFactory(EndpointId endpointId) const override;

EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const override;

Expand All @@ -118,15 +120,15 @@ class StaticSupportedModesManager : public chip::app::Clusters::ModeSelect::Supp
{
for (auto & entry : *supportedModes)
{
_iteratorFactoriesByEndpoints.insert(std::pair<EndpointId, IteratorFactory>(entry.first, IteratorFactory(entry.second)));
_iteratorFactoriesByEndpoints.insert(
std::pair<EndpointId, IteratorFactory>(entry.first, IteratorFactory(entry.second)));
}
}
// TODO: Implement move constructor?

std::map<EndpointId, IteratorFactory> _iteratorFactoriesByEndpoints;
};


} // namespace ModeSelect
} // namespace Clusters
} // namespace app
Expand Down
24 changes: 11 additions & 13 deletions src/app/clusters/mode-select-server/supported-modes-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ class SupportedModesManager
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = const ModeOptionStructType;
using pointer = value_type*;
using reference = value_type&;
using pointer = value_type *;
using reference = value_type &;

virtual reference operator*() const = 0;
virtual pointer operator->() = 0;
virtual pointer operator->() const = 0;
virtual pointer operator->() = 0;
virtual pointer operator->() const = 0;

// Prefix increment
virtual ModeOptionStructIterator& operator++() = 0;

virtual bool operator== (const ModeOptionStructIterator& other) const = 0;
virtual bool operator!= (const ModeOptionStructIterator& other) const = 0;
virtual ModeOptionStructIterator & operator++() = 0;

virtual bool operator==(const ModeOptionStructIterator & other) const = 0;
virtual bool operator!=(const ModeOptionStructIterator & other) const = 0;

virtual ~ModeOptionStructIterator() {}
};
Expand All @@ -68,7 +67,7 @@ class SupportedModesManager
*/
struct ModeOptionStructIteratorFactory
{
using const_pointer = const ModeOptionStructIterator*;
using const_pointer = const ModeOptionStructIterator *;

/**
* Returns the ModeOptionStructIterator to the first option.
Expand All @@ -95,13 +94,12 @@ class SupportedModesManager
* @param endpointId The endpoint for which to search the ModeOptionStruct.
* @param mode The mode for which to search the ModeOptionStruct.
* @param dataPtr The pointer to receive the ModeOptionStruct, if one is found.
* @return EMBER_ZCL_STATUS_SUCCESS if sucessfully found the option. Otherwise, returns appropriate status code (found in <app/util/af-enums.h>)
* @return EMBER_ZCL_STATUS_SUCCESS if sucessfully found the option. Otherwise, returns appropriate status code (found in
* <app/util/af-enums.h>)
*/
virtual EmberAfStatus getModeOptionByMode(EndpointId endpointId, uint8_t mode, const ModeOptionStructType ** dataPtr) const = 0;

virtual ~SupportedModesManager(){}


virtual ~SupportedModesManager() {}
};

} // namespace ModeSelect
Expand Down
3 changes: 2 additions & 1 deletion src/darwin/Framework/CHIP/templates/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/

function getTests() {
function getTests()
{
const BinaryInput = [
'Test_TC_BI_1_1',
];
Expand Down

0 comments on commit acffd1c

Please sign in to comment.