using System.Threading; using AsterNET.Manager.Action; using AsterNET.Manager.Response; namespace AsterNET.Manager { /// /// A simple response handler that stores the received response in a ResponseHandlerResult for further processing. /// public class ResponseHandler : IResponseHandler { private ManagerAction action; private AutoResetEvent autoEvent; private int hash; private ManagerResponse response; /// /// Creates a new instance. /// /// the result to store the response in /// the thread to interrupt when the response has been received public ResponseHandler(ManagerAction action, AutoResetEvent autoEvent) { response = null; this.action = action; this.autoEvent = autoEvent; } public ManagerResponse Response { get { return this.response; } } public ManagerAction Action { get { return this.action; } } public int Hash { get { return hash; } set { hash = value; } } public void Free() { autoEvent = null; action = null; response = null; } public virtual void HandleResponse(ManagerResponse response) { this.response = response; if (autoEvent != null) this.autoEvent.Set(); } } }