JD2022-TU1/main/tools/framework/JD.Interfaces/Remoting/IPlugin.cs

65 lines
No EOL
2.3 KiB
C#

using System;
using System.ComponentModel;
using JD.Remoting;
namespace JD.Interfaces.Remoting
{
/// <inheritdoc />
/// <summary>
/// A plugin is the High Level entity responsible of handling commands in order to communicate with its counterpat on engine side.
/// </summary>
public interface IPlugin : IMessageSender, IDisposable
{
string Name { get; }
/// <summary>
/// How to dispatch actions on the main thread.
/// </summary>
Action<Action> DispatchOnMainThread { get; set; }
/// <summary>
/// Action that is called when a "join" operation expires (when the engine did not answer).
/// </summary>
Action ReportQueryTimeout { get; set; }
/// <summary>
/// True if there is an active communication with the engine.
/// </summary>
bool IsConnected { get; }
/// <summary>
/// Starts the plugin, from that point, it will try to auto connect to the engine.
/// </summary>
void Start(IEndPointId endPointId = default(IEndPointId));
/// <summary>
/// Stops to listen/send commands.
/// </summary>
void Stop();
/// <summary>
/// Will be called with the blob when the engine sends the command of given <paramref name="commandName"/>.
/// </summary>
void RegisterHandler(string commandName, Action<IBlob> handler, bool dispatchOnMainThread = true);
/// <summary>
/// Queries the engine for a set of data using the specified command. Parse the blob, and call the handler with the final data.
/// </summary>
IQueryResult<TData> Query<TData>(string queryName, Converter<IBlob, TData> resultParser);
/// <summary>
/// Queries the engine for a set of data using the specified command. Parse the blob, and call the handler with the final data.
/// </summary>
IQueryResult<TData> Query<TData>(string queryName, Action<IBlob> writeCommand, string responseName, Converter<IBlob, TData> resultParser);
/// <summary>
/// Triggered when the plugin is disposed.
/// </summary>
event EventHandler Disposed;
/// <summary>
/// Triggered on disconnection and on connection.
/// </summary>
event EventHandler<IPlugin> ConnectedChanged;
}
}