corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * - Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using System.Collections.Generic; |
||
29 | using System.Threading; |
||
30 | using OpenMetaverse; |
||
31 | |||
32 | namespace OpenMetaverse.Utilities |
||
33 | { |
||
34 | public partial class VoiceManager |
||
35 | { |
||
36 | /// <summary>Amount of time to wait for the voice daemon to respond. |
||
37 | /// The value needs to stay relatively high because some of the calls |
||
38 | /// require the voice daemon to make remote queries before replying</summary> |
||
39 | public int BlockingTimeout = 30 * 1000; |
||
40 | |||
41 | protected Dictionary<int, AutoResetEvent> Events = new Dictionary<int, AutoResetEvent>(); |
||
42 | |||
43 | public List<string> CaptureDevices() |
||
44 | { |
||
45 | AutoResetEvent evt = new AutoResetEvent(false); |
||
46 | Events[_CommandCookie] = evt; |
||
47 | |||
48 | if (RequestCaptureDevices() == -1) |
||
49 | { |
||
50 | Events.Remove(_CommandCookie); |
||
51 | return new List<string>(); |
||
52 | } |
||
53 | |||
54 | if (evt.WaitOne(BlockingTimeout, false)) |
||
55 | return CurrentCaptureDevices(); |
||
56 | else |
||
57 | return new List<string>(); |
||
58 | } |
||
59 | |||
60 | public List<string> RenderDevices() |
||
61 | { |
||
62 | AutoResetEvent evt = new AutoResetEvent(false); |
||
63 | Events[_CommandCookie] = evt; |
||
64 | |||
65 | if (RequestRenderDevices() == -1) |
||
66 | { |
||
67 | Events.Remove(_CommandCookie); |
||
68 | return new List<string>(); |
||
69 | } |
||
70 | |||
71 | if (evt.WaitOne(BlockingTimeout, false)) |
||
72 | return CurrentRenderDevices(); |
||
73 | else |
||
74 | return new List<string>(); |
||
75 | } |
||
76 | |||
77 | public string CreateConnector(out int status) |
||
78 | { |
||
79 | status = 0; |
||
80 | |||
81 | AutoResetEvent evt = new AutoResetEvent(false); |
||
82 | Events[_CommandCookie] = evt; |
||
83 | |||
84 | if (RequestCreateConnector() == -1) |
||
85 | { |
||
86 | Events.Remove(_CommandCookie); |
||
87 | return String.Empty; |
||
88 | } |
||
89 | |||
90 | bool success = evt.WaitOne(BlockingTimeout, false); |
||
91 | status = statusCode; |
||
92 | |||
93 | if (success && statusCode == 0) |
||
94 | return connectorHandle; |
||
95 | else |
||
96 | return String.Empty; |
||
97 | } |
||
98 | |||
99 | public string Login(string accountName, string password, string connectorHandle, out int status) |
||
100 | { |
||
101 | status = 0; |
||
102 | |||
103 | AutoResetEvent evt = new AutoResetEvent(false); |
||
104 | Events[_CommandCookie] = evt; |
||
105 | |||
106 | if (RequestLogin(accountName, password, connectorHandle) == -1) |
||
107 | { |
||
108 | Events.Remove(_CommandCookie); |
||
109 | return String.Empty; |
||
110 | } |
||
111 | |||
112 | bool success = evt.WaitOne(BlockingTimeout, false); |
||
113 | status = statusCode; |
||
114 | |||
115 | if (success && statusCode == 0) |
||
116 | return accountHandle; |
||
117 | else |
||
118 | return String.Empty; |
||
119 | } |
||
120 | |||
121 | protected void RegisterCallbacks() |
||
122 | { |
||
123 | OnCaptureDevices += new DevicesCallback(VoiceManager_OnCaptureDevices); |
||
124 | OnRenderDevices += new DevicesCallback(VoiceManager_OnRenderDevices); |
||
125 | OnConnectorCreated += new ConnectorCreatedCallback(VoiceManager_OnConnectorCreated); |
||
126 | OnLogin += new LoginCallback(VoiceManager_OnLogin); |
||
127 | } |
||
128 | |||
129 | #region Callbacks |
||
130 | |||
131 | private void VoiceManager_OnCaptureDevices(int cookie, int statusCode, string statusString, string currentDevice) |
||
132 | { |
||
133 | if (Events.ContainsKey(cookie)) |
||
134 | Events[cookie].Set(); |
||
135 | } |
||
136 | |||
137 | private void VoiceManager_OnRenderDevices(int cookie, int statusCode, string statusString, string currentDevice) |
||
138 | { |
||
139 | if (Events.ContainsKey(cookie)) |
||
140 | Events[cookie].Set(); |
||
141 | } |
||
142 | |||
143 | private void VoiceManager_OnConnectorCreated(int cookie, int statusCode, string statusString, string connectorHandle) |
||
144 | { |
||
145 | if (Events.ContainsKey(cookie)) |
||
146 | Events[cookie].Set(); |
||
147 | } |
||
148 | |||
149 | private void VoiceManager_OnLogin(int cookie, int statusCode, string statusString, string accountHandle) |
||
150 | { |
||
151 | if (Events.ContainsKey(cookie)) |
||
152 | Events[cookie].Set(); |
||
153 | } |
||
154 | |||
155 | #endregion Callbacks |
||
156 | } |
||
157 | } |