Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 4ad39b0

Browse files
authored
Merge pull request #427 from robszewczyk/bug/logic-bug-in-weave-time-client
Fix a logic bug and perform minor cleanup
2 parents ebabb5e + 18a02fd commit 4ad39b0

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/lib/profiles/time/WeaveTime.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,21 @@ class NL_DLL_EXPORT TimeSyncNode:
11081108

11091109
static void HandleAutoSyncTimeout(System::Layer* aSystemLayer, void* aAppState, System::Error aError);
11101110

1111+
/**
1112+
* @brief
1113+
* Determine whether given state is operational
1114+
*
1115+
* Convenience method to determine whether the ClientState denotes
1116+
* operational state, i.e. the client has completed initialization and is
1117+
* not in the process of shutting down.
1118+
*
1119+
* @param[in] aState state to be evaluated
1120+
*
1121+
* @return true if the state falls after the initialization has completed
1122+
* and before the shutdown has started, false otherwise.
1123+
*/
1124+
static inline bool IsOperationalState(ClientState aState) { return ((kClientState_BeginNormal < aState) && (aState < kClientState_EndNormal)); }
1125+
11111126
#endif // WEAVE_CONFIG_TIME_ENABLE_CLIENT
11121127
};
11131128

src/lib/profiles/time/WeaveTimeClient.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,11 @@ WEAVE_ERROR TimeSyncNode::Abort(void)
557557

558558
DestroyCommContext();
559559

560-
if ((kClientState_BeginNormal > state) || (kClientState_EndNormal < state))
561-
{
562-
// don't touch the state
563-
}
564-
else
560+
if (IsOperationalState(state))
565561
{
566562
SetClientState(kClientState_Idle);
567563
}
564+
// dont touch the state if its either initializing or shutting down
568565
}
569566

570567
exit:
@@ -1940,8 +1937,7 @@ void TimeSyncNode::HandleTimeChangeNotification(ExchangeContext *ec, const IPPac
19401937

19411938
// check internal state
19421939
// only try to decode if we're in any of these normal states
1943-
if ((kClientState_BeginNormal >= ClientStateAtEntry)
1944-
&& (kClientState_EndNormal <= ClientStateAtEntry))
1940+
if (!IsOperationalState(ClientStateAtEntry))
19451941
{
19461942
ExitNow(err = WEAVE_ERROR_INCORRECT_STATE);
19471943
}

0 commit comments

Comments
 (0)