using System; using System.Collections.Generic; using System.Threading; using libsecondlife; namespace libsecondlife.Utilities { public partial class VoiceManager { /// 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 public int BlockingTimeout = 30 * 1000; protected Dictionary Events = new Dictionary(); public List CaptureDevices() { AutoResetEvent evt = new AutoResetEvent(false); Events[_CommandCookie] = evt; if (RequestCaptureDevices() == -1) { Events.Remove(_CommandCookie); return new List(); } if (evt.WaitOne(BlockingTimeout, false)) return CurrentCaptureDevices(); else return new List(); } public List RenderDevices() { AutoResetEvent evt = new AutoResetEvent(false); Events[_CommandCookie] = evt; if (RequestRenderDevices() == -1) { Events.Remove(_CommandCookie); return new List(); } if (evt.WaitOne(BlockingTimeout, false)) return CurrentRenderDevices(); else return new List(); } 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 } }