PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewergenericmessage.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 95 lines | 56 code | 13 blank | 26 comment | 6 complexity | df718e98f2c2c4017ebb4021740bbf8d MD5 | raw file
 1/** 
 2 * @file llviewergenericmessage.cpp
 3 * @brief Handle processing of "generic messages" which contain short lists of strings.
 4 * @author James Cook
 5 *
 6 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 7 * Second Life Viewer Source Code
 8 * Copyright (C) 2010, Linden Research, Inc.
 9 * 
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation;
13 * version 2.1 of the License only.
14 * 
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Lesser General Public License for more details.
19 * 
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 * 
24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
25 * $/LicenseInfo$
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llviewergenericmessage.h"
31
32#include "lldispatcher.h"
33#include "lluuid.h"
34#include "message.h"
35
36#include "llagent.h"
37
38
39LLDispatcher gGenericDispatcher;
40
41
42void send_generic_message(const std::string& method,
43						  const std::vector<std::string>& strings,
44						  const LLUUID& invoice)
45{
46	LLMessageSystem* msg = gMessageSystem;
47	msg->newMessage("GenericMessage");
48	msg->nextBlockFast(_PREHASH_AgentData);
49	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
50	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
51	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
52	msg->nextBlock("MethodData");
53	msg->addString("Method", method);
54	msg->addUUID("Invoice", invoice);
55	if(strings.empty())
56	{
57		msg->nextBlock("ParamList");
58		msg->addString("Parameter", NULL);
59	}
60	else
61	{
62		std::vector<std::string>::const_iterator it = strings.begin();
63		std::vector<std::string>::const_iterator end = strings.end();
64		for(; it != end; ++it)
65		{
66			msg->nextBlock("ParamList");
67			msg->addString("Parameter", *it);
68		}
69	}
70	gAgent.sendReliableMessage();
71}
72
73
74
75void process_generic_message(LLMessageSystem* msg, void**)
76{
77	LLUUID agent_id;
78	msg->getUUID("AgentData", "AgentID", agent_id);
79	if (agent_id != gAgent.getID())
80	{
81		llwarns << "GenericMessage for wrong agent" << llendl;
82		return;
83	}
84
85	std::string request;
86	LLUUID invoice;
87	LLDispatcher::sparam_t strings;
88	LLDispatcher::unpackMessage(msg, request, invoice, strings);
89
90	if(!gGenericDispatcher.dispatch(request, invoice, strings))
91	{
92		llwarns << "GenericMessage " << request << " failed to dispatch" 
93			<< llendl;
94	}
95}