From 61e77bf6ed31b7f6857bdca4d51b5a21b40da10e Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sun, 22 Dec 2019 18:44:16 -0800 Subject: [PATCH] [topology] adding Neighbor::StateToString() (#4440) The `Neighbor::StateToString()` converts a given `Neighbor::State` to a human-readable string. --- src/core/thread/topology.cpp | 16 ++++++++++++++++ src/core/thread/topology.hpp | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/core/thread/topology.cpp b/src/core/thread/topology.cpp index 60b54653b..8dfebc21c 100644 --- a/src/core/thread/topology.cpp +++ b/src/core/thread/topology.cpp @@ -197,6 +197,22 @@ void Neighbor::RemoveAllForwardTrackingSeriesInfo(void) } #endif // OPENTHREAD_CONFIG_MLE_LINK_METRICS_ENABLE +const char *Neighbor::StateToString(State aState) +{ + static const char *kStateStrings[] = { + "Invalid", // kStateInvalid + "Restored", // kStateRestored + "ParentReq", // kStateParentRequest + "ParentRes", // kStateParentResponse + "ChildIdReq", // kStateChildIdRequest + "LinkReq", // kStateLinkRequest + "ChildUpdateReq", // kStateChildUpdateRequest + "Valid", // kStateValid + }; + + return static_cast(aState) < OT_ARRAY_LENGTH(kStateStrings) ? kStateStrings[aState] : "Unknown"; +} + void Child::Info::SetFrom(const Child &aChild) { Clear(); diff --git a/src/core/thread/topology.hpp b/src/core/thread/topology.hpp index bf7f28724..cecf3c9e1 100644 --- a/src/core/thread/topology.hpp +++ b/src/core/thread/topology.hpp @@ -645,6 +645,17 @@ public: void RemoveAllForwardTrackingSeriesInfo(void); #endif + + /** + * This method converts a given `State` to a human-readable string. + * + * @param[in] aState A neighbor state. + * + * @returns A string representation of given state. + * + */ + static const char *StateToString(State aState); + protected: /** * This method initializes the `Neighbor` object.