indexing description: "[ Event subscription pattern for object types. An event processor let clients subscribe to events. If an event occurs later, all subscribed clients will be notified. ]" date: "$Date$" revision: "$Revision$" class EM_NET_EVENT_PROCESSOR create {EM_NET_BASE} make feature {NONE} -- Initialisation make is -- Create a new event processor. do create events.make (40) ensure events_created: events /= Void end feature -- Element change subscribe_by_type_id (an_event_type_id: INTEGER; a_procedure: PROCEDURE [ANY, TUPLE]) is -- Subscribe `a_procedure' to an event with `an_event_type_id'. local tmp_event_type: EM_EVENT_CHANNEL [TUPLE] do if events.has (an_event_type_id) then events.item (an_event_type_id).subscribe (a_procedure) else create tmp_event_type tmp_event_type.subscribe (a_procedure) events.force (tmp_event_type, an_event_type_id) end end subscribe_by_event (an_event: EM_NET_EVENT_OBJECT; a_procedure: PROCEDURE [ANY, TUPLE]) is -- Subscribe `a_procedure' to `an_event'. do subscribe_by_type_id (an_event.type_id, a_procedure) end unsubscribe_by_type_id (an_event_type_id: INTEGER; a_procedure: PROCEDURE [ANY, TUPLE]) is -- Unsubscribe `a_procedure' from an event with `an_event_type_id'. do if events.has (an_event_type_id) then events.item (an_event_type_id).unsubscribe (a_procedure) end end unsubscribe_by_event (an_event: EM_NET_OBJECT; a_procedure: PROCEDURE [ANY, TUPLE]) is -- Unsubscribe `a_procedure' from `an_event'. do unsubscribe_by_type_id (an_event.type_id, a_procedure) end feature -- Publishing publish (an_event: EM_NET_EVENT_OBJECT) is -- Publish `an_event' to the event queue. do if events.has (an_event.type_id) then events.item (an_event.type_id).publish ([an_event]) end end feature {NONE} -- Implementation events: DS_HASH_TABLE [EM_EVENT_CHANNEL [TUPLE], INTEGER] -- Events and their subscriptions invariant end