// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Threading.Tasks; namespace osu.Framework.Platform { public class IpcChannel : IDisposable { private readonly IIpcHost host; public event Action MessageReceived; public IpcChannel(IIpcHost host) { this.host = host; this.host.MessageReceived += handleMessage; } public Task SendMessageAsync(T message) => host.SendMessageAsync(new IpcMessage { Type = typeof(T).AssemblyQualifiedName, Value = message, }); private void handleMessage(IpcMessage message) { if (message.Type != typeof(T).AssemblyQualifiedName) return; MessageReceived?.Invoke((T)message.Value); } public void Dispose() { host.MessageReceived -= handleMessage; } } }