Skip to content

Commit 1104088

Browse files
mideayanghuirestyled-commits
authored andcommitted
Fixes: [OPSTATE] specific phase in the list should not null (#31176)
* fix #27931 [OPSTATE] specific phase in the list should not null * Restyled by clang-format * remove unuseful namespace * modify the document of api * modify the document for api --------- Co-authored-by: Restyled.io <[email protected]>
1 parent 4a70aaa commit 1104088

16 files changed

+94
-240
lines changed

examples/all-clusters-app/all-clusters-common/include/operational-state-delegate-impl.h

+8-17
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,18 @@ class GenericOperationalStateDelegateImpl : public Delegate
5050
CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) override;
5151

5252
/**
53-
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
53+
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
5454
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
55+
*
56+
* If CHIP_ERROR_NOT_FOUND is returned for index 0, that indicates that the PhaseList attribute is null
57+
* (there are no phases defined at all).
58+
*
5559
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
5660
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
5761
* @param index The index of the phase, with 0 representing the first phase.
58-
* @param operationalPhase The GenericOperationalPhase is filled.
62+
* @param operationalPhase The MutableCharSpan is filled.
5963
*/
60-
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) override;
64+
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;
6165

6266
// command callback
6367
/**
@@ -86,7 +90,7 @@ class GenericOperationalStateDelegateImpl : public Delegate
8690

8791
protected:
8892
Span<const GenericOperationalState> mOperationalStateList;
89-
Span<const GenericOperationalPhase> mOperationalPhaseList;
93+
Span<const CharSpan> mOperationalPhaseList;
9094
};
9195

9296
// This is an application level delegate to handle operational state commands according to the specific business logic.
@@ -100,16 +104,10 @@ class OperationalStateDelegate : public GenericOperationalStateDelegateImpl
100104
GenericOperationalState(to_underlying(OperationalStateEnum::kError)),
101105
};
102106

103-
const GenericOperationalPhase opPhaseList[1] = {
104-
// Phase List is null
105-
GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
106-
};
107-
108107
public:
109108
OperationalStateDelegate()
110109
{
111110
GenericOperationalStateDelegateImpl::mOperationalStateList = Span<const GenericOperationalState>(opStateList);
112-
GenericOperationalStateDelegateImpl::mOperationalPhaseList = Span<const GenericOperationalPhase>(opPhaseList);
113111
}
114112
};
115113

@@ -134,18 +132,11 @@ class RvcOperationalStateDelegate : public OperationalState::GenericOperationalS
134132
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
135133
};
136134

137-
const OperationalState::GenericOperationalPhase rvcOpPhaseList[1] = {
138-
// Phase List is null
139-
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
140-
};
141-
142135
public:
143136
RvcOperationalStateDelegate()
144137
{
145138
GenericOperationalStateDelegateImpl::mOperationalStateList =
146139
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
147-
GenericOperationalStateDelegateImpl::mOperationalPhaseList =
148-
Span<const OperationalState::GenericOperationalPhase>(rvcOpPhaseList);
149140
}
150141
};
151142

examples/all-clusters-app/all-clusters-common/src/operational-state-delegate-impl.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_
3333
return CHIP_NO_ERROR;
3434
}
3535

36-
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase)
36+
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase)
3737
{
3838
if (index >= mOperationalPhaseList.size())
3939
{
4040
return CHIP_ERROR_NOT_FOUND;
4141
}
42-
operationalPhase = mOperationalPhaseList[index];
43-
return CHIP_NO_ERROR;
42+
return CopyCharSpanToMutableCharSpan(mOperationalPhaseList[index], operationalPhase);
4443
}
4544

4645
void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError & err)

examples/all-clusters-app/ameba/main/OperationalStateManager.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_
3333
return CHIP_NO_ERROR;
3434
}
3535

36-
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase)
36+
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase)
3737
{
3838
if (index >= mOperationalPhaseList.size())
3939
{
4040
return CHIP_ERROR_NOT_FOUND;
4141
}
42-
operationalPhase = mOperationalPhaseList[index];
43-
return CHIP_NO_ERROR;
42+
return CopyCharSpanToMutableCharSpan(mOperationalPhaseList[index], operationalPhase);
4443
}
4544

4645
void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError & err)

examples/all-clusters-app/ameba/main/include/OperationalStateManager.h

+8-17
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ class GenericOperationalStateDelegateImpl : public Delegate
5454
CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) override;
5555

5656
/**
57-
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
57+
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
5858
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
59+
*
60+
* If CHIP_ERROR_NOT_FOUND is returned for index 0, that indicates that the PhaseList attribute is null
61+
* (there are no phases defined at all).
62+
*
5963
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
6064
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
6165
* @param index The index of the phase, with 0 representing the first phase.
62-
* @param operationalPhase The GenericOperationalPhase is filled.
66+
* @param operationalPhase The MutableCharSpan is filled.
6367
*/
64-
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) override;
68+
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;
6569

