indexing description: "[ Event queue to publish events from EM_COMPONENTs. Use EM_SHARED_COMPONENT_EVENT_QUEUE to access the singleton instance. ]" date: "$Date$" revision: "$Revision$" class EM_COMPONENT_EVENT_QUEUE create {EM_SHARED_COMPONENT_EVENT_QUEUE} make feature {NONE} -- Initialisation make is -- Initilalise default values. do create events_impl.make end feature -- Access events: DS_LINEAR [TUPLE [EM_EVENT_CHANNEL [TUPLE []], TUPLE[]]] is -- Event list do Result := events_impl ensure events_not_void: Result /= Void end feature -- Status report is_flushing: BOOLEAN -- Is `Current' flushing events? -- (If yes then added events are immediatly processed) feature -- Status setting set_flushing (a_value: BOOLEAN) is -- Set `is_flushing' to `a_value'. do is_flushing := a_value ensure is_flushing_set: is_flushing = a_value end enable_flushing is -- Enable flushing. do is_flushing := True ensure flushing_enabled: is_flushing end disable_flushing is -- Disable flushing. do is_flushing := False ensure flushing_disabled: not is_flushing end feature -- Element change add_event (an_event: EM_EVENT_CHANNEL [TUPLE[]]; an_arguments: TUPLE []) is -- Add `an_event' to events. require an_event_not_void: an_event /= Void an_arguments_not_void: an_arguments /= Void do if not an_event.is_suspended then if is_flushing then an_event.publish (an_arguments) else events_impl.force_last ([an_event, an_arguments]) end end ensure event_added: not is_flushing and then not an_event.is_suspended implies events.count = old events.count + 1 end feature -- Removal wipe_out is -- Clear all `events'. do events_impl.wipe_out end feature -- Basic operations process_events is -- Process all `events'. local cursor: DS_LIST_CURSOR [TUPLE [EM_EVENT_CHANNEL [TUPLE []], TUPLE[]]] an_event: EM_EVENT_CHANNEL [TUPLE []] an_arguments: TUPLE [] do from cursor := events_impl.new_cursor cursor.start until cursor.after loop an_event ?= cursor.item.item (1) an_arguments ?= cursor.item.item (2) cursor.remove an_event.publish (an_arguments) cursor.start end ensure events_processed: events.is_empty end feature {NONE} -- Implementation events_impl: DS_LINKED_LIST [TUPLE [EM_EVENT_CHANNEL [TUPLE []], TUPLE[]]] -- List of events invariant events_impl_not_void: events_impl /= Void end