asternet/Asterisk.2013/Asterisk.NET/Manager/ResponseHandler.cs

75 lines
2.1 KiB
C#
Raw Normal View History

using System.Threading;
2014-01-08 14:16:39 +00:00
using AsterNET.Manager.Action;
using AsterNET.Manager.Response;
2014-01-08 14:16:39 +00:00
namespace AsterNET.Manager
{
2015-01-03 15:37:29 +00:00
/// <summary>
/// A simple response handler that stores the received response in a ResponseHandlerResult for further processing.
/// </summary>
public class ResponseHandler : IResponseHandler
{
private ManagerAction action;
private AutoResetEvent autoEvent;
private int hash;
private ManagerResponse response;
2015-01-03 15:37:29 +00:00
/// <summary>
2018-09-02 18:35:20 +00:00
/// Creates a new <see cref="ResponseHandler"/>.
2015-01-03 15:37:29 +00:00
/// </summary>
2018-09-02 18:35:20 +00:00
/// <param name="action"><see cref="ManagerAction"/></param>
/// <param name="autoEvent"><see cref="AutoResetEvent"/></param>
2015-01-03 15:37:29 +00:00
public ResponseHandler(ManagerAction action, AutoResetEvent autoEvent)
{
response = null;
this.action = action;
this.autoEvent = autoEvent;
}
2018-09-02 18:35:20 +00:00
/// <summary>
/// Gets the response.
/// </summary>
2015-01-03 15:37:29 +00:00
public ManagerResponse Response
{
get { return this.response; }
}
2018-09-02 18:35:20 +00:00
/// <summary>
/// Gets the action.
/// </summary>
2015-01-03 15:37:29 +00:00
public ManagerAction Action
{
get { return this.action; }
}
2018-09-02 18:35:20 +00:00
/// <summary>
/// Gets or sets the hash.
/// </summary>
2015-01-03 15:37:29 +00:00
public int Hash
{
get { return hash; }
set { hash = value; }
}
2018-09-02 18:35:20 +00:00
/// <summary>
/// Frees this instance.
/// </summary>
2015-01-03 15:37:29 +00:00
public void Free()
{
autoEvent = null;
action = null;
response = null;
}
2018-09-02 18:35:20 +00:00
/// <summary>
/// This method is called when a response is received.
/// </summary>
/// <param name="response">the response received</param>
2015-01-03 15:37:29 +00:00
public virtual void HandleResponse(ManagerResponse response)
{
this.response = response;
if (autoEvent != null)
this.autoEvent.Set();
}
}
}