Files
libremetaverse/libsecondlife/libsecondlife.Utilities/VoiceManagerBlocking.cs
John Hurliman d9e2b40e3e * Massive amount of work on VoiceManager and VoiceTest, we are almost logging in
* Fixed a few lingering bugs with the CAPS event queue wanting to time out
* Forced CapsRequest to always use POST
* Removed more debugging spew from HttpBase

git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@1346 52acb1d6-8a22-11de-b505-999d5b087335
2007-08-03 16:00:50 +00:00

131 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using libsecondlife;
namespace libsecondlife.Utilities
{
public partial class VoiceManager
{
/// <summary>Amount of time to wait for the voice daemon to respond.
/// The value needs to stay relatively high because some of the calls
/// require the voice daemon to make remote queries before replying</summary>
public int BlockingTimeout = 30 * 1000;
protected Dictionary<int, AutoResetEvent> Events = new Dictionary<int, AutoResetEvent>();
public List<string> CaptureDevices()
{
AutoResetEvent evt = new AutoResetEvent(false);
Events[_CommandCookie] = evt;
if (RequestCaptureDevices() == -1)
{
Events.Remove(_CommandCookie);
return new List<string>();
}
if (evt.WaitOne(BlockingTimeout, false))
return CurrentCaptureDevices();
else
return new List<string>();
}
public List<string> RenderDevices()
{
AutoResetEvent evt = new AutoResetEvent(false);
Events[_CommandCookie] = evt;
if (RequestRenderDevices() == -1)
{
Events.Remove(_CommandCookie);
return new List<string>();
}
if (evt.WaitOne(BlockingTimeout, false))
return CurrentRenderDevices();
else
return new List<string>();
}
public string CreateConnector(out int status)
{
status = 0;
AutoResetEvent evt = new AutoResetEvent(false);
Events[_CommandCookie] = evt;
if (RequestCreateConnector() == -1)
{
Events.Remove(_CommandCookie);
return String.Empty;
}
bool success = evt.WaitOne(BlockingTimeout, false);
status = statusCode;
if (success && statusCode == 0)
return connectorHandle;
else
return String.Empty;
}
public string Login(string accountName, string password, string connectorHandle, out int status)
{
status = 0;
AutoResetEvent evt = new AutoResetEvent(false);
Events[_CommandCookie] = evt;
if (RequestLogin(accountHandle, password, connectorHandle) == -1)
{
Events.Remove(_CommandCookie);
return String.Empty;
}
bool success = evt.WaitOne(BlockingTimeout, false);
status = statusCode;
if (success && statusCode == 0)
return accountHandle;
else
return String.Empty;
}
protected void RegisterCallbacks()
{
OnCaptureDevices += new DevicesCallback(VoiceManager_OnCaptureDevices);
OnRenderDevices += new DevicesCallback(VoiceManager_OnRenderDevices);
OnConnectorCreated += new ConnectorCreatedCallback(VoiceManager_OnConnectorCreated);
OnLogin += new LoginCallback(VoiceManager_OnLogin);
}
#region Callbacks
private void VoiceManager_OnCaptureDevices(int cookie, int statusCode, string statusString, string currentDevice)
{
if (Events.ContainsKey(cookie))
Events[cookie].Set();
}
private void VoiceManager_OnRenderDevices(int cookie, int statusCode, string statusString, string currentDevice)
{
if (Events.ContainsKey(cookie))
Events[cookie].Set();
}
private void VoiceManager_OnConnectorCreated(int cookie, int statusCode, string statusString, string connectorHandle)
{
if (Events.ContainsKey(cookie))
Events[cookie].Set();
}
private void VoiceManager_OnLogin(int cookie, int statusCode, string statusString, string accountHandle)
{
if (Events.ContainsKey(cookie))
Events[cookie].Set();
}
#endregion Callbacks
}
}