From 33068c6da8f079c557e4fb520b074f6e5ce40ba4 Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Wed, 14 Nov 2012 10:40:51 -0800
Subject: CHUI-479 : WIP : Add debug tracing into speaking indicator manager
 and monitors (to be deleted eventually).

---
 indra/newview/llconversationmodel.cpp        | 10 +++++++++
 indra/newview/llconversationmodel.h          |  1 +
 indra/newview/llconversationview.cpp         | 32 ++++++++++++++++++++++++++++
 indra/newview/llconversationview.h           |  8 +++++--
 indra/newview/lloutputmonitorctrl.cpp        | 29 +++++++++++++++++++++++--
 indra/newview/llspeakingindicatormanager.cpp |  7 ++++++
 indra/newview/llspeakingindicatormanager.h   |  2 +-
 7 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/indra/newview/llconversationmodel.cpp b/indra/newview/llconversationmodel.cpp
index 47a82bfe17..8aa740e5d1 100644
--- a/indra/newview/llconversationmodel.cpp
+++ b/indra/newview/llconversationmodel.cpp
@@ -440,6 +440,16 @@ void LLConversationItemParticipant::onAvatarNameCache(const LLAvatarName& av_nam
 	}
 }
 
+LLConversationItemSession* LLConversationItemParticipant::getParentSession()
+{
+	LLConversationItemSession* parent_session = NULL;
+	if (hasParent())
+	{
+		parent_session = dynamic_cast<LLConversationItemSession*>(mParent);
+	}
+	return parent_session;
+}
+
 void LLConversationItemParticipant::dumpDebugData()
 {
 	llinfos << "Merov debug : participant, uuid = " << mUUID << ", name = " << mName << ", display name = " << mDisplayName << ", muted = " << mIsMuted << ", moderator = " << mIsModerator << llendl;
diff --git a/indra/newview/llconversationmodel.h b/indra/newview/llconversationmodel.h
index 481d46af58..2ee21d0c16 100755
--- a/indra/newview/llconversationmodel.h
+++ b/indra/newview/llconversationmodel.h
@@ -195,6 +195,7 @@ public:
 	virtual const bool getDistanceToAgent(F64& dist) const { dist = mDistToAgent; return (dist >= 0.0); }
 
 	void fetchAvatarName();
+	LLConversationItemSession* getParentSession();
 
 	void dumpDebugData();
 
diff --git a/indra/newview/llconversationview.cpp b/indra/newview/llconversationview.cpp
index 295dd2ae6d..11eef3f7dc 100755
--- a/indra/newview/llconversationview.cpp
+++ b/indra/newview/llconversationview.cpp
@@ -327,6 +327,7 @@ void LLConversationViewSession::onCurrentVoiceSessionChanged(const LLUUID& sessi
 			mSpeakingIndicator->setSpeakerId(is_active ? gAgentID : LLUUID::null);
 		}
 
+		llinfos << "Merov debug : onCurrentVoiceSessionChanged, switchIndicator is_active = " << is_active << llendl;
 		mSpeakingIndicator->switchIndicator(is_active);
 		mCallIconLayoutPanel->setVisible(is_active);
 	}
@@ -366,6 +367,11 @@ LLConversationViewParticipant::LLConversationViewParticipant( const LLConversati
 {
 }
 
+LLConversationViewParticipant::~LLConversationViewParticipant()
+{
+	mActiveVoiceChannelConnection.disconnect();
+}
+
 void LLConversationViewParticipant::initFromParams(const LLConversationViewParticipant::Params& params)
 {	
     LLAvatarIconCtrl::Params avatar_icon_params(params.avatar_icon());
@@ -392,6 +398,7 @@ BOOL LLConversationViewParticipant::postBuild()
 	mInfoBtn->setClickedCallback(boost::bind(&LLConversationViewParticipant::onInfoBtnClick, this));
 	mInfoBtn->setVisible(false);
 
+	mActiveVoiceChannelConnection = LLVoiceChannel::setCurrentVoiceChannelChangedCallback(boost::bind(&LLConversationViewParticipant::onCurrentVoiceSessionChanged, this, _1));
 	mSpeakingIndicator = getChild<LLOutputMonitorCtrl>("speaking_indicator");
 
     if (!sStaticInitialized)
@@ -445,6 +452,29 @@ S32 LLConversationViewParticipant::arrange(S32* width, S32* height)
     return arranged;
 }
 
+void LLConversationViewParticipant::onCurrentVoiceSessionChanged(const LLUUID& session_id)
+{
+	llinfos << "Merov debug : onCurrentVoiceSessionChanged begin, uuid = " << mUUID << ", session_id = " << session_id << llendl;
+	LLConversationItemParticipant* participant_model = dynamic_cast<LLConversationItemParticipant*>(getViewModelItem());
+	//llinfos << "Merov debug : onCurrentVoiceSessionChanged participant_model = " << participant_model << llendl;
+	
+	if (participant_model)
+	{
+		//llinfos << "Merov debug : onCurrentVoiceSessionChanged enter if 1" << llendl;
+		LLConversationItemSession* parent_session = participant_model->getParentSession();
+		//llinfos << "Merov debug : onCurrentVoiceSessionChanged parent_session = " << parent_session << llendl;
+		if (parent_session)
+		{
+			//llinfos << "Merov debug : onCurrentVoiceSessionChanged enter if 2" << llendl;
+			bool is_active = (parent_session->getUUID() == session_id);
+			//llinfos << "Merov debug : onCurrentVoiceSessionChanged, is_active = " << is_active << llendl;
+			mSpeakingIndicator->switchIndicator(is_active);
+			//llinfos << "Merov debug : onCurrentVoiceSessionChanged switchIndicator done" << llendl;
+		}
+	}
+	//llinfos << "Merov debug : onCurrentVoiceSessionChanged end" << llendl;
+}
+
 void LLConversationViewParticipant::refresh()
 {
 	// Refresh the participant view from its model data
@@ -453,6 +483,7 @@ void LLConversationViewParticipant::refresh()
 	
 	// *TODO: We should also do something with vmi->isModerator() to echo that state in the UI somewhat
 	mSpeakingIndicator->setIsMuted(vmi->isMuted());
+	//mSpeakingIndicator->switchIndicator(true);
 	
 	// Do the regular upstream refresh
 	LLFolderViewItem::refresh();
@@ -471,6 +502,7 @@ void LLConversationViewParticipant::addToFolder(LLFolderViewFolder* folder)
         mAvatarIcon->setValue(mUUID);
 
         //Allows the speaker indicator to be activated based on the user and conversation
+//		llinfos << "Merov debug : setSpeakerId of " << mUUID << ", session id = " << vmi->getUUID() << llendl;
         mSpeakingIndicator->setSpeakerId(mUUID, vmi->getUUID()); 
     }
 }
