PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llcommanddispatcherlistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 77 lines | 37 code | 4 blank | 36 comment | 1 complexity | 659923abe211a0604c108ee152047715 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcommanddispatcherlistener.cpp
  3. * @author Nat Goodspeed
  4. * @date 2009-12-10
  5. * @brief Implementation for llcommanddispatcherlistener.
  6. *
  7. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. // Precompiled header
  29. #include "llviewerprecompiledheaders.h"
  30. // associated header
  31. #include "llcommanddispatcherlistener.h"
  32. // STL headers
  33. // std headers
  34. // external library headers
  35. // other Linden headers
  36. #include "llcommandhandler.h"
  37. LLCommandDispatcherListener::LLCommandDispatcherListener(/* LLCommandDispatcher* instance */):
  38. LLEventAPI("LLCommandDispatcher", "Access to LLCommandHandler commands") /* ,
  39. mDispatcher(instance) */
  40. {
  41. add("dispatch",
  42. "Execute a command registered as an LLCommandHandler,\n"
  43. "passing any required parameters:\n"
  44. "[\"cmd\"] string command name\n"
  45. "[\"params\"] array of parameters, as if from components of URL path\n"
  46. "[\"query\"] map of parameters, as if from ?key1=val&key2=val\n"
  47. "[\"trusted\"] boolean indicating trusted browser [default true]",
  48. &LLCommandDispatcherListener::dispatch);
  49. add("enumerate",
  50. "Post to [\"reply\"] a map of registered LLCommandHandler instances, containing\n"
  51. "name key and (e.g.) untrusted flag",
  52. &LLCommandDispatcherListener::enumerate,
  53. LLSD().with("reply", LLSD()));
  54. }
  55. void LLCommandDispatcherListener::dispatch(const LLSD& params) const
  56. {
  57. // For most purposes, we expect callers to want to be trusted.
  58. bool trusted_browser = true;
  59. if (params.has("trusted"))
  60. {
  61. // But for testing, allow a caller to specify untrusted.
  62. trusted_browser = params["trusted"].asBoolean();
  63. }
  64. LLCommandDispatcher::dispatch(params["cmd"], params["params"], params["query"], NULL,
  65. "clicked", trusted_browser);
  66. }
  67. void LLCommandDispatcherListener::enumerate(const LLSD& params) const
  68. {
  69. LLReqID reqID(params);
  70. LLSD response(LLCommandDispatcher::enumerate());
  71. reqID.stamp(response);
  72. LLEventPumps::instance().obtain(params["reply"]).post(response);
  73. }