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

em.network.multiplayer

Class EM_NET_GROUP


Direct ancestors

EM_NET_OBJECT_TYPES, EM_NET_EVENT_PROCESSOR, EM_TIME_SINGLETON, EM_DELAYED_PROCEDURES

Creation

Features

Invariants

indexing

description

A group of connections and objects.

Groups are a central concept in the multiplayer framework.
Every group is a set of connections and objects.

A connection may belong to as many groups as it want, but is always member of an
additional personal_group, that only holds one connection and no objects.

Objects on the other hand, can only belong to one single group. Changes in the
objects state are reflected to all other peers (= connections in the group) in the same group.

It is also possible to publish events to all connections of a group using the
net_event_container_object.

A group also manages timeouts in network activity for personal groups.
You may for example use low timeout value for a game group, but a higher for a
chat group.

date

$Date: 2005/10/25 20:12:11 $

revision

$Revision: 1.36 $

class

EM_NET_GROUP

inherit

EM_NET_EVENT_PROCESSOR

create {EM_NET_BASE}

make (a_name: STRING; a_base: EM_NET_BASE[EM_NET_OBJECT_TYPES])

-- Initialize a new socket group.
-- a_name is the unique group name.
-- net_base is an instance of the network base class that manages the group.

require
a_name_not_void: a_name /= Void
a_net_base_not_void: a_base /= Void
ensure
name_set: name = a_name
net_event_container_object_created: net_event_container_object /= Void
connection_list_created: connections /= Void
object_list_createdt: objects /= Void

feature {EM_NET_EVENT_OBJECT, EM_NET_EVENT_CONTAINER_OBJECT, EM_NET_GROUP} -- Access

base: EM_NET_BASE[EM_NET_OBJECT_TYPES]

-- Network base class, that manages the group

feature -- Element change

add_connection (a_connection: EM_NET_CONNECTION)

-- Add a_connection to the group.

require
a_connection_not_void: a_connection /= Void
not_has_a_connection: not has_connection(a_connection)
ensure
connection_added: has_connection (a_connection)
add_object (an_object: EM_NET_OBJECT)

-- Add an_object to the group.

require
an_object_not_void: an_object /= Void
not_has_an_object: not has_object(an_object)
ensure
object_added_to_base: base.has_object(an_object)
object_added: has_object (an_object)
remove_connection (a_connection: EM_NET_CONNECTION)

-- Remove a_connection from the group.

require
a_connection_not_void: a_connection /= Void
has_connection: has_connection(a_connection)
ensure
connection_removed: not has_connection (a_connection)
remove_object (an_object: EM_NET_OBJECT)

-- Remove an_object from the group.

require
an_object_not_void: an_object /= Void
has_an_object: has_object (an_object)
ensure
object_deleted: not has_object (an_object)
subscribe_by_event (an_event: EM_NET_EVENT_OBJECT; a_procedure: PROCEDURE [ANY, TUPLE])

-- Subscribe a_procedure to an_event.

-- (From EM_NET_EVENT_PROCESSOR)

subscribe_by_type_id (an_event_type_id: INTEGER; a_procedure: PROCEDURE [ANY, TUPLE])

-- Subscribe a_procedure to an event with an_event_type_id.

-- (From EM_NET_EVENT_PROCESSOR)

unsubscribe_by_event (an_event: EM_NET_OBJECT; a_procedure: PROCEDURE [ANY, TUPLE])

-- Unsubscribe a_procedure from an_event.

-- (From EM_NET_EVENT_PROCESSOR)

unsubscribe_by_type_id (an_event_type_id: INTEGER; a_procedure: PROCEDURE [ANY, TUPLE])

-- Unsubscribe a_procedure from an event with an_event_type_id.

-- (From EM_NET_EVENT_PROCESSOR)

feature -- Operations

send_ack (an_id: INTEGER)

-- Send an acknowledgement for an_id to all clients in the group.

set_max_inactivity_time (a_time_in_ms: INTEGER)

-- Set max_inactivity_time to a_time_in_ms.

require
a_time_in_ms_positive: a_time_in_ms > 0
ensure
max_inactivity_time_set: max_inactivity_time = a_time_in_ms

feature -- Publishing

publish (an_event: EM_NET_EVENT_OBJECT)

-- Publish an_event to the event queue.

-- (From EM_NET_EVENT_PROCESSOR)

feature -- Information

name: STRING

-- Name of the group

feature -- Status information

has_connection (a_connection: EM_NET_CONNECTION): BOOLEAN

-- Does a_connection exist in the group?

require
a_connection_not_void: a_connection /= Void
has_object (an_object: EM_NET_OBJECT): BOOLEAN

-- Does an_object exist in the group?

require
an_object_not_void: an_object /= Void

feature -- Attributes

max_inactivity_time: INTEGER

-- Maximum inactivity time
-- This is not directly involved into the framework.
-- But can be used to implement a more complex timeout mechanism

timeout_event: EM_EVENT_TYPE[TUPLE[EM_NET_CONNECTION]]

-- Timeout event
-- This is not directly involved into the framework.
-- But can be used to implement a more complex timeout mechanism

feature {EM_NET_BASE,EM_NET_SERVER_DISCOVERY_RESPONSE,EM_NET_2PC_EVENT_OBJECT,EM_NET_EVENT_CONTAINER_OBJECT} -- Implementation

acknowledged_event: DS_HASH_TABLE[INTEGER,INTEGER]

-- Hashtable of acknowledged events.
-- The key is event id.
-- The value is the time of the ack. This is used to cleanup the list prediodically.

connections: DS_LINKED_LIST[EM_NET_CONNECTION]

-- Linked list of sockets of the current group

objects: DS_LINKED_LIST[EM_NET_OBJECT]

-- Linked list of objects of the current group

invariant

net_event_container_object_exists: net_event_container_object /= Void
net_event_container_object_linked: objects.has (net_event_container_object)
base_set: base /= Void
group_correct_linked: base.group (name) = Current

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

end