Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.utility

Class EM_EVENT_TYPE



Features

Invariants

indexing

description

Generic implementation of the publish/subscribe pattern.
Use this class to implement an event-publishing mechanism by passing
as generic parameter the type of event you publish (as a tuple list).

date

$Date: 2005/10/23 20:36:21 $

revision

$Revision: 1.10 $

class

EM_EVENT_TYPE [EVENT_DATA -> TUPLE create default_create end]

feature -- Access

once_subscriptions: DS_LINEAR [PROCEDURE [ANY, EVENT_DATA]]

-- List of once subscriptions.

ensure
result_exist: Result /= Void
subscriptions: DS_LINEAR [PROCEDURE [ANY, EVENT_DATA]]

-- List of subscriptions.

ensure
result_exist: Result /= Void

feature -- Status report

has (an_action: PROCEDURE [ANY, EVENT_DATA]): BOOLEAN

-- Is an_action subscribed?

has_once (an_action: PROCEDURE [ANY, EVENT_DATA]): BOOLEAN

-- Is an_action subscribed in the once list?

require
an_action_not_void: an_action /= Void
is_suspended: BOOLEAN

-- Is the publication of all actions from the subscription list suspended?
-- (Answer: no by default.)

feature -- Element change

subscribe (an_action: PROCEDURE [ANY, EVENT_DATA])

-- Add an_action to the subscription list.

require
an_action_not_void: an_action /= Void
an_action_not_already_subscribed: not has (an_action)
ensure
an_action_subscribed: has (an_action)
count_incremented: subscriptions.count = old subscriptions.count + 1
subscribe_once (an_action: PROCEDURE [ANY, EVENT_DATA])

-- Add an_action to the once subscription list.
-- an_action will be called next time the event occurs and will be removed afterwards.

require
an_action_not_void: an_action /= Void
an_action_not_already_subscribed: not has_once (an_action)
ensure
an_action_subscribed: has_once (an_action)
count_incremented: once_subscriptions.count = old once_subscriptions.count + 1
unsubscribe (an_action: PROCEDURE [ANY, EVENT_DATA])

-- Remove an_action from the subscription list.

require
an_action_not_void: an_action /= Void
ensure
an_action_unsubscribed: not has (an_action)
count_decremenetd: old has (an_action) implies subscriptions.count = old subscriptions.count - 1
unsubscribe_once (an_action: PROCEDURE [ANY, EVENT_DATA])

-- Remove an_action from the once subscription list.

require
an_action_not_void: an_action /= Void
ensure
an_action_unsubscribed: not has_once (an_action)
count_decremenetd: old has_once (an_action) implies once_subscriptions.count = old once_subscriptions.count - 1

feature -- Publication

publish (arguments: EVENT_DATA)

-- Publish all not suspended actions from the subscription list.

require
arguments_not_void: arguments /= Void

feature -- Status settings

restore_subscription

-- Consider again the call of all actions from the subscription list,
-- until feature suspend_subscription is called.

ensure
subscription_not_suspended: not is_suspended
suspend_subscription

-- Ignore the call of all actions from the subscription list,
-- until feature restore_subscription is called.

ensure
subscription_suspended: is_suspended

invariant

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end