2013-01-18 15:55:50 +00:00
|
|
|
using System.Threading;
|
2014-01-08 14:16:39 +00:00
|
|
|
using AsterNET.Manager.Action;
|
|
|
|
using AsterNET.Manager.Response;
|
2013-01-18 15:55:50 +00:00
|
|
|
|
2014-01-08 14:16:39 +00:00
|
|
|
namespace AsterNET.Manager
|
2013-01-18 15:55:50 +00:00
|
|
|
{
|
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;
|
2013-01-18 15:55:50 +00:00
|
|
|
|
2015-01-03 15:37:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new instance.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="result">the result to store the response in</param>
|
|
|
|
/// <param name="thread">the thread to interrupt when the response has been received</param>
|
|
|
|
public ResponseHandler(ManagerAction action, AutoResetEvent autoEvent)
|
|
|
|
{
|
|
|
|
response = null;
|
|
|
|
this.action = action;
|
|
|
|
this.autoEvent = autoEvent;
|
|
|
|
}
|
2013-01-18 15:55:50 +00:00
|
|
|
|
2015-01-03 15:37:29 +00:00
|
|
|
public ManagerResponse Response
|
|
|
|
{
|
|
|
|
get { return this.response; }
|
|
|
|
}
|
2013-01-18 15:55:50 +00:00
|
|
|
|
2015-01-03 15:37:29 +00:00
|
|
|
public ManagerAction Action
|
|
|
|
{
|
|
|
|
get { return this.action; }
|
|
|
|
}
|
2013-01-18 15:55:50 +00:00
|
|
|
|
2015-01-03 15:37:29 +00:00
|
|
|
public int Hash
|
|
|
|
{
|
|
|
|
get { return hash; }
|
|
|
|
set { hash = value; }
|
|
|
|
}
|
2013-01-18 15:55:50 +00:00
|
|
|
|
2015-01-03 15:37:29 +00:00
|
|
|
public void Free()
|
|
|
|
{
|
|
|
|
autoEvent = null;
|
|
|
|
action = null;
|
|
|
|
response = null;
|
|
|
|
}
|
2013-01-18 15:55:50 +00:00
|
|
|
|
2015-01-03 15:37:29 +00:00
|
|
|
public virtual void HandleResponse(ManagerResponse response)
|
|
|
|
{
|
|
|
|
this.response = response;
|
|
|
|
if (autoEvent != null)
|
|
|
|
this.autoEvent.Set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|