PageRenderTime 100ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  28. #include "llviewergenericmessage.h"
  29. #include "lldispatcher.h"
  30. #include "lluuid.h"
  31. #include "message.h"
  32. #include "llagent.h"
  33. LLDispatcher gGenericDispatcher;
  34. void send_generic_message(const std::string& method,
  35. const std::vector<std::string>& strings,
  36. const LLUUID& invoice)
  37. {
  38. LLMessageSystem* msg = gMessageSystem;
  39. msg->newMessage("GenericMessage");
  40. msg->nextBlockFast(_PREHASH_AgentData);
  41. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  42. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  43. msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
  44. msg->nextBlock("MethodData");
  45. msg->addString("Method", method);
  46. msg->addUUID("Invoice", invoice);
  47. if(strings.empty())
  48. {
  49. msg->nextBlock("ParamList");
  50. msg->addString("Parameter", NULL);
  51. }
  52. else
  53. {
  54. std::vector<std::string>::const_iterator it = strings.begin();
  55. std::vector<std::string>::const_iterator end = strings.end();
  56. for(; it != end; ++it)
  57. {
  58. msg->nextBlock("ParamList");
  59. msg->addString("Parameter", *it);
  60. }
  61. }
  62. gAgent.sendReliableMessage();
  63. }
  64. void process_generic_message(LLMessageSystem* msg, void**)
  65. {
  66. LLUUID agent_id;
  67. msg->getUUID("AgentData", "AgentID", agent_id);
  68. if (agent_id != gAgent.getID())
  69. {
  70. llwarns << "GenericMessage for wrong agent" << llendl;
  71. return;
  72. }
  73. std::string request;
  74. LLUUID invoice;
  75. LLDispatcher::sparam_t strings;
  76. LLDispatcher::unpackMessage(msg, request, invoice, strings);
  77. if(!gGenericDispatcher.dispatch(request, invoice, strings))
  78. {
  79. llwarns << "GenericMessage " << request << " failed to dispatch"
  80. << llendl;
  81. }
  82. }