6670
// command callback
6771
/**
@@ -90,7 +94,7 @@ class GenericOperationalStateDelegateImpl : public Delegate
9094

9195
protected:
9296
Span<const GenericOperationalState> mOperationalStateList;
93-
Span<const GenericOperationalPhase> mOperationalPhaseList;
97+
Span<const CharSpan> mOperationalPhaseList;
9498
};
9599

96100
// This is an application level delegate to handle operational state commands according to the specific business logic.
@@ -104,16 +108,10 @@ class OperationalStateDelegate : public GenericOperationalStateDelegateImpl
104108
GenericOperationalState(to_underlying(OperationalStateEnum::kError)),
105109
};
106110

107-
const GenericOperationalPhase opPhaseList[1] = {
108-
// Phase List is null
109-
GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
110-
};
111-
112111
public:
113112
OperationalStateDelegate()
114113
{
115114
GenericOperationalStateDelegateImpl::mOperationalStateList = Span<const GenericOperationalState>(opStateList);
116-
GenericOperationalStateDelegateImpl::mOperationalPhaseList = Span<const GenericOperationalPhase>(opPhaseList);
117115
}
118116
};
119117

@@ -140,18 +138,11 @@ class RvcOperationalStateDelegate : public OperationalState::GenericOperationalS
140138
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
141139
};
142140

143-
const OperationalState::GenericOperationalPhase rvcOpPhaseList[1] = {
144-
// Phase List is null
145-
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
146-
};
147-
148141
public:
149142
RvcOperationalStateDelegate()
150143
{
151144
GenericOperationalStateDelegateImpl::mOperationalStateList =
152145
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
153-
GenericOperationalStateDelegateImpl::mOperationalPhaseList =
154-
Span<const OperationalState::GenericOperationalPhase>(rvcOpPhaseList);
155146
}
156147
};
157148

examples/chef/common/chef-rvc-operational-state-delegate.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_
3737
return CHIP_NO_ERROR;
3838
}
3939

40-
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase)
40+
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase)
4141
{
4242
if (index >= mOperationalPhaseList.size())
4343
{
4444
return CHIP_ERROR_NOT_FOUND;
4545
}
46-
operationalPhase = mOperationalPhaseList[index];
47-
return CHIP_NO_ERROR;
46+
return CopyCharSpanToMutableCharSpan(mOperationalPhaseList[index], operationalPhase);
4847
}
4948

5049
void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError & err)

examples/chef/common/chef-rvc-operational-state-delegate.h

+8-17
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,18 @@ class GenericOperationalStateDelegateImpl : public Delegate
5050
CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) override;
5151

5252
/**
53-
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
53+
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
5454
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
55+
*
56+
* If CHIP_ERROR_NOT_FOUND is returned for index 0, that indicates that the PhaseList attribute is null
57+
* (there are no phases defined at all).
58+
*
5559
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
5660
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
5761
* @param index The index of the phase, with 0 representing the first phase.
58-
* @param operationalPhase The GenericOperationalPhase is filled.
62+
* @param operationalPhase The MutableCharSpan is filled.
5963
*/
60-
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) override;
64+
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;
6165