diff --git a/indra/newview/llconversationview.h b/indra/newview/llconversationview.h
index cc6995c207..4b2c9b2d76 100755
--- a/indra/newview/llconversationview.h
+++ b/indra/newview/llconversationview.h
@@ -94,7 +94,7 @@ private:
 	bool					mMinimizedMode;
 
 	LLVoiceClientStatusObserver* mVoiceClientObserver;
-
+	
 	boost::signals2::connection mActiveVoiceChannelConnection;
 };
 
@@ -116,7 +116,7 @@ public:
 		Params();
 	};
 	
-    virtual ~LLConversationViewParticipant( void ) { }
+    virtual ~LLConversationViewParticipant( void );
 
     bool hasSameValue(const LLUUID& uuid) { return (uuid == mUUID); }
     virtual void refresh();
@@ -140,6 +140,8 @@ protected:
 	void onInfoBtnClick();
 
 private:
+	void onCurrentVoiceSessionChanged(const LLUUID& session_id);
+
     LLAvatarIconCtrl* mAvatarIcon;
 	LLButton * mInfoBtn;
     LLOutputMonitorCtrl* mSpeakingIndicator;
@@ -156,6 +158,8 @@ private:
     static void initChildrenWidths(LLConversationViewParticipant* self);
     void updateChildren();
     LLView* getItemChildView(EAvatarListItemChildIndex child_view_index);
+	
+	boost::signals2::connection mActiveVoiceChannelConnection;
 };
 
 #endif // LL_LLCONVERSATIONVIEW_H
