@@ -151,31 +151,26 @@ bool isChannelMatched(const ChannelInfoType & channel, const CharSpan & match)
151
151
152
152
void ChannelManager::HandleChangeChannel (CommandResponseHelper<ChangeChannelResponseType> & helper, const CharSpan & match)
153
153
{
154
- std::vector<ChannelInfoType> matchedChannels;
155
- uint16_t iFirstMatchedChannel = 0 ;
156
- for (auto const & channel : mChannels )
154
+ int iMatchedChannel = -1 ;
155
+ ChangeChannelResponseType response;
156
+
157
+ for (uint16_t i = 0 ; i < mChannels .size (); i++)
157
158
{
158
159
// verify if CharSpan matches channel name
159
160
// or callSign or affiliateCallSign or majorNumber.minorNumber
160
- if (isChannelMatched (channel , match))
161
+ if (isChannelMatched (mChannels [i] , match))
161
162
{
162
- matchedChannels.push_back (channel);
163
- }
164
- else if (matchedChannels.empty ())
165
- {
166
- iFirstMatchedChannel++;
167
- }
163
+ if (iMatchedChannel != -1 ) {
164
+ // Error: Found multiple matches
165
+ response.status = chip::app::Clusters::Channel::StatusEnum::kMultipleMatches ;
166
+ helper.Success (response);
167
+ return ;
168
+ }
169
+ iMatchedChannel = i;
170
+ }
168
171
}
169
172
170
- ChangeChannelResponseType response;
171
-
172
- // Error: Found multiple matches
173
- if (matchedChannels.size () > 1 )
174
- {
175
- response.status = chip::app::Clusters::Channel::StatusEnum::kMultipleMatches ;
176
- helper.Success (response);
177
- }
178
- else if (matchedChannels.empty ())
173
+ if (iMatchedChannel == -1 )
179
174
{
180
175
// Error: Found no match
181
176
response.status = chip::app::Clusters::Channel::StatusEnum::kNoMatches ;
@@ -185,8 +180,8 @@ void ChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResp
185
180
{
186
181
response.status = chip::app::Clusters::Channel::StatusEnum::kSuccess ;
187
182
response.data = chip::MakeOptional (CharSpan::fromCharString (" data response" ));
188
- mCurrentChannel = matchedChannels[ 0 ];
189
- mCurrentChannelIndex = iFirstMatchedChannel ;
183
+ mCurrentChannel = mChannels [iMatchedChannel ];
184
+ mCurrentChannelIndex = iMatchedChannel ;
190
185
helper.Success (response);
191
186
}
192
187
}
@@ -206,6 +201,7 @@ bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, c
206
201
channelChanged = true ;
207
202
mCurrentChannelIndex = index ;
208
203
mCurrentChannel = channel;
204
+ return channelChanged;
209
205
}
210
206
}
211
207
index ++;
0 commit comments