From 7fbbd4b766a86c3b8d0d0ed3b9e2ebf3fd27a889 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 31 May 2019 16:42:07 -0400
Subject: [PATCH] SL-11216: Add a "getStateTable" op to "LLStartUp" listener.

getStateTable returns a list of the EStartupState symbolic names, implicitly
mapping each to its index (its enum numeric value).
---
 indra/newview/llstartup.h           |  1 +
 indra/newview/llstartuplistener.cpp | 26 +++++++++++++++++++++++++-
 indra/newview/llstartuplistener.h   |  1 +
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llstartup.h b/indra/newview/llstartup.h
index d7d294e9f4c..3ec3ff41330 100644
--- a/indra/newview/llstartup.h
+++ b/indra/newview/llstartup.h
@@ -128,6 +128,7 @@ class LLStartUp
 
 	static LLViewerStats::PhaseMap& getPhases() { return *sPhases; }
 private:
+	friend class LLStartupListener;
 	static LLSLURL sStartSLURL;
 
 	static std::string startupStateToString(EStartupState state);
diff --git a/indra/newview/llstartuplistener.cpp b/indra/newview/llstartuplistener.cpp
index d9a21f908ee..5770b595d08 100644
--- a/indra/newview/llstartuplistener.cpp
+++ b/indra/newview/llstartuplistener.cpp
@@ -35,7 +35,7 @@
 // external library headers
 // other Linden headers
 #include "llstartup.h"
-
+#include "stringize.h"
 
 LLStartupListener::LLStartupListener(/* LLStartUp* instance */):
     LLEventAPI("LLStartUp", "Access e.g. LLStartup::postStartupState()") /* ,
@@ -43,9 +43,33 @@ LLStartupListener::LLStartupListener(/* LLStartUp* instance */):
 {
     add("postStartupState", "Refresh \"StartupState\" listeners with current startup state",
         &LLStartupListener::postStartupState);
+    add("getStateTable", "Reply with array of EStartupState string names",
+        &LLStartupListener::getStateTable);
 }
 
 void LLStartupListener::postStartupState(const LLSD&) const
 {
     LLStartUp::postStartupState();
 }
+
+void LLStartupListener::getStateTable(const LLSD& event) const
+{
+    Response response(LLSD(), event);
+
+    // This relies on our knowledge that STATE_STARTED is the very last
+    // EStartupState value. If that ever stops being true, we're going to lie
+    // without realizing it. I can think of no reliable way to test whether
+    // the enum has been extended *beyond* STATE_STARTED. We could, of course,
+    // test whether stuff has been inserted before it, by testing its
+    // numerical value against the constant value as of the last time we
+    // looked; but that's pointless, as values inserted before STATE_STARTED
+    // will continue to work fine. The bad case is if new symbols get added
+    // *after* it.
+    LLSD table;
+    // note <= comparison: we want to *include* STATE_STARTED.
+    for (LLSD::Integer istate{0}; istate <= LLSD::Integer(STATE_STARTED); ++istate)
+    {
+        table.append(LLStartUp::startupStateToString(EStartupState(istate)));
+    }
+    response["table"] = table;
+}
diff --git a/indra/newview/llstartuplistener.h b/indra/newview/llstartuplistener.h
index a35e11f6ebc..0b4380a5684 100644
--- a/indra/newview/llstartuplistener.h
+++ b/indra/newview/llstartuplistener.h
@@ -40,6 +40,7 @@ class LLStartupListener: public LLEventAPI
 
 private:
     void postStartupState(const LLSD&) const;
+    void getStateTable(const LLSD&) const;
 
     //LLStartup* mStartup;
 };
-- 
GitLab