Skip to content

Commit

Permalink
Remove vector in chef-channel-manage.[cp]
Browse files Browse the repository at this point in the history
And avoid using "using" in header file
  • Loading branch information
erwinpan1 committed Jul 27, 2023
1 parent 0c39f39 commit 3a55750
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
10 changes: 7 additions & 3 deletions examples/chef/common/chef-channel-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/callback.h>
#include <app/util/config.h>
#include <vector>

using ChangeChannelResponseType = chip::app::Clusters::Channel::Commands::ChangeChannelResponse::Type;
using ChannelInfoType = chip::app::Clusters::Channel::Structs::ChannelInfoStruct::Type;
using LineupInfoType = chip::app::Clusters::Channel::Structs::LineupInfoStruct::Type;
// Include Channel Cluster Server callbacks only when the server is enabled
#ifdef EMBER_AF_PLUGIN_CHANNEL_SERVER
#include <chef-channel-manager.h>
Expand Down Expand Up @@ -120,15 +122,17 @@ CHIP_ERROR ChefChannelManager::HandleGetCurrentChannel(app::AttributeValueEncode
void ChefChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResponseType> & helper,
const chip::CharSpan & match)
{
std::vector<ChannelInfoType> matchedChannels;
std::array<ChannelInfoType, kMaxChannels> matchedChannels;

uint16_t index = 0;
uint16_t totalMatchedChannels = 0;
for (auto const & channel : mChannels)
{
// verify if CharSpan matches channel name
// or callSign or affiliateCallSign or majorNumber.minorNumber
if (isChannelMatched(channel, match))
{
matchedChannels.push_back(channel);
matchedChannels[totalMatchedChannels++] = (channel);
}
else if (matchedChannels.size() == 0)
{
Expand Down
19 changes: 5 additions & 14 deletions examples/chef/common/chef-channel-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,8 @@
#pragma once

#include <app/clusters/channel-server/channel-server.h>
#include <vector>

using chip::CharSpan;
using chip::app::AttributeValueEncoder;
using chip::app::CommandResponseHelper;
using ChannelDelegate = chip::app::Clusters::Channel::Delegate;
using ChangeChannelResponseType = chip::app::Clusters::Channel::Commands::ChangeChannelResponse::Type;
using ChannelInfoType = chip::app::Clusters::Channel::Structs::ChannelInfoStruct::Type;
using LineupInfoType = chip::app::Clusters::Channel::Structs::LineupInfoStruct::Type;

#define CHEF_CHANNEL_MANAGER_MAX_CHANNELS 10

class ChefChannelManager : public ChannelDelegate
class ChefChannelManager : public chip::app::Clusters::Channel::Delegate
{

public:
Expand All @@ -41,7 +30,8 @@ class ChefChannelManager : public ChannelDelegate
CHIP_ERROR HandleGetLineup(chip::app::AttributeValueEncoder & aEncoder);
CHIP_ERROR HandleGetCurrentChannel(chip::app::AttributeValueEncoder & aEncoder);

void HandleChangeChannel(CommandResponseHelper<ChangeChannelResponseType> & helper, const chip::CharSpan & match);
void HandleChangeChannel(chip::app::CommandResponseHelper<chip::app::Clusters::Channel::Commands::ChangeChannelResponse::Type> & helper,
const chip::CharSpan & match);
bool HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber);
bool HandleSkipChannel(const int16_t & count);

Expand All @@ -57,7 +47,8 @@ class ChefChannelManager : public ChannelDelegate
~ChefChannelManager() = default;

protected:
static constexpr size_t kMaxChannels = 10;
uint16_t mCurrentChannelIndex{ 0 };
uint16_t mTotalChannels{ 0 };
std::array<ChannelInfoType, CHEF_CHANNEL_MANAGER_MAX_CHANNELS> mChannels;
std::array<chip::app::Clusters::Channel::Structs::ChannelInfoStruct::Type, kMaxChannels> mChannels;
};

0 comments on commit 3a55750

Please sign in to comment.