@@ -25,25 +25,25 @@ using namespace chip::app::Clusters::MediaInput;
25
25
26
26
MediaInputManager::MediaInputManager ()
27
27
{
28
- mCurrentInput = 1 ;
28
+ struct InputData inputData1 (1 , chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi , " HDMI 1" ,
29
+ " High-Definition Multimedia Interface" );
30
+ mInputs .push_back(inputData1);
31
+ struct InputData inputData2 (2 , chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi , " HDMI 2" ,
32
+ " High-Definition Multimedia Interface" );
33
+ mInputs .push_back(inputData2);
34
+ struct InputData inputData3 (3 , chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi , " HDMI 3" ,
35
+ " High-Definition Multimedia Interface" );
36
+ mInputs .push_back(inputData3);
29
37
30
- for (int i = 1 ; i < mTotalInput ; ++i)
31
- {
32
- InputInfoType inputInfo;
33
- inputInfo.description = chip::CharSpan::fromCharString (" High-Definition Multimedia Interface" );
34
- inputInfo.name = chip::CharSpan::fromCharString (" HDMI" );
35
- inputInfo.inputType = chip::app::Clusters::MediaInput::InputTypeEnum::kHdmi ;
36
- inputInfo.index = static_cast <uint8_t >(i);
37
- mInputs .push_back (inputInfo);
38
- }
38
+ mCurrentInput = 1 ;
39
39
}
40
40
41
41
CHIP_ERROR MediaInputManager::HandleGetInputList (chip::app::AttributeValueEncoder & aEncoder)
42
42
{
43
43
return aEncoder.EncodeList ([this ](const auto & encoder) -> CHIP_ERROR {
44
- for (auto const & inputInfo : this ->mInputs )
44
+ for (auto const & inputData : this ->mInputs )
45
45
{
46
- ReturnErrorOnFailure (encoder.Encode (inputInfo ));
46
+ ReturnErrorOnFailure (encoder.Encode (inputData. GetEncodable () ));
47
47
}
48
48
return CHIP_NO_ERROR;
49
49
});
@@ -56,9 +56,9 @@ uint8_t MediaInputManager::HandleGetCurrentInput()
56
56
57
57
bool MediaInputManager::HandleSelectInput (const uint8_t index)
58
58
{
59
- for (InputInfoType & input : mInputs )
59
+ for (auto const & inputData : mInputs )
60
60
{
61
- if (input .index == index )
61
+ if (inputData .index == index )
62
62
{
63
63
mCurrentInput = index ;
64
64
return true ;
@@ -71,13 +71,11 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)
71
71
bool MediaInputManager::HandleShowInputStatus ()
72
72
{
73
73
ChipLogProgress (Zcl, " MediaInputManager::HandleShowInputStatus()" );
74
- for (auto const & inputInfo : this -> mInputs )
74
+ for (auto const & inputData : mInputs )
75
75
{
76
- string name (inputInfo.name .data (), inputInfo.name .size ());
77
- string desc (inputInfo.description .data (), inputInfo.description .size ());
78
- ChipLogProgress (Zcl, " [%d] type=%d selected=%d name=%s desc=%s" , inputInfo.index ,
79
- static_cast <uint16_t >(inputInfo.inputType ), (mCurrentInput == inputInfo.index ? 1 : 0 ), name.c_str (),
80
- desc.c_str ());
76
+ ChipLogProgress (Zcl, " [%d] type=%d selected=%d name=%s desc=%s" , inputData.index ,
77
+ static_cast <uint16_t >(inputData.inputType ), (mCurrentInput == inputData.index ? 1 : 0 ),
78
+ inputData.name .c_str (), inputData.description .c_str ());
81
79
}
82
80
return true ;
83
81
}
@@ -88,15 +86,13 @@ bool MediaInputManager::HandleHideInputStatus()
88
86
return true ;
89
87
}
90
88
91
- bool MediaInputManager::HandleRenameInput (const uint8_t index, const chip::CharSpan & name )
89
+ bool MediaInputManager::HandleRenameInput (const uint8_t index, const chip::CharSpan & newName )
92
90
{
93
- for (InputInfoType & input : mInputs )
91
+ for (auto & inputData : mInputs )
94
92
{
95
- if (input .index == index )
93
+ if (inputData .index == index )
96
94
{
97
- const size_t len = std::min (mNameLenMax , name.size ());
98
- memcpy (mInputName [index ], name.data (), len);
99
- input.name = mInputName [index ];
95
+ inputData.Rename (newName);
100
96
return true ;
101
97
}
102
98
}
0 commit comments