note
	description: "A sequence of actions to be performed on call."
	legal: "See notice at end of class."
	instructions: "[
		Use features inherited from LIST to add/remove actions.
		An action is a procedure of ANY class that takes EVENT_DATA.
		When call is called the actions in the list will be executed
		in order stating at first.
		An action may call abort which will cause call to stop executing
		actions in the sequence. (Until the next call to call).
		Descendants may redefine initialize to arrange for call to
		be called by an event source.
		Use block, pause, flush and resume to change the behavior
		of call.
		eg.
		 birthday_data: TUPLE [INTEGER, STRING] -- (age, name)
		 birthday_actions: ACTION_SEQUENCE [like birthday_data]
		 create birthday_actions.make ("birthday", <<"age","name">>)
		 send_card (age: INTEGER, name, from: STRING) is ...
		 buy_gift (age: INTEGER, name, gift, from: STRING) is ...
		 birthday_actions.extend (agent send_card (?, ?, "Sam")
		 birthday_actions.extend (agent buy_gift (?, ?, "Wine", "Sam")
		 birthday_actions.call ([35, "Julia"])
		 causes call to: send_card (35, "Julia", "Sam")
		                 buy_gift (35, "Julia", "Wine", "Sam")
	]"
	status: "See notice at end of class."
	keywords: event, action
	date: "$Date: 2018-11-14 15:15:17 +0000 (Wed, 14 Nov 2018) $"
	revision: "$Revision: 102463 $"

class interface
	ACTION_SEQUENCE [EVENT_DATA -> detachable TUPLE create default_create end]

create 
	default_create,
	make


create {ACTION_SEQUENCE}
	arrayed_list_make,
	make_filled

feature -- Miscellaneous

	on_item_added_at (an_item: like item; item_index: INTEGER_32)
			-- an_item has just been added at index item_index.

	on_item_removed_at (an_item: like item; item_index: INTEGER_32)
			-- an_item has just been removed from index item_index.
	
feature -- Basic operations

	call (event_data: detachable EVENT_DATA)
			-- Call each procedure in order unless is_blocked.
			-- If is_paused delay execution until resume.
			-- Stop at current point in list on abort.
		ensure
			is_aborted_stack_unchanged: (old is_aborted_stack) ~ is_aborted_stack

	extend_kamikaze (an_item: like item)
			-- Extend an_item and remove it again after it is called.
	
feature -- Access

	name: detachable STRING_8
			-- Textual description.
		ensure
			equal_to_name_internal: Result ~ name_internal
	
feature -- Status setting

	abort
			-- Abort the current call.
			-- (The current item.call will be completed.)
		require
			call_is_underway: call_is_underway
		ensure
			is_aborted_set: is_aborted_stack.item

	block
			-- Ignore subsequent calls.
		ensure
			blocked_state: state = Blocked_state

	pause
			-- Buffer subsequent calls for later execution.
			-- If is_blocked calls will simply be ignored.
		ensure
			paused_state: state = Paused_state

	resume
			-- Used after block or pause to resume normal call
			-- execution.  Executes any buffered calls.
		ensure
			normal_state: state = Normal_state

	flush
			-- Discard any buffered calls.
		ensure
			call_buffer_empty: call_buffer.is_empty
	
feature -- Status report

	state: INTEGER_32
			-- One of Normal_state Paused_state or Blocked_state

	Normal_state: INTEGER_32 = 1

	Paused_state: INTEGER_32 = 2

	Blocked_state: INTEGER_32 = 3

	call_is_underway: BOOLEAN
			-- Is call currently being executed?
		ensure
				Result = not is_aborted_stack.is_empty
	
feature -- Removal

	prune (v: like item)
			-- Remove first occurrence of v, if any,
			-- after cursor position.
			-- Move cursor to right neighbor.
			-- (or after if no right neighbor or v does not occur)

	prune_when_called (an_action: like item)
			-- Remove an_action after the next time it is called.
		require
				has (an_action)
	
feature -- Element status

	has_kamikaze_action (an_action: like item): BOOLEAN
			-- Return True is an_action is found and will be pruned when called.
		require
				has (an_action)
	
feature -- Event handling

	not_empty_actions: ARRAYED_LIST [PROCEDURE]
			-- Actions to be performed on transition from is_empty to not is_empty.

	empty_actions: ARRAYED_LIST [PROCEDURE]
			-- Actions to be performed on transition from not is_empty to is_empty.
	
invariant
	is_aborted_stack_not_void: is_aborted_stack /= Void
	call_buffer_not_void: call_buffer /= Void
	valid_state: state = Normal_state or state = Paused_state or state = Blocked_state
	call_buffer_consistent: state = Normal_state implies call_buffer.is_empty
	not_empty_actions_not_void: not_empty_actions /= Void
	empty_actions_not_void: empty_actions /= Void

note
	library: "EiffelBase: Library of reusable components for Eiffel."
	copyright: "Copyright (c) 1984-2018, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class ACTION_SEQUENCE

Generated by ISE EiffelStudio