diff --git a/indra/newview/lloutputmonitorctrl.cpp b/indra/newview/lloutputmonitorctrl.cpp
index 4a9a50d96a..3569516388 100644
--- a/indra/newview/lloutputmonitorctrl.cpp
+++ b/indra/newview/lloutputmonitorctrl.cpp
@@ -278,21 +278,45 @@ BOOL LLOutputMonitorCtrl::handleMouseUp(S32 x, S32 y, MASK mask)
 
 void LLOutputMonitorCtrl::setSpeakerId(const LLUUID& speaker_id, const LLUUID& session_id/* = LLUUID::null*/, bool show_other_participants_speaking /* = false */)
 {
+	static LLUUID test_uuid("c684ce33-89fb-4544-8f7b-dae243c8b214");
+	bool test_on = (speaker_id == test_uuid);
+	if (test_on)
+	{
+		llinfos << "Merov debug : setSpeakerId, this = " << this << ", session_id = " << session_id << llendl;
+	}
 	if (speaker_id.isNull() && mSpeakerId.notNull())
 	{
 		LLSpeakingIndicatorManager::unregisterSpeakingIndicator(mSpeakerId, this);
 	}
 
-	if (speaker_id.isNull() || speaker_id == mSpeakerId) return;
+	if (speaker_id.isNull() || speaker_id == mSpeakerId) 
+	{
+		if (test_on)
+		{
+			llinfos << "Merov debug : setSpeakerId, nothing done because mSpeakerId == speaker_id" << llendl;
+		}
+		return;
+	}
 
 	if (mSpeakerId.notNull())
 	{
+		if (test_on)
+		{
+			llinfos << "Merov debug : setSpeakerId, unregisterSpeakingIndicator" << llendl;
+		}
 		// Unregister previous registration to avoid crash. EXT-4782.
-		LLSpeakingIndicatorManager::unregisterSpeakingIndicator(mSpeakerId, this);
+		if (getTargetSessionID() == session_id)
+		{
+			LLSpeakingIndicatorManager::unregisterSpeakingIndicator(mSpeakerId, this);
+		}
 	}
 
 	mShowParticipantsSpeaking = show_other_participants_speaking;
 	mSpeakerId = speaker_id;
+	if (test_on)
+	{
+		llinfos << "Merov debug : setSpeakerId, registerSpeakingIndicator" << llendl;
+	}
 	LLSpeakingIndicatorManager::registerSpeakingIndicator(mSpeakerId, this, session_id);
 
 	//mute management
@@ -320,6 +344,7 @@ void LLOutputMonitorCtrl::onChange()
 // virtual
 void LLOutputMonitorCtrl::switchIndicator(bool switch_on)
 {
+	llinfos << "Merov debug : switchIndicator, mSpeakerId = " << mSpeakerId << ", switch_on = " << switch_on << llendl;
 	// ensure indicator is visible in case it is not in visible chain
 	// to be called when parent became visible next time to notify parent that visibility is changed.
 	setVisible(TRUE);
diff --git a/indra/newview/llspeakingindicatormanager.cpp b/indra/newview/llspeakingindicatormanager.cpp
index 900379ae1e..316a2739b8 100644
--- a/indra/newview/llspeakingindicatormanager.cpp
+++ b/indra/newview/llspeakingindicatormanager.cpp
@@ -155,6 +155,7 @@ void SpeakingIndicatorManager::registerSpeakingIndicator(const LLUUID& speaker_i
 	BOOL is_in_same_voice = LLVoiceClient::getInstance()->isParticipant(speaker_id);
 
 	speakers_uuids.insert(speaker_id);
+	llinfos << "Merov debug : registerSpeakingIndicator call switchSpeakerIndicators, switch = " << is_in_same_voice << llendl;	
 	switchSpeakerIndicators(speakers_uuids, is_in_same_voice);
 }
 
@@ -195,6 +196,7 @@ SpeakingIndicatorManager::~SpeakingIndicatorManager()
 
 void SpeakingIndicatorManager::sOnCurrentChannelChanged(const LLUUID& /*session_id*/)
 {
+	llinfos << "Merov debug : sOnCurrentChannelChanged call switchSpeakerIndicators, FALSE" << llendl;	
 	switchSpeakerIndicators(mSwitchedIndicatorsOn, FALSE);
 	mSwitchedIndicatorsOn.clear();
 }
@@ -208,16 +210,21 @@ void SpeakingIndicatorManager::onParticipantsChanged()
 
 	LL_DEBUGS("SpeakingIndicator") << "Switching all OFF, count: " << mSwitchedIndicatorsOn.size() << LL_ENDL;
 	// switch all indicators off
+	llinfos << "Merov debug : onParticipantsChanged call switchSpeakerIndicators, FALSE" << llendl;	
 	switchSpeakerIndicators(mSwitchedIndicatorsOn, FALSE);
+	llinfos << "Merov debug : onParticipantsChanged call switchSpeakerIndicators, end FALSE switch" << llendl;	
 	mSwitchedIndicatorsOn.clear();
 
 	LL_DEBUGS("SpeakingIndicator") << "Switching all ON, count: " << speakers_uuids.size() << LL_ENDL;
 	// then switch current voice participants indicators on
+	llinfos << "Merov debug : onParticipantsChanged call switchSpeakerIndicators, TRUE" << llendl;	
 	switchSpeakerIndicators(speakers_uuids, TRUE);
+	llinfos << "Merov debug : onParticipantsChanged call switchSpeakerIndicators, end TRUE switch" << llendl;	
 }
 
 void SpeakingIndicatorManager::switchSpeakerIndicators(const speaker_ids_t& speakers_uuids, BOOL switch_on)
 {
+	llinfos << "Merov debug : switchSpeakerIndicators, switch_on = " << switch_on << llendl;
 	LLVoiceChannel* voice_channel = LLVoiceChannel::getCurrentVoiceChannel();
 	LLUUID session_id;
 	if (voice_channel)
diff --git a/indra/newview/llspeakingindicatormanager.h b/indra/newview/llspeakingindicatormanager.h
index b0a147865b..c2cf2a3702 100644
--- a/indra/newview/llspeakingindicatormanager.h
+++ b/indra/newview/llspeakingindicatormanager.h
@@ -37,7 +37,7 @@ public:
 	virtual ~LLSpeakingIndicator(){}
 	virtual void switchIndicator(bool switch_on) = 0;
 
-private:
+//private:
 	friend class SpeakingIndicatorManager;
 	// Accessors for target voice session UUID.
 	// They are intended to be used only from SpeakingIndicatorManager to ensure target session is 
-- 
cgit v1.2.3