6266
// command callback
6367
/**
@@ -86,7 +90,7 @@ class GenericOperationalStateDelegateImpl : public Delegate
8690

8791
protected:
8892
Span<const GenericOperationalState> mOperationalStateList;
89-
Span<const GenericOperationalPhase> mOperationalPhaseList;
93+
Span<const CharSpan> mOperationalPhaseList;
9094
};
9195

9296
// This is an application level delegate to handle operational state commands according to the specific business logic.
@@ -100,16 +104,10 @@ class OperationalStateDelegate : public GenericOperationalStateDelegateImpl
100104
GenericOperationalState(to_underlying(OperationalStateEnum::kError)),
101105
};
102106

103-
const GenericOperationalPhase opPhaseList[1] = {
104-
// Phase List is null
105-
GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
106-
};
107-
108107
public:
109108
OperationalStateDelegate()
110109
{
111110
GenericOperationalStateDelegateImpl::mOperationalStateList = Span<const GenericOperationalState>(opStateList);
112-
GenericOperationalStateDelegateImpl::mOperationalPhaseList = Span<const GenericOperationalPhase>(opPhaseList);
113111
}
114112
};
115113

@@ -134,18 +132,11 @@ class RvcOperationalStateDelegate : public OperationalState::GenericOperationalS
134132
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
135133
};
136134

137-
const OperationalState::GenericOperationalPhase rvcOpPhaseList[1] = {
138-
// Phase List is null
139-
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
140-
};
141-
142135
public:
143136
RvcOperationalStateDelegate()
144137
{
145138
GenericOperationalStateDelegateImpl::mOperationalStateList =
146139
Span<const OperationalState::GenericOperationalState>(rvcOpStateList);
147-
GenericOperationalStateDelegateImpl::mOperationalPhaseList =
148-
Span<const OperationalState::GenericOperationalPhase>(rvcOpPhaseList);
149140
}
150141
};
151142

examples/dishwasher-app/dishwasher-common/include/operational-state-delegate-impl.h

+8-10
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ class OperationalStateDelegate : public Delegate
5050

5151
/**
5252
* Get the list of supported operational phases.
53-
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
53+
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
5454
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
55+
*
56+
* If CHIP_ERROR_NOT_FOUND is returned for index 0, that indicates that the PhaseList attribute is null
57+
* (there are no phases defined at all).
58+
*
5559
* @param index The index of the phase, with 0 representing the first phase.
56-
* @param operationalPhase The GenericOperationalPhase is filled.
60+
* @param operationalPhase The MutableCharSpan is filled.
5761
*/
58-
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) override;
62+
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;
5963

6064
// command callback
6165
/**
@@ -91,13 +95,7 @@ class OperationalStateDelegate : public Delegate
9195
};
9296

9397
app::DataModel::List<const GenericOperationalState> mOperationalStateList = Span<const GenericOperationalState>(rvcOpStateList);
94-
95-
const GenericOperationalPhase opPhaseList[1] = {
96-
// Phase List is null
97-
GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
98-
};
99-
100-
Span<const GenericOperationalPhase> mOperationalPhaseList = Span<const GenericOperationalPhase>(opPhaseList);
98+
const Span<const CharSpan> mOperationalPhaseList;
10199
};
102100

103101
void Shutdown();

examples/dishwasher-app/dishwasher-common/src/operational-state-delegate-impl.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ CHIP_ERROR OperationalStateDelegate::GetOperationalStateAtIndex(size_t index, Ge
3232
return CHIP_NO_ERROR;
3333
}
3434

35-
CHIP_ERROR OperationalStateDelegate::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase)
35+
CHIP_ERROR OperationalStateDelegate::GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase)
3636
{
37-
if (index > mOperationalPhaseList.size() - 1)
37+
if (index >= mOperationalPhaseList.size())
3838
{
3939
return CHIP_ERROR_NOT_FOUND;
4040
}
41-
operationalPhase = mOperationalPhaseList[index];
42-
return CHIP_NO_ERROR;
41+
return CopyCharSpanToMutableCharSpan(mOperationalPhaseList[index], operationalPhase);
4342
}
4443

4544
void OperationalStateDelegate::HandlePauseStateCallback(GenericOperationalError & err)

examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,18 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate,
111111
CHIP_ERROR GetOperationalStateAtIndex(size_t index, OperationalState::GenericOperationalState & operationalState) override;
112112

113113
/**
114-
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
114+
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
115115
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
116+
*
117+
* If CHIP_ERROR_NOT_FOUND is returned for index 0, that indicates that the PhaseList attribute is null
118+
* (there are no phases defined at all).
119+
*
116120
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
117121
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
118122
* @param index The index of the phase, with 0 representing the first phase.
119-
* @param operationalPhase The GenericOperationalPhase is filled.
123+
* @param operationalPhase The MutableCharSpan is filled.
120124
*/
121-
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, OperationalState::GenericOperationalPhase & operationalPhase) override;
125+
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;
122126

