-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionEventsSink.cs
70 lines (62 loc) · 2.49 KB
/
ConnectionEventsSink.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
62
63
64
65
66
67
68
69
70
using System;
using MbnApi;
namespace MBN_DotNet
{
public delegate void OnConnectCompleteHandler(IMbnConnection connection, uint requestId, int status);
public delegate void OnDisconnectCompleteHandler(IMbnConnection connection, uint requestId, int status);
class ConnectionEventsSink : IMbnConnectionEvents, IDisposable
{
private WeakReference<OnConnectCompleteHandler> m_ConnectCallback;
private WeakReference<OnDisconnectCompleteHandler> m_DisconnectCallback;
private IConnectionPoint m_ConnectionPoint;
private uint m_AdviseCookie;
public ConnectionEventsSink(
OnConnectCompleteHandler connectCallback,
OnDisconnectCompleteHandler disconnectCallback,
IConnectionPoint connectionPoint)
{
m_ConnectCallback = new WeakReference<OnConnectCompleteHandler>(connectCallback);
m_DisconnectCallback = new WeakReference<OnDisconnectCompleteHandler>(disconnectCallback);
m_ConnectionPoint = connectionPoint;
m_ConnectionPoint.Advise(this, out m_AdviseCookie);
}
~ConnectionEventsSink()
{
Dispose();
}
public void Dispose()
{
if (m_AdviseCookie != 0)
{
m_ConnectionPoint.Unadvise(m_AdviseCookie);
m_AdviseCookie = 0;
}
}
// This will be called back when connect operation is complete
public void OnConnectComplete(IMbnConnection connection, uint requestId, int status)
{
// Invoke main page thread to show UI
OnConnectCompleteHandler callback;
if (m_ConnectCallback.TryGetTarget(out callback))
{
callback.Invoke(connection, requestId, status);
}
}
// This will be called back when disconnect operation is complete
public void OnDisconnectComplete(IMbnConnection connection, uint requestId, int status)
{
// Invoke main page thread to show UI
OnDisconnectCompleteHandler callback;
if (m_DisconnectCallback.TryGetTarget(out callback))
{
callback.Invoke(connection, requestId, status);
}
}
// Not implemented for sample
public void OnConnectStateChange(IMbnConnection connection)
{
Console.WriteLine("OnConnectStateChange");
}
public void OnVoiceCallStateChange(IMbnConnection connection) { }
}
}