Commits

nat_linden committed e412efe

DEV-40930: Added ["change"] key to login-module status events. Changed
existing event calls to use state as "offline" or "online", with "change"
indicating the reason for this status event. Changed disconnect() to send
state "offline", change "disconnect" -- instead of replaying last auth
failure. Changed unit tests accordingly.
Changed LLLoginInstance::handleLoginEvent() to use LLEventDispatcher to route
calls to handleLoginFailure() et al.
Added LLEventDispatcher::get() to allow retrieving Callable by name and
testing for empty().

  • Participants
  • Parent commits a1ddb13

Comments (0)

Files changed (7)

File indra/llcommon/lleventdispatcher.cpp

     return true;                    // tell caller we were able to call
 }
 
+LLEventDispatcher::Callable LLEventDispatcher::get(const std::string& name) const
+{
+    DispatchMap::const_iterator found = mDispatch.find(name);
+    if (found == mDispatch.end())
+    {
+        return Callable();
+    }
+    return found->second.first;
+}
+
 LLDispatchListener::LLDispatchListener(const std::string& pumpname, const std::string& key):
     LLEventDispatcher(pumpname, key),
     mPump(pumpname, true),          // allow tweaking for uniqueness

File indra/llcommon/lleventdispatcher.h

     /// @a required prototype specified at add() time, die with LL_ERRS.
     void operator()(const LLSD& event) const;
 
+    /// Fetch the Callable for the specified name. If no such name was
+    /// registered, return an empty() Callable.
+    Callable get(const std::string& name) const;
+
 private:
     template <class CLASS, typename METHOD>
     void addMethod(const std::string& name, const METHOD& method, const LLSD& required)

File indra/newview/lllogininstance.cpp

 	mUserInteraction(true),
 	mSkipOptionalUpdate(false),
 	mAttemptComplete(false),
-	mTransferRate(0.0f)
+	mTransferRate(0.0f),
+	mDispatcher("LLLoginInstance", "change")
 {
 	mLoginModule->getEventPump().listen("lllogininstance", 
 		boost::bind(&LLLoginInstance::handleLoginEvent, this, _1));
+	mDispatcher.add("fail.login", boost::bind(&LLLoginInstance::handleLoginFailure, this, _1));
+	mDispatcher.add("connect",    boost::bind(&LLLoginInstance::handleLoginSuccess, this, _1));
+	mDispatcher.add("disconnect", boost::bind(&LLLoginInstance::handleDisconnect, this, _1));
 }
 
 LLLoginInstance::~LLLoginInstance()
 	std::cout << "LoginListener called!: \n";
 	std::cout << event << "\n";
 
-	if(!(event.has("state") && event.has("progress")))
+	if(!(event.has("state") && event.has("change") && event.has("progress")))
 	{
-		llerrs << "Unknown message from LLLogin!" << llendl;
+		llerrs << "Unknown message from LLLogin: " << event << llendl;
 	}
 
 	mLoginState = event["state"].asString();
 		mTransferRate = event["transfer_rate"].asReal();
 	}
 
-	if(mLoginState == "offline")
+	// Call the method registered in constructor, if any, for more specific
+	// handling
+	LLEventDispatcher::Callable method(mDispatcher.get(event["change"]));
+	if (! method.empty())
 	{
-		handleLoginFailure(event);
+		method(event);
 	}
-	else if(mLoginState == "online")
-	{
-		handleLoginSuccess(event);
-	}
-
 	return false;
 }
 
-bool LLLoginInstance::handleLoginFailure(const LLSD& event)
+void LLLoginInstance::handleLoginFailure(const LLSD& event)
 {
 	// Login has failed. 
 	// Figure out why and respond...
 	{
 		attemptComplete();
 	}
-
-	return false;
 }
 
