/* * */ /// <summary> /// Put event in event queue if the websocket of the event handler is up, /// else store the event in a queue until a valid event handler is set /// Return true if the event is put in queue, return false in other cases /// </summary> /// <param name="objectName"> The name of the object that sent this event</param> /// <param name="eventName">The name of the event sent by the object</param> /// <param name="value"> Value of the event sent by the object </param> public void PutPeripheralEventInQueue(string objectName, string eventName, string value) { if (this.eventHandler == null) { this.eventQueue.Enqueue(new Event(objectName, eventName, value)); } else { // In case of crash of the websocket // This will relaunch the waiting and storing queue if (!this.eventHandler.socketHandler.GetWebsocketStatus()) { this.eventHandler = null; } else { this.eventHandler.PutPeripheralEventInQueue(objectName, eventName, value); } } }
/// <summary> /// Set an eventHandler to the proxy /// It will empty the queue of events in order to treat them in the given PeripheralEventHandler /// </summary> /// <param name="eventHandler"></param> public void SetEventHandler(PeripheralEventHandler eventHandler) { this.eventHandler = eventHandler; CallEventInQueue(); }
private PeripheralEventHandlerProxy() { this.eventQueue = new ConcurrentQueue <Event>(); this.eventHandler = null; }