/indra/newview/llgesturelistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 159 lines · 105 code · 21 blank · 33 comment · 8 complexity · df466092aa92a810df35be51f8ac7ac2 MD5 · raw file

  1. /**
  2. * @file llgesturelistener.cpp
  3. * @author Dave Simmons
  4. * @date 2011-03-28
  5. * @brief Implementation for LLGestureListener.
  6. *
  7. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2011, 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. #include "llviewerprecompiledheaders.h"
  29. #include "llgesturelistener.h"
  30. #include "llgesturemgr.h"
  31. #include "llmultigesture.h"
  32. LLGestureListener::LLGestureListener()
  33. : LLEventAPI("LLGesture",
  34. "LLGesture listener interface to control gestures")
  35. {
  36. add("getActiveGestures",
  37. "Return information about the agent's available gestures [\"reply\"]:\n"
  38. "[\"gestures\"]: a dictionary with UUID strings as keys\n"
  39. " and the following dict values for each entry:\n"
  40. " [\"name\"]: name of the gesture, may be empty\n"
  41. " [\"trigger\"]: trigger string used to invoke via user chat, may be empty\n"
  42. " [\"playing\"]: true or false indicating the playing state",
  43. &LLGestureListener::getActiveGestures,
  44. LLSDMap("reply", LLSD()));
  45. add("isGesturePlaying",
  46. "[\"id\"]: UUID of the gesture to query. Returns True or False in [\"playing\"] value of the result",
  47. &LLGestureListener::isGesturePlaying);
  48. add("startGesture",
  49. "[\"id\"]: UUID of the gesture to start playing",
  50. &LLGestureListener::startGesture);
  51. add("stopGesture",
  52. "[\"id\"]: UUID of the gesture to stop",
  53. &LLGestureListener::stopGesture);
  54. }
  55. // "getActiveGestures" command
  56. void LLGestureListener::getActiveGestures(const LLSD& event_data) const
  57. {
  58. LLSD reply = LLSD::emptyMap();
  59. LLSD gesture_map = LLSD::emptyMap();
  60. const LLGestureMgr::item_map_t& active_gestures = LLGestureMgr::instance().getActiveGestures();
  61. // Scan active gesture map and get all the names
  62. LLGestureMgr::item_map_t::const_iterator it;
  63. for (it = active_gestures.begin(); it != active_gestures.end(); ++it)
  64. {
  65. LLMultiGesture* gesture = (*it).second;
  66. if (gesture)
  67. { // Add an entry to the result map with the LLUUID as key with a map containing data
  68. LLSD info = LLSD::emptyMap();
  69. info["name"] = (LLSD::String) gesture->mName;
  70. info["trigger"] = (LLSD::String) gesture->mTrigger;
  71. info["playing"] = (LLSD::Boolean) gesture->mPlaying;
  72. gesture_map[(*it).first.asString()] = info;
  73. }
  74. }
  75. reply["gestures"] = gesture_map;
  76. sendReply(reply, event_data);
  77. }
  78. // "isGesturePlaying" command
  79. void LLGestureListener::isGesturePlaying(const LLSD& event_data) const
  80. {
  81. bool is_playing = false;
  82. if (event_data.has("id"))
  83. {
  84. LLUUID gesture_id = event_data["id"].asUUID();
  85. if (gesture_id.notNull())
  86. {
  87. is_playing = LLGestureMgr::instance().isGesturePlaying(gesture_id);
  88. }
  89. else
  90. {
  91. llwarns << "isGesturePlaying did not find a gesture object for " << gesture_id << llendl;
  92. }
  93. }
  94. else
  95. {
  96. llwarns << "isGesturePlaying didn't have 'id' value passed in" << llendl;
  97. }
  98. LLSD reply = LLSD::emptyMap();
  99. reply["playing"] = (LLSD::Boolean) is_playing;
  100. sendReply(reply, event_data);
  101. }
  102. // "startGesture" command
  103. void LLGestureListener::startGesture(LLSD const & event_data) const
  104. {
  105. startOrStopGesture(event_data, true);
  106. }
  107. // "stopGesture" command
  108. void LLGestureListener::stopGesture(LLSD const & event_data) const
  109. {
  110. startOrStopGesture(event_data, false);
  111. }
  112. // Real code for "startGesture" or "stopGesture"
  113. void LLGestureListener::startOrStopGesture(LLSD const & event_data, bool start) const
  114. {
  115. if (event_data.has("id"))
  116. {
  117. LLUUID gesture_id = event_data["id"].asUUID();
  118. if (gesture_id.notNull())
  119. {
  120. if (start)
  121. {
  122. LLGestureMgr::instance().playGesture(gesture_id);
  123. }
  124. else
  125. {
  126. LLGestureMgr::instance().stopGesture(gesture_id);
  127. }
  128. }
  129. else
  130. {
  131. llwarns << "startOrStopGesture did not find a gesture object for " << gesture_id << llendl;
  132. }
  133. }
  134. else
  135. {
  136. llwarns << "startOrStopGesture didn't have 'id' value passed in" << llendl;
  137. }
  138. }