Skip to content

Commit

Permalink
Rename Data() function to GetXxxxName() function
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinpan1 committed Feb 13, 2024
1 parent 6fda537 commit 4af0b95
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ bool AudioOutputManager::HandleRenameOutput(const uint8_t & index, const chip::C
if (output.index == index)
{
audioOutputRenamed = true;
const size_t len = std::min(mBufMax, name.size());
memcpy(this->Data(index), name.data(), len);
output.name = chip::CharSpan(this->Data(index), len);
const size_t len = std::min(mNameLenMax, name.size());
memcpy(mOutputName[index], name.data(), len);
output.name = mOutputName[index];
return audioOutputRenamed;
}
}

return audioOutputRenamed;
}

Expand Down
12 changes: 9 additions & 3 deletions examples/chef/common/clusters/audio-output/AudioOutputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ class AudioOutputManager : public chip::app::Clusters::AudioOutput::Delegate
CHIP_ERROR HandleGetOutputList(chip::app::AttributeValueEncoder & aEncoder) override;
bool HandleRenameOutput(const uint8_t & index, const chip::CharSpan & name) override;
bool HandleSelectOutput(const uint8_t & index) override;
char * Data(uint8_t index) { return mCharDataBuffer[index]; }
CHIP_ERROR GetOutputName(uint8_t index, chip::CharSpan & name) {
if (index < mOutputs.size()) {
name = chip::CharSpan::fromCharString(mOutputName[index]);
return CHIP_NO_ERROR;
}
return CHIP_ERROR_INVALID_ARGUMENT;
}

protected:
uint8_t mCurrentOutput = 1;
std::vector<OutputInfoType> mOutputs;
// Magic numbers are here on purpose, please allocate memory
static constexpr size_t mBufMax = 32;
char mCharDataBuffer[10][mBufMax];
static constexpr size_t mNameLenMax = 32;
char mOutputName[10][mNameLenMax];
};
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS
if (input.index == index)
{
mediaInputRenamed = true;
const size_t len = std::min(mBufMax, name.size());
memcpy(this->Data(index), name.data(), len);
input.name = chip::CharSpan(this->Data(index), name.size());
const size_t len = std::min(mNameLenMax, name.size());
memcpy(mInputName[index], name.data(), len);
input.name = mInputName[index];
return mediaInputRenamed;
}
}
Expand Down
14 changes: 10 additions & 4 deletions examples/chef/common/clusters/media-input/MediaInputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ class MediaInputManager : public chip::app::Clusters::MediaInput::Delegate
bool HandleShowInputStatus() override;
bool HandleHideInputStatus() override;
bool HandleRenameInput(const uint8_t index, const chip::CharSpan & name) override;
char * Data(uint8_t index) { return mCharDataBuffer[index]; }
CHIP_ERROR GetInputName(uint8_t index, chip::CharSpan & name) {
if (index < mInputs.size()) {
name = chip::CharSpan::fromCharString(mInputName[index]);
return CHIP_NO_ERROR;
}
return CHIP_ERROR_INVALID_ARGUMENT;
}

protected:
uint8_t mCurrentInput;
std::vector<chip::app::Clusters::MediaInput::Structs::InputInfoStruct::Type> mInputs;
std::vector<InputInfoType> mInputs;
// Magic numbers are here on purpose, please allocate memory
static constexpr size_t mBufMax = 32;
char mCharDataBuffer[10][mBufMax];
static constexpr size_t mNameLenMax = 32;
char mInputName[10][mNameLenMax];

private:
static constexpr int mTotalInput = 3;
Expand Down

0 comments on commit 4af0b95

Please sign in to comment.