forked from cefsharp/CefSharp.OutOfProcess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallbackProxyBase.cs
More file actions
45 lines (39 loc) · 1.11 KB
/
CallbackProxyBase.cs
File metadata and controls
45 lines (39 loc) · 1.11 KB
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
using System;
using System.Collections.Generic;
using CefSharp.OutOfProcess.Interface;
namespace CefSharp.OutOfProcess.BrowserProcess.CallbackProxies
{
internal class CallbackProxyBase<T> : IDisposable
{
private int id = 0;
private readonly Dictionary<int, T> callbacks = new Dictionary<int, T>();
private protected readonly IOutOfProcessHostRpc host;
public CallbackProxyBase(IOutOfProcessHostRpc host)
{
this.host = host ?? throw new ArgumentNullException(nameof(host));
}
protected int CreateCallback(T callback)
{
int lid = id++;
callbacks.Add(lid, callback);
return lid;
}
protected T GetCallback(int id)
{
T cb = callbacks[id];
callbacks.Remove(id);
return cb;
}
public void Dispose()
{
foreach (var cbs in callbacks)
{
if (cbs.Value is IDisposable d)
{
d.Dispose();
}
}
callbacks.Clear();
}
}
}