19
19
20
20
#include < cstdint>
21
21
#include < cstring>
22
+ #include < optional>
22
23
23
24
#include < inet/InetInterface.h>
24
25
#include < lib/core/CHIPError.h>
25
- #include < lib/core/Optional.h>
26
26
#include < lib/core/PeerId.h>
27
27
#include < lib/dnssd/Constants.h>
28
28
#include < lib/support/BytesToHex.h>
@@ -91,10 +91,10 @@ struct CommonResolutionData
91
91
uint16_t port = 0 ;
92
92
char hostName[kHostNameMaxLength + 1 ] = {};
93
93
bool supportsTcp = false ;
94
- Optional <bool > isICDOperatingAsLIT;
95
- Optional <System::Clock::Milliseconds32> mrpRetryIntervalIdle;
96
- Optional <System::Clock::Milliseconds32> mrpRetryIntervalActive;
97
- Optional <System::Clock::Milliseconds16> mrpRetryActiveThreshold;
94
+ std::optional <bool > isICDOperatingAsLIT;
95
+ std::optional <System::Clock::Milliseconds32> mrpRetryIntervalIdle;
96
+ std::optional <System::Clock::Milliseconds32> mrpRetryIntervalActive;
97
+ std::optional <System::Clock::Milliseconds16> mrpRetryActiveThreshold;
98
98
99
99
CommonResolutionData () { Reset (); }
100
100
@@ -103,32 +103,32 @@ struct CommonResolutionData
103
103
ReliableMessageProtocolConfig GetRemoteMRPConfig () const
104
104
{
105
105
const ReliableMessageProtocolConfig defaultConfig = GetDefaultMRPConfig ();
106
- return ReliableMessageProtocolConfig (GetMrpRetryIntervalIdle ().ValueOr (defaultConfig.mIdleRetransTimeout ),
107
- GetMrpRetryIntervalActive ().ValueOr (defaultConfig.mActiveRetransTimeout ),
108
- GetMrpRetryActiveThreshold ().ValueOr (defaultConfig.mActiveThresholdTime ));
106
+ return ReliableMessageProtocolConfig (GetMrpRetryIntervalIdle ().value_or (defaultConfig.mIdleRetransTimeout ),
107
+ GetMrpRetryIntervalActive ().value_or (defaultConfig.mActiveRetransTimeout ),
108
+ GetMrpRetryActiveThreshold ().value_or (defaultConfig.mActiveThresholdTime ));
109
109
}
110
- Optional <System::Clock::Milliseconds32> GetMrpRetryIntervalIdle () const { return mrpRetryIntervalIdle; }
111
- Optional <System::Clock::Milliseconds32> GetMrpRetryIntervalActive () const { return mrpRetryIntervalActive; }
112
- Optional <System::Clock::Milliseconds16> GetMrpRetryActiveThreshold () const { return mrpRetryActiveThreshold; }
110
+ std::optional <System::Clock::Milliseconds32> GetMrpRetryIntervalIdle () const { return mrpRetryIntervalIdle; }
111
+ std::optional <System::Clock::Milliseconds32> GetMrpRetryIntervalActive () const { return mrpRetryIntervalActive; }
112
+ std::optional <System::Clock::Milliseconds16> GetMrpRetryActiveThreshold () const { return mrpRetryActiveThreshold; }
113
113
114
114
bool IsDeviceTreatedAsSleepy (const ReliableMessageProtocolConfig * defaultMRPConfig) const
115
115
{
116
116
// If either session interval (Idle - SII, Active - SAI) has a value and that value is greater
117
117
// than the value passed to this function, then the peer device will be treated as if it is
118
118
// a Sleepy End Device (SED)
119
- return (mrpRetryIntervalIdle.HasValue () && (mrpRetryIntervalIdle. Value () > defaultMRPConfig->mIdleRetransTimeout )) ||
120
- (mrpRetryIntervalActive.HasValue () && (mrpRetryIntervalActive. Value () > defaultMRPConfig->mActiveRetransTimeout ));
119
+ return (mrpRetryIntervalIdle.has_value () && (* mrpRetryIntervalIdle > defaultMRPConfig->mIdleRetransTimeout )) ||
120
+ (mrpRetryIntervalActive.has_value () && (* mrpRetryIntervalActive > defaultMRPConfig->mActiveRetransTimeout ));
121
121
}
122
122
123
123
bool IsHost (const char * host) const { return strcmp (host, hostName) == 0 ; }
124
124
125
125
void Reset ()
126
126
{
127
127
memset (hostName, 0 , sizeof (hostName));
128
- mrpRetryIntervalIdle = NullOptional ;
129
- mrpRetryIntervalActive = NullOptional ;
130
- mrpRetryActiveThreshold = NullOptional ;
131
- isICDOperatingAsLIT = NullOptional ;
128
+ mrpRetryIntervalIdle = std::nullopt ;
129
+ mrpRetryIntervalActive = std::nullopt ;
130
+ mrpRetryActiveThreshold = std::nullopt ;
131
+ isICDOperatingAsLIT = std::nullopt ;
132
132
numIPs = 0 ;
133
133
port = 0 ;
134
134
supportsTcp = false ;
@@ -157,34 +157,34 @@ struct CommonResolutionData
157
157
{
158
158
ChipLogDetail (Discovery, " \t Port: %u" , port);
159
159
}
160
- if (mrpRetryIntervalIdle.HasValue ())
160
+ if (mrpRetryIntervalIdle.has_value ())
161
161
{
162
- ChipLogDetail (Discovery, " \t Mrp Interval idle: %" PRIu32 " ms" , mrpRetryIntervalIdle. Value (). count ());
162
+ ChipLogDetail (Discovery, " \t Mrp Interval idle: %" PRIu32 " ms" , mrpRetryIntervalIdle-> count ());
163
163
}
164
164
else
165
165
{
166
166
ChipLogDetail (Discovery, " \t Mrp Interval idle: not present" );
167
167
}
168
- if (mrpRetryIntervalActive.HasValue ())
168
+ if (mrpRetryIntervalActive.has_value ())
169
169
{
170
- ChipLogDetail (Discovery, " \t Mrp Interval active: %" PRIu32 " ms" , mrpRetryIntervalActive. Value (). count ());
170
+ ChipLogDetail (Discovery, " \t Mrp Interval active: %" PRIu32 " ms" , mrpRetryIntervalActive-> count ());
171
171
}
172
172
else
173
173
{
174
174
ChipLogDetail (Discovery, " \t Mrp Interval active: not present" );
175
175
}
176
- if (mrpRetryActiveThreshold.HasValue ())
176
+ if (mrpRetryActiveThreshold.has_value ())
177
177
{
178
- ChipLogDetail (Discovery, " \t Mrp Active Threshold: %u ms" , mrpRetryActiveThreshold. Value (). count ());
178
+ ChipLogDetail (Discovery, " \t Mrp Active Threshold: %u ms" , mrpRetryActiveThreshold-> count ());
179
179
}
180
180
else
181
181
{
182
182
ChipLogDetail (Discovery, " \t Mrp Active Threshold: not present" );
183
183
}
184
184
ChipLogDetail (Discovery, " \t TCP Supported: %d" , supportsTcp);
185
- if (isICDOperatingAsLIT.HasValue ())
185
+ if (isICDOperatingAsLIT.has_value ())
186
186
{
187
- ChipLogDetail (Discovery, " \t The ICD operates in %s" , isICDOperatingAsLIT. Value () ? " LIT" : " SIT" );
187
+ ChipLogDetail (Discovery, " \t The ICD operates in %s" , * isICDOperatingAsLIT ? " LIT" : " SIT" );
188
188
}
189
189
else
190
190
{
0 commit comments