32
32
#include < app/icd/server/ICDConfigurationData.h> // nogncheck
33
33
#endif
34
34
35
- #include < optional>
36
-
37
35
namespace chip {
38
36
39
37
using namespace System ::Clock::Literals;
40
38
41
39
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
42
- namespace {
43
- // Use std::optional for globals to avoid static initializers
44
- std::optional<System::Clock::Timeout> gIdleRetransTimeoutOverride ;
45
- std::optional<System::Clock::Timeout> gActiveRetransTimeoutOverride ;
46
- std::optional<System::Clock::Timeout> gActiveThresholdTimeOverride ;
47
- } // namespace
40
+ static Optional<System::Clock::Timeout> idleRetransTimeoutOverride = NullOptional;
41
+ static Optional<System::Clock::Timeout> activeRetransTimeoutOverride = NullOptional;
42
+ static Optional<System::Clock::Timeout> activeThresholdTimeOverride = NullOptional;
48
43
49
44
void OverrideLocalMRPConfig (System::Clock::Timeout idleRetransTimeout, System::Clock::Timeout activeRetransTimeout,
50
45
System::Clock::Timeout activeThresholdTime)
51
46
{
52
- gIdleRetransTimeoutOverride = idleRetransTimeout;
53
- gActiveRetransTimeoutOverride = activeRetransTimeout;
54
- gActiveThresholdTimeOverride = activeThresholdTime;
47
+ idleRetransTimeoutOverride. SetValue ( idleRetransTimeout) ;
48
+ activeRetransTimeoutOverride. SetValue ( activeRetransTimeout) ;
49
+ activeThresholdTimeOverride. SetValue ( activeThresholdTime) ;
55
50
}
56
51
57
52
void ClearLocalMRPConfigOverride ()
58
53
{
59
- gActiveRetransTimeoutOverride = std::nullopt ;
60
- gIdleRetransTimeoutOverride = std::nullopt ;
61
- gActiveThresholdTimeOverride = std::nullopt ;
54
+ activeRetransTimeoutOverride. ClearValue () ;
55
+ idleRetransTimeoutOverride. ClearValue () ;
56
+ activeThresholdTimeOverride. ClearValue () ;
62
57
}
63
58
#endif
64
59
@@ -67,15 +62,14 @@ namespace {
67
62
68
63
// This is not a static member of ReliableMessageProtocolConfig because the free
69
64
// function GetLocalMRPConfig() needs access to it.
70
- // Use std::optional to avoid a static initializer
71
- std::optional<ReliableMessageProtocolConfig> sDynamicLocalMPRConfig ;
65
+ Optional<ReliableMessageProtocolConfig> sDynamicLocalMPRConfig ;
72
66
73
67
} // anonymous namespace
74
68
75
69
bool ReliableMessageProtocolConfig::SetLocalMRPConfig (const Optional<ReliableMessageProtocolConfig> & localMRPConfig)
76
70
{
77
71
auto oldConfig = GetLocalMRPConfig ();
78
- sDynamicLocalMPRConfig = localMRPConfig. std_optional () ;
72
+ sDynamicLocalMPRConfig = localMRPConfig;
79
73
return oldConfig != GetLocalMRPConfig ();
80
74
}
81
75
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
@@ -95,9 +89,9 @@ Optional<ReliableMessageProtocolConfig> GetLocalMRPConfig()
95
89
ReliableMessageProtocolConfig config (CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL);
96
90
97
91
#if CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
98
- if (sDynamicLocalMPRConfig .has_value ())
92
+ if (sDynamicLocalMPRConfig .HasValue ())
99
93
{
100
- config = sDynamicLocalMPRConfig .value ();
94
+ config = sDynamicLocalMPRConfig .Value ();
101
95
}
102
96
#endif // CHIP_DEVICE_CONFIG_ENABLE_DYNAMIC_MRP_CONFIG
103
97
@@ -111,19 +105,19 @@ Optional<ReliableMessageProtocolConfig> GetLocalMRPConfig()
111
105
#endif
112
106
113
107
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
114
- if (gIdleRetransTimeoutOverride . has_value ())
108
+ if (idleRetransTimeoutOverride. HasValue ())
115
109
{
116
- config.mIdleRetransTimeout = gIdleRetransTimeoutOverride . value ();
110
+ config.mIdleRetransTimeout = idleRetransTimeoutOverride. Value ();
117
111
}
118
112
119
- if (gActiveRetransTimeoutOverride . has_value ())
113
+ if (activeRetransTimeoutOverride. HasValue ())
120
114
{
121
- config.mActiveRetransTimeout = gActiveRetransTimeoutOverride . value ();
115
+ config.mActiveRetransTimeout = activeRetransTimeoutOverride. Value ();
122
116
}
123
117
124
- if (gActiveThresholdTimeOverride . has_value ())
118
+ if (activeThresholdTimeOverride. HasValue ())
125
119
{
126
- config.mActiveThresholdTime = gActiveThresholdTimeOverride . value ();
120
+ config.mActiveThresholdTime = activeRetransTimeoutOverride. Value ();
127
121
}
128
122
#endif
129
123
0 commit comments