/// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="events">the ResponseEvents to store the events in</param>
 /// <param name="actionCompleteEventClass">the type of event that indicates that all events have been received</param>
 /// <param name="thread">the thread to interrupt when the actionCompleteEventClass has been received</param>
 public ResponseEventHandler(ManagerConnection connection, ManagerActionEvent action, AutoResetEvent autoEvent)
 {
     this.connection = connection;
     this.events = new ResponseEvents();
     this.action = action;
     this.autoEvent = autoEvent;
 }
 public void Free()
 {
     connection = null;
     autoEvent = null;
     action = null;
     events.Events.Clear();
     events.Response = null;
     events = null;
 }
Esempio n. 3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="action"></param>
		/// <param name="timeout">wait timeout in milliseconds</param>
		/// <returns></returns>
		public ResponseEvents SendEventGeneratingAction(ManagerActionEvent action, int timeout)
		{
			if (action == null)
				throw new ArgumentException("Unable to send action: action is null.");
			else if (action.ActionCompleteEventClass() == null)
				throw new ArgumentException("Unable to send action: ActionCompleteEventClass is null.");
			else if (!typeof(ResponseEvent).IsAssignableFrom(action.ActionCompleteEventClass()))
				throw new ArgumentException("Unable to send action: ActionCompleteEventClass is not a ResponseEvent.");

			if (mrSocket == null)
				throw new SystemException("Unable to send " + action.Action + " action: not connected.");

			AutoResetEvent autoEvent = new AutoResetEvent(false);
			ResponseEventHandler handler = new ResponseEventHandler(this, action, autoEvent);

			string internalActionId = createInternalActionId();
			handler.Hash = internalActionId.GetHashCode();
			AddResponseHandler(handler);
			AddResponseEventHandler(handler);

			SendToAsterisk(action, internalActionId);

			bool result = autoEvent.WaitOne(timeout <= 0 ? -1 : timeout, true);

			RemoveResponseHandler(handler);
			RemoveResponseEventHandler(handler);

			if (result)
				return handler.ResponseEvents;

			throw new EventTimeoutException("Timeout waiting for response or response events to " + action.Action, handler.ResponseEvents);
		}
Esempio n. 4
0
		public ResponseEvents SendEventGeneratingAction(ManagerActionEvent action)
		{
			return SendEventGeneratingAction(action, defaultEventTimeout);
		}