-bool LLLoginInstance::handleLoginSuccess(const LLSD& event)
+void LLLoginInstance::handleLoginSuccess(const LLSD& event)
 {
 	if(gSavedSettings.getBOOL("ForceMandatoryUpdate"))
 	{
 	{
 		attemptComplete();
 	}
-	return false;
+}
+
+void LLLoginInstance::handleDisconnect(const LLSD& event)
+{
+    // placeholder
 }
 
 bool LLLoginInstance::handleTOSResponse(bool accepted, const std::string& key)

File indra/newview/lllogininstance.h

 #ifndef LL_LLLOGININSTANCE_H
 #define LL_LLLOGININSTANCE_H
 
+#include "lleventdispatcher.h"
 #include <boost/scoped_ptr.hpp>
 #include <boost/function.hpp>
 class LLLogin;
 	bool updateDialogCallback(const LLSD& notification, const LLSD& response);
 
 	bool handleLoginEvent(const LLSD& event);
-	bool handleLoginFailure(const LLSD& event);
-	bool handleLoginSuccess(const LLSD& event);
+	void handleLoginFailure(const LLSD& event);
+	void handleLoginSuccess(const LLSD& event);
+	void handleDisconnect(const LLSD& event);
 
 	bool handleTOSResponse(bool v, const std::string& key);
 
 	int mLastExecEvent;
 	UpdaterLauncherCallback mUpdaterLauncher;
 	boost::scoped_ptr<LLEventStream> mUpdateAppResponse;
+	LLEventDispatcher mDispatcher;
 };
 
 #endif

File indra/newview/tests/lllogininstance_test.cpp

 		// Dummy success response.
 		LLSD response;
 		response["state"] = "online";
+		response["change"] = "connect";
 		response["progress"] = 1.0;
 		response["transfer_rate"] = 7;
 		response["data"] = "test_data";
 
 		response.clear();
 		response["state"] = "offline";
+		response["change"] = "disconnect";
 		response["progress"] = 0.0;
 		response["transfer_rate"] = 0;
 		response["data"] = "test_data";
 		// TOS failure response.
 		LLSD response;
 		response["state"] = "offline";
+		response["change"] = "fail.login";
 		response["progress"] = 0.0;
 		response["transfer_rate"] = 7;
 		response["data"]["reason"] = "tos";
 		// Update needed failure response.
 		LLSD response;
 		response["state"] = "offline";
+		response["change"] = "fail.login";
 		response["progress"] = 0.0;
 		response["transfer_rate"] = 7;
 		response["data"]["reason"] = "update";
 		// Update needed failure response.
 		LLSD response;
 		response["state"] = "offline";
+		response["change"] = "fail.login";
 		response["progress"] = 0.0;
 		response["transfer_rate"] = 7;
 		response["data"]["reason"] = "update";
 		// Update needed failure response.
 		LLSD response;
 		response["state"] = "offline";
+		response["change"] = "fail.login";
 		response["progress"] = 0.0;
 		response["transfer_rate"] = 7;
 		response["data"]["reason"] = "optional";
 		// Update needed failure response.
 		LLSD response;
 		response["state"] = "offline";
+		response["change"] = "fail.login";
 		response["progress"] = 0.0;
 		response["transfer_rate"] = 7;
 		response["data"]["reason"] = "optional";

File indra/viewer_components/login/lllogin.cpp

 	LLEventPump& getEventPump() { return mPump; }
 
 private:
-	void sendProgressEvent(const std::string& desc, const LLSD& data = LLSD::emptyMap())
+	void sendProgressEvent(const std::string& state, const std::string& change,
+						   const LLSD& data = LLSD())
 	{
 		LLSD status_data;
-		status_data["state"] = desc;
+		status_data["state"] = state;
+		status_data["change"] = change;
 		status_data["progress"] = 0.0f;
 
 		if(mAuthResponse.has("transfer_rate"))
 			status_data["transfer_rate"] = mAuthResponse["transfer_rate"];
 		}
 
-		if(data.size() != 0)
+		if(data.isDefined())
 		{
 			status_data["data"] = data;
 		}
     LLSD rewrittenURIs;
     {
         LLEventTimeout filter(replyPump);
-        sendProgressEvent("srvrequest");
+        sendProgressEvent("offline", "srvrequest");
 
         // Request SRV record.
         LL_INFOS("LLLogin") << "Requesting SRV record from " << uri << LL_ENDL;
             LLSD progress_data;
             progress_data["attempt"] = attempts;
             progress_data["request"] = request;
-            sendProgressEvent("authenticating", progress_data);
+            sendProgressEvent("offline", "authenticating", progress_data);
 
             // We expect zero or more "Downloading" status events, followed by
             // exactly one event with some other status. Use postAndWait() the
                                      waitForEventOn(self, replyPump)))
             {
                 // Still Downloading -- send progress update.
-                sendProgressEvent("downloading");
+                sendProgressEvent("offline", "downloading");
             }
             status = mAuthResponse["status"].asString();
 
             // StatusComplete does not imply auth success. Check the
             // actual outcome of the request. We've already handled the
             // "indeterminate" case in the loop above.
-            sendProgressEvent((mAuthResponse["responses"]["login"].asString() == "true")?
-                              "online" : "offline",
-                              mAuthResponse["responses"]);
+            if (mAuthResponse["responses"]["login"].asString() == "true")
+            {
+                sendProgressEvent("online", "connect", mAuthResponse["responses"]);
+            }
+            else
+            {
+                sendProgressEvent("offline", "fail.login", mAuthResponse["responses"]);
+            }
             return;             // Done!
         }
         // If we don't recognize status at all, trouble
     // Here we got through all the rewrittenURIs without succeeding. Tell
     // caller this didn't work out so well. Of course, the only failure data
     // we can reasonably show are from the last of the rewrittenURIs.
-    sendProgressEvent("offline", mAuthResponse["responses"]);
+    sendProgressEvent("offline", "fail.login", mAuthResponse["responses"]);
 }
 
 void LLLogin::Impl::disconnect()
 {
-    sendProgressEvent("offline", mAuthResponse["responses"]);
+    sendProgressEvent("offline", "disconnect");
 }
 
 //*********************

File indra/viewer_components/login/tests/lllogin_test.cpp

 
 		login.connect("login.bar.com", credentials);
 
-		ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); 
+		ensure_equals("SRV state", listener.lastEvent()["change"].asString(), "srvrequest"); 
 
 		dummyLLAres.sendReply();
 
 		// Test Authenticating State prior to first response.
-		ensure_equals("Auth state 1", listener.lastEvent()["state"].asString(), "authenticating"); 
+		ensure_equals("Auth state 1", listener.lastEvent()["change"].asString(), "authenticating"); 
 		ensure_equals("Attempt 1", listener.lastEvent()["data"]["attempt"].asInteger(), 1); 
 		ensure_equals("URI 1", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.foo.com"); 
 
 		dummyXMLRPC.setResponse(data);
 		dummyXMLRPC.sendReply();
 
-		ensure_equals("Fail back to authenticate 1", listener.lastEvent()["state"].asString(), "authenticating"); 
+		ensure_equals("Fail back to authenticate 1", listener.lastEvent()["change"].asString(), "authenticating"); 
 		ensure_equals("Attempt 2", listener.lastEvent()["data"]["attempt"].asInteger(), 2); 
 		ensure_equals("URI 2", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.bar.com"); 
 
 		dummyXMLRPC.setResponse(data);
 		dummyXMLRPC.sendReply();
 
-		ensure_equals("Fail back to authenticate 2", listener.lastEvent()["state"].asString(), "authenticating"); 
+		ensure_equals("Fail back to authenticate 2", listener.lastEvent()["change"].asString(), "authenticating"); 
 		ensure_equals("Attempt 3", listener.lastEvent()["data"]["attempt"].asInteger(), 3); 
 		ensure_equals("URI 3", listener.lastEvent()["data"]["request"]["uri"].asString(), "login.indeterminate.com"); 
 
 
 		login.connect("login.bar.com", credentials);
 
-		ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); 
+		ensure_equals("SRV state", listener.lastEvent()["change"].asString(), "srvrequest"); 
 
 		dummyLLAres.sendReply();
 
-		ensure_equals("Auth state", listener.lastEvent()["state"].asString(), "authenticating"); 
+		ensure_equals("Auth state", listener.lastEvent()["change"].asString(), "authenticating"); 
 
 		// Send the failed auth request reponse
 		LLSD data;
 
 		login.connect("login.bar.com", credentials);
 
-		ensure_equals("SRV state", listener.lastEvent()["state"].asString(), "srvrequest"); 
+		ensure_equals("SRV state", listener.lastEvent()["change"].asString(), "srvrequest"); 
 
 		dummyLLAres.sendReply();
 
-		ensure_equals("Auth state", listener.lastEvent()["state"].asString(), "authenticating"); 
+		ensure_equals("Auth state", listener.lastEvent()["change"].asString(), "authenticating"); 
 
 		// Send the failed auth request reponse
 		LLSD data;