123127
/**
124128
* Handle Command Callback in application: Pause
@@ -220,14 +224,7 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate,
220224

221225
const app::DataModel::List<const OperationalState::GenericOperationalState> mOperationalStateList =
222226
Span<const OperationalState::GenericOperationalState>(mOpStateList);
223-
224-
const OperationalState::GenericOperationalPhase mOpPhaseList[1] = {
225-
// Phase List is null
226-
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
227-
};
228-
229-
Span<const OperationalState::GenericOperationalPhase> mOperationalPhaseList =
230-
Span<const OperationalState::GenericOperationalPhase>(mOpPhaseList);
227+
const Span<const CharSpan> mOperationalPhaseList;
231228
};
232229

233230
} // namespace Clusters

examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalStateAtIndex(size_t index,
8080
return CHIP_NO_ERROR;
8181
}
8282

83-
CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalPhaseAtIndex(size_t index,
84-
OperationalState::GenericOperationalPhase & operationalPhase)
83+
CHIP_ERROR ExampleMicrowaveOvenDevice::GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase)
8584
{
86-
if (index > mOperationalPhaseList.size() - 1)
85+
if (index >= mOperationalPhaseList.size())
8786
{
8887
return CHIP_ERROR_NOT_FOUND;
8988
}
90-
operationalPhase = mOperationalPhaseList[index];
91-
return CHIP_NO_ERROR;
89+
return CopyCharSpanToMutableCharSpan(mOperationalPhaseList[index], operationalPhase);
9290
}
9391

9492
void ExampleMicrowaveOvenDevice::HandlePauseStateCallback(OperationalState::GenericOperationalError & err)

examples/rvc-app/rvc-common/include/rvc-operational-state-delegate.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ class RvcOperationalStateDelegate : public OperationalState::Delegate
4747
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kCharging)),
4848
OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)),
4949
};
50-
51-
const Clusters::OperationalState::GenericOperationalPhase mOperationalPhaseList[1] = {
52-
// Phase List is null
53-
OperationalState::GenericOperationalPhase(DataModel::Nullable<CharSpan>()),
54-
};
50+
const Span<const CharSpan> mOperationalPhaseList;
5551

5652
RvcDevice * mPauseRvcDeviceInstance;
5753
HandleOpStateCommand mPauseCallback;
@@ -77,15 +73,18 @@ class RvcOperationalStateDelegate : public OperationalState::Delegate
7773
Clusters::OperationalState::GenericOperationalState & operationalState) override;
7874

7975
/**
80-
* Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one,
76+
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
8177
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
78+
*
79+
* If CHIP_ERROR_NOT_FOUND is returned for index 0, that indicates that the PhaseList attribute is null
80+
* (there are no phases defined at all).
81+
*
8282
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
8383
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
8484
* @param index The index of the phase, with 0 representing the first phase.
85-
* @param operationalPhase The GenericOperationalPhase is filled.
85+
* @param operationalPhase The MutableCharSpan is filled.
8686
*/
87-
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index,
88-
Clusters::OperationalState::GenericOperationalPhase & operationalPhase) override;
87+
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;
8988

9089
// command callback
9190
/**

0 commit comments

Comments
 (0)