-
Notifications
You must be signed in to change notification settings - Fork 0
/
OscClient.cs
61 lines (49 loc) · 1.67 KB
/
OscClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Threading;
using System.Threading.Tasks;
namespace Suhock.Osc;
public sealed class OscClient : IOscClient
{
private readonly IOscConnection _connection;
private readonly IOscMessageParser _messageParser;
/// <summary>
/// Creates an OSC client instance with a default OscMessageFactory implementation, accepting the default
/// argument types specified in the OSC specification.
/// </summary>
/// <param name="connection">an OSC connection implementation</param>
public OscClient(IOscConnection connection) : this(connection, new OscMessageParser())
{
}
/// <summary>
/// Creates an OSC client instance.
/// </summary>
/// <param name="connection">an OSC connection implementation</param>
/// <param name="messageParser">a </param>
public OscClient(IOscConnection connection, IOscMessageParser messageParser)
{
_connection = connection;
_messageParser = messageParser;
}
private void VerifyState()
{
}
public OscMessage Receive()
{
VerifyState();
return _messageParser.ParseBytes(_connection.Receive(), out _);
}
public async Task<OscMessage> ReceiveAsync(CancellationToken cancellationToken)
{
VerifyState();
return _messageParser.ParseBytes(await _connection.ReceiveAsync(cancellationToken), out _);
}
public void Send(OscMessage msg)
{
VerifyState();
_connection.Send(msg.GetPacketBytes());
}
public async Task SendAsync(OscMessage msg, CancellationToken cancellationToken)
{
VerifyState();
await _connection.SendAsync(msg.GetPacketBytes(), cancellationToken);
}
}