diff --git a/src/Draco.JsonRpc/IJsonRpcConnection.cs b/src/Draco.JsonRpc/IJsonRpcConnection.cs new file mode 100644 index 0000000000..49a804ac9d --- /dev/null +++ b/src/Draco.JsonRpc/IJsonRpcConnection.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Draco.JsonRpc; + +/// +/// Represents a JSON RPC connection. +/// +public interface IJsonRpcConnection +{ + /// + /// Registers an RPC method handler. + /// + /// The handler to register. + public void AddHandler(IJsonRpcMethodHandler handler); + + /// + /// Starts the connection to listen for messages. + /// + /// The task that completes when the listening stops. + public Task ListenAsync(); + + /// + /// Stops the connection. + /// + public void Shutdown(); +} diff --git a/src/Draco.JsonRpc/JsonRpcConnection.cs b/src/Draco.JsonRpc/JsonRpcConnection.cs index cd546f3e54..8b9a93f10a 100644 --- a/src/Draco.JsonRpc/JsonRpcConnection.cs +++ b/src/Draco.JsonRpc/JsonRpcConnection.cs @@ -20,7 +20,7 @@ namespace Draco.JsonRpc; /// /// The message type. /// The error message type. -public abstract class JsonRpcConnection +public abstract class JsonRpcConnection : IJsonRpcConnection where TMessage : IJsonRpcMessage { private interface IOutgoingRequest @@ -87,10 +87,8 @@ private enum ConsumerState SingleWriter = false, }); - // TODO: Doc public void AddHandler(IJsonRpcMethodHandler handler) => this.methodHandlers.Add(handler.Method, handler); - // TODO: Doc public Task ListenAsync() => Task.WhenAll(this.ReaderLoop(), this.WriterLoop()); private Task WriterLoop() => Task.Run(async () =>