Gorilla.Arena.Session Unit Reference
Overview
The Gorilla.Arena.Session unit provides TGorillaArenaSession, a component
that turns a group of devices into a session: a role, a chosen transport, a
member list and one message channel. It descends from TGorillaArenaManager
and adds what an application needs on top of raw tethering, including the
workarounds without which two devices on an ordinary network do not find each
other.
On Linux the class descends from TGorillaArenaCustomManager instead — App
Tethering has no Linux implementation there — and every session runs over the
Arena's own transport, atDirect (Gorilla.Arena.Net). Users, items and
entities work the same on every platform.
Class Hierarchy
TComponent
└── TGorillaArenaCustomManager (Gorilla.Arena.Base - users, items, events)
├── TGorillaArenaManager (App Tethering, not on Linux)
│ └── TGorillaArenaSession
│ └── TGorillaArenaMatch
└── TGorillaArenaSession (Linux)
└── TGorillaArenaMatch
Conditional Compilation
| Symbol |
Meaning |
NOTETHER |
Defined by the unit itself when LINUX is defined. The tethered half is compiled out; sessions run over atDirect |
Enumerations
TGorillaArenaSessionRole
| Value |
Description |
asrOffline |
Not in a session |
asrHost |
Opened the session; keeps the state and decides |
asrClient |
Joined somebody else's session |
TGorillaArenaTransport
| Value |
Description |
atNetwork |
App Tethering, UDP broadcast over the local network |
atBluetooth |
App Tethering, RFCOMM to a device already paired at OS level |
atDirect |
The Arena's own transport: UDP discovery, TCP to the host. All platforms, the only one on Linux (default) |
Exactly one at a time — two allowed tethering adapters deadlock
TTetheringAppProfile.Connect. Tethering and atDirect do not see each other.
Event Types
| Type |
Signature |
TGorillaArenaNoticeEvent |
procedure(const ASender : TObject; const AText : String) of object |
TGorillaArenaMessageEvent |
procedure(const ASender : TObject; AMessage : TGorillaArenaMessage; var AHandled : Boolean) of object |
TGorillaArenaSession
Published Properties
| Property |
Type |
Default |
Description |
Transport |
TGorillaArenaTransport |
atDirect |
Which transport the next session uses |
MessageResource |
String |
ArenaMessage |
Name of the tethering resource all messages travel through |
AppVersion |
Integer |
1 |
Version of the application's payloads; a mismatch is refused |
EnvPrefix |
String |
ARENA |
Prefix of the environment variables read |
LogTag |
String |
Arena |
Prefix of platform log lines |
SearchInterval |
Integer |
4000 |
Milliseconds between two searches |
SearchWindow |
Integer |
3000 |
How long one search listens |
SearchMaxTries |
Integer |
15 |
Searches before giving up |
DirectPort |
Integer |
47810 |
atDirect: TCP port of the host; the next nine are tried when taken |
DiscoveryPort |
Integer |
47811 |
atDirect: UDP discovery port |
Id, DisplayName, Target, AllowedAdapters, BindToAddress |
String |
|
Inherited from TGorillaArenaManager; on Linux published by the session itself under the same names |
OnStatusChanged, OnUserEvent, OnItemEvent, OnMessage, OnError |
|
|
Inherited from TGorillaArenaCustomManager |
OnNotice |
TGorillaArenaNoticeEvent |
|
Something worth telling the user |
OnMembersChanged |
TNotifyEvent |
|
Somebody arrived or left |
OnAppMessage |
TGorillaArenaMessageEvent |
|
A message the framework does not know |
Messages of Its Own (atDirect)
| Constant |
Value |
Payload |
ARENA_MSG_ENTITY |
arena.entity |
kind (user/item), entity (the entity's JSON). Accepted only from the owner named in SourceProfile |
ARENA_MSG_ENTITY_GONE |
arena.entity.gone |
guid of an item its owner removed |
Both are handled in DispatchMessage; they never reach OnAppMessage.
Everything TGorillaArenaManager publishes — Id, DisplayName, Target,
AllowedAdapters, BindToAddress, OnStatusChanged, OnUserEvent,
OnMessage, OnError — remains available and unused by this class.
Public Properties
| Property |
Type |
Description |
Role |
TGorillaArenaSessionRole |
Where this device stands |
IsHost |
Boolean |
Role = asrHost |
IsOffline |
Boolean |
Role = asrOffline |
MemberCount |
Integer |
How many members are known |
Public Methods
| Method |
Description |
OpenSession(const ADisplayName : String) |
Opens a session and waits for others. On Android returns before the session is up — the Bluetooth permission is asked first |
JoinSession(const ADisplayName : String; const ATarget : String = '') |
Looks for a session and joins it. ATarget names a host directly |
CloseSession() |
Leaves the session. virtual |
SendMessage(AMsg : TGorillaArenaMessage) |
Sends to everybody. Takes ownership of AMsg |
NewMessage(const AType : String) : TGorillaArenaMessage |
Builds a message carrying this session's versions and sender |
Notice(const AText : String) |
Logs the text and raises OnNotice |
MyId() : String |
Our own member id; empty until opened or joined |
LocalAddress() : String |
The address others must be pointed at when discovery fails |
Members() : TGorillaArenaMembers |
Everybody known, ourselves included |
MemberName(const AId : String) : String |
The name behind an id, or '' |
LocalAddresses() : TArray<String> |
The IPv4 addresses of this machine, for choosing a network card |
ListenPort() : Integer |
atDirect host: the TCP port actually listened on; 0 otherwise |
UpdateUsers() |
atDirect: shares our entities again and reports every user with Update. Tethering: as the manager |
CleanupUsers() |
atDirect: drops the entities of everybody no longer in the session. Tethering: as the manager |
AddItem(const AItem) / RemoveItem(const AItem) |
Inherited from TGorillaArenaCustomManager: share one of our items, or take it back |
Protected Methods (Extension Points)
| Method |
Description |
DoSessionStarting() |
A role was taken, before the network comes up |
DoSessionReady() |
The session is up |
DoMemberArrived(const AMember : TGorillaArenaMember) |
Somebody joined. The base raises a notice |
DoMemberGone(const AMember : TGorillaArenaMember) |
Somebody left |
DispatchMessage(AMsg) : Boolean |
Act on a message; False offers it to OnAppMessage |
Transmit(const AText : String) |
The only place the network is touched — a test seam |
RebuildMembers() |
Rebuild the member list from the arena user list — a test seam |
ApplyBindOverride() |
Applies <PREFIX>_BIND |
AdapterList() : String |
The adapters to allow, from Transport or <PREFIX>_ADAPTERS |
PickBindAddress(const ASubnets) : String |
Overridden to return '' — the RTL then binds every card |
ConnectRemoteProfiles() |
Overridden to accept a refused connection only when ConnectedProfiles confirms one, and to leave it to the search repeat otherwise |
DiscoverPairedProfiles() |
Asks a paired manager for its profiles again while none of ours is known from it — the passively paired side gets no discovery of its own |
EnvValue(const ASuffix : String) : String |
Reads <EnvPrefix>_<ASuffix> |
LogPrefix() : String |
LogTag, or Arena while the manager's constructor is still running |
UsesDirect() : Boolean |
Whether a session opened now goes over atDirect — always on Linux |
ApplyRoster(const APeers) |
atDirect: makes the member list the host's roster, raises DoMemberArrived/DoMemberGone, removes the entities of those who left and shares ours with those who came |
DirectCreateMyself() |
atDirect: our own user, owned by this session's member id |
SendEntity(const AEntity) / ResendOwnEntities() |
atDirect: shares one or all of our entities |
HandleEntity(AMsg) / HandleEntityGone(AMsg) |
atDirect: applies what an owner shared or removed |
EntityOwnerId, EntityChanged, EntitySubmit, EntityPropertySubmit |
IGorillaArenaEntityHost: on atDirect an owned, listed entity is sent in full; on tethering the manager's behaviour |
When overriding DoStatusChanged or DoUserEvent, return immediately if
FDestroying is set — the manager reports its own teardown through them.
Protected Fields
| Field |
Type |
Description |
FRole |
TGorillaArenaSessionRole |
Current role |
FMembers |
TList<TGorillaArenaMember> |
The member list |
FMyId |
String |
Our own id |
FSeqOut |
Int64 |
Outgoing sequence counter |
FGate |
TGorillaArenaSequenceGate |
Drops late and duplicated messages |
Environment Variables
All prefixed with EnvPrefix.
| Variable |
Description |
<PREFIX>_LOG |
File to append the trace to |
<PREFIX>_BIND |
Network card to bind to; overrides everything |
<PREFIX>_ADAPTERS |
Adapters to allow. Separate with ; or \|, never with commas |
Lifetime Notes
Destroy calls inherited before freeing its lists: tearing the manager
down runs Leave(), which comes back through DoStatusChanged and
DoUserEvent, and those read what would otherwise already be gone.
See Also