PageRenderTime 62ms CodeModel.GetById 2ms app.highlight 50ms RepoModel.GetById 2ms app.codeStats 0ms

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