Skip to content
Snippets Groups Projects
Commit 4ef02bc1 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

Introduce and use new sendReply() function for LLEventAPI methods.

Each LLEventAPI method that generates a reply needs to extract the name of the
reply LLEventPump from the request, typically from a ["reply"] key, copy the
["reqid"] value from request to reply, locate the reply LLEventPump and send
the enriched reply object. Encapsulate in sendReply() function before we
proliferate doing all that by hand too many more times.
parent 89258376
No related branches found
No related tags found
No related merge requests found
...@@ -588,3 +588,16 @@ void LLReqID::stamp(LLSD& response) const ...@@ -588,3 +588,16 @@ void LLReqID::stamp(LLSD& response) const
} }
response["reqid"] = mReqid; response["reqid"] = mReqid;
} }
bool sendReply(const LLSD& reply, const LLSD& request, const std::string& replyKey)
{
// Copy 'reply' to modify it.
LLSD newreply(reply);
// Get the ["reqid"] element from request
LLReqID reqID(request);
// and copy it to 'newreply'.
reqID.stamp(newreply);
// Send reply on LLEventPump named in request[replyKey]. Don't forget to
// send the modified 'newreply' instead of the original 'reply'.
return LLEventPumps::instance().obtain(request[replyKey]).post(newreply);
}
...@@ -691,6 +691,20 @@ class LL_COMMON_API LLReqID ...@@ -691,6 +691,20 @@ class LL_COMMON_API LLReqID
LLSD mReqid; LLSD mReqid;
}; };
/**
* Conventionally send a reply to a request event.
*
* @a reply is the LLSD reply event to send
* @a request is the corresponding LLSD request event
* @a replyKey is the key in the @a request event, conventionally ["reply"],
* whose value is the name of the LLEventPump on which to send the reply.
*
* Before sending the reply event, sendReply() copies the ["reqid"] item from
* the request to the reply.
*/
LL_COMMON_API bool sendReply(const LLSD& reply, const LLSD& request,
const std::string& replyKey="reply");
/** /**
* Base class for LLListenerWrapper. See visit_and_connect() and llwrap(). We * Base class for LLListenerWrapper. See visit_and_connect() and llwrap(). We
* provide virtual @c accept_xxx() methods, customization points allowing a * provide virtual @c accept_xxx() methods, customization points allowing a
......
...@@ -76,9 +76,7 @@ LLFloaterRegListener::LLFloaterRegListener(): ...@@ -76,9 +76,7 @@ LLFloaterRegListener::LLFloaterRegListener():
void LLFloaterRegListener::getBuildMap(const LLSD& event) const void LLFloaterRegListener::getBuildMap(const LLSD& event) const
{ {
// Honor the "reqid" convention by echoing event["reqid"] in our reply packet. LLSD reply;
LLReqID reqID(event);
LLSD reply(reqID.makeResponse());
// Build an LLSD map that mirrors sBuildMap. Since we have no good way to // Build an LLSD map that mirrors sBuildMap. Since we have no good way to
// represent a C++ callable in LLSD, the only part of BuildData we can // represent a C++ callable in LLSD, the only part of BuildData we can
// store is the filename. For each LLSD map entry, it would be more // store is the filename. For each LLSD map entry, it would be more
...@@ -91,7 +89,7 @@ void LLFloaterRegListener::getBuildMap(const LLSD& event) const ...@@ -91,7 +89,7 @@ void LLFloaterRegListener::getBuildMap(const LLSD& event) const
reply[mi->first] = mi->second.mFile; reply[mi->first] = mi->second.mFile;
} }
// Send the reply to the LLEventPump named in event["reply"]. // Send the reply to the LLEventPump named in event["reply"].
LLEventPumps::instance().obtain(event["reply"]).post(reply); sendReply(reply, event);
} }
void LLFloaterRegListener::showInstance(const LLSD& event) const void LLFloaterRegListener::showInstance(const LLSD& event) const
...@@ -111,10 +109,8 @@ void LLFloaterRegListener::toggleInstance(const LLSD& event) const ...@@ -111,10 +109,8 @@ void LLFloaterRegListener::toggleInstance(const LLSD& event) const
void LLFloaterRegListener::instanceVisible(const LLSD& event) const void LLFloaterRegListener::instanceVisible(const LLSD& event) const
{ {
LLReqID reqID(event); sendReply(LLSDMap("visible", LLFloaterReg::instanceVisible(event["name"], event["key"])),
LLSD reply(reqID.makeResponse()); event);
reply["visible"] = LLFloaterReg::instanceVisible(event["name"], event["key"]);
LLEventPumps::instance().obtain(event["reply"]).post(reply);
} }
void LLFloaterRegListener::clickButton(const LLSD& event) const void LLFloaterRegListener::clickButton(const LLSD& event) const
......
...@@ -37,16 +37,12 @@ LLSideTrayListener::LLSideTrayListener(const Getter& getter): ...@@ -37,16 +37,12 @@ LLSideTrayListener::LLSideTrayListener(const Getter& getter):
void LLSideTrayListener::getCollapsed(const LLSD& event) const void LLSideTrayListener::getCollapsed(const LLSD& event) const
{ {
LLReqID reqID(event); sendReply(LLSDMap("open", ! mGetter()->getCollapsed()), event);
LLSD reply(reqID.makeResponse());
reply["open"] = ! mGetter()->getCollapsed();
LLEventPumps::instance().obtain(event["reply"]).post(reply);
} }
void LLSideTrayListener::getTabs(const LLSD& event) const void LLSideTrayListener::getTabs(const LLSD& event) const
{ {
LLReqID reqID(event); LLSD reply;
LLSD reply(reqID.makeResponse());
LLSideTray* tray = mGetter(); LLSideTray* tray = mGetter();
LLSD::Integer ord(0); LLSD::Integer ord(0);
...@@ -68,7 +64,7 @@ void LLSideTrayListener::getTabs(const LLSD& event) const ...@@ -68,7 +64,7 @@ void LLSideTrayListener::getTabs(const LLSD& event) const
reply[child->getName()] = info; reply[child->getName()] = info;
} }
LLEventPumps::instance().obtain(event["reply"]).post(reply); sendReply(reply, event);
} }
static LLSD getTabInfo(LLPanel* tab) static LLSD getTabInfo(LLPanel* tab)
...@@ -133,8 +129,7 @@ static LLSD getTabInfo(LLPanel* tab) ...@@ -133,8 +129,7 @@ static LLSD getTabInfo(LLPanel* tab)
void LLSideTrayListener::getPanels(const LLSD& event) const void LLSideTrayListener::getPanels(const LLSD& event) const
{ {
LLReqID reqID(event); LLSD reply;
LLSD reply(reqID.makeResponse());
LLSideTray* tray = mGetter(); LLSideTray* tray = mGetter();
// Iterate through the attached tabs. // Iterate through the attached tabs.
...@@ -163,5 +158,5 @@ void LLSideTrayListener::getPanels(const LLSD& event) const ...@@ -163,5 +158,5 @@ void LLSideTrayListener::getPanels(const LLSD& event) const
reply[tab->getName()] = getTabInfo(tab).with("attached", false).with("ord", ord); reply[tab->getName()] = getTabInfo(tab).with("attached", false).with("ord", ord);
} }
LLEventPumps::instance().obtain(event["reply"]).post(reply); sendReply(reply, event);
} }
...@@ -65,7 +65,6 @@ LLViewerWindowListener::LLViewerWindowListener(LLViewerWindow* llviewerwindow): ...@@ -65,7 +65,6 @@ LLViewerWindowListener::LLViewerWindowListener(LLViewerWindow* llviewerwindow):
void LLViewerWindowListener::saveSnapshot(const LLSD& event) const void LLViewerWindowListener::saveSnapshot(const LLSD& event) const
{ {
LLReqID reqid(event);
typedef std::map<LLSD::String, LLViewerWindow::ESnapshotType> TypeMap; typedef std::map<LLSD::String, LLViewerWindow::ESnapshotType> TypeMap;
TypeMap types; TypeMap types;
#define tp(name) types[#name] = LLViewerWindow::SNAPSHOT_TYPE_##name #define tp(name) types[#name] = LLViewerWindow::SNAPSHOT_TYPE_##name
...@@ -98,9 +97,7 @@ void LLViewerWindowListener::saveSnapshot(const LLSD& event) const ...@@ -98,9 +97,7 @@ void LLViewerWindowListener::saveSnapshot(const LLSD& event) const
type = found->second; type = found->second;
} }
bool ok = mViewerWindow->saveSnapshot(event["filename"], width, height, showui, rebuild, type); bool ok = mViewerWindow->saveSnapshot(event["filename"], width, height, showui, rebuild, type);
LLSD response(reqid.makeResponse()); sendReply(LLSDMap("ok", ok), event);
response["ok"] = ok;
LLEventPumps::instance().obtain(event["reply"]).post(response);
} }
void LLViewerWindowListener::requestReshape(LLSD const & event_data) const void LLViewerWindowListener::requestReshape(LLSD const & event_data) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment