SlateInstantiationImpl.mesa
Copyright Ó 1992, 1993 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, November 2, 1990 1:04:32 pm PST
Christian Jacobi, July 3, 1993 9:59 am PDT
Theimer, December 17, 1992 1:29 pm PST
DIRECTORY
FanoutStream,
PropList,
SF,
SharedCell,
SlatePrivateTypes,
Slate;
SlateInstantiationImpl: CEDAR MONITOR
IMPORTS FanoutStream, PropList, SharedCell, Slate
EXPORTS Slate ~
BEGIN OPEN Slate;
SessionPrivateRec: PUBLIC TYPE = SlatePrivateTypes.SessionPrivateRec;
InstancePrivateRec: PUBLIC TYPE = SlatePrivateTypes.InstancePrivateRec;
NewSession: PUBLIC PROC [] RETURNS [session: Session] = {
session ¬ NEW[SessionRec ¬ [
activePage: NIL,
debugLog: FanoutStream.Create[forwardClose: FALSE],
properties: PropList.NewPropList[],
nameCell: SharedCell.Create[],
private: NEW[SessionPrivateRec ¬ [
instanceList: PropList.NewPropList[],
pageList: NIL
]]
]];
CallGlobalEvent[instance: NIL, session: session, event: $NewSession];
};
NewInstance: PUBLIC PROC [session: Session] RETURNS [instance: Instance] = {
instance ¬ NEW[InstanceRec ¬ [
session: session,
log: FanoutStream.Create[forwardClose: TRUE],
properties: PropList.NewPropList[],
private: NEW[InstancePrivateRec ¬ []]
]];
IF session#NIL THEN {
sessionPrivate: REF SessionPrivateRec ¬ session.private;
PropList.TrustedAddNewProp[sessionPrivate.instanceList, instance, instance];
};
CallGlobalEvent[instance: instance, session: session, event: $NewInstance];
};
DestroyInstance: PUBLIC PROC [instance: Instance] = {
session: Session ¬ instance.session;
IF session#NIL THEN {
sessionPrivate: REF SessionPrivateRec ¬ session.private;
instanceList: PropList.List ~ sessionPrivate.instanceList;
didit: BOOL ¬ FALSE;
Monitored: ENTRY PROC [] = INLINE {
didit ¬ instance.session#NIL;
instance.session ¬ NIL;
[] ¬ PropList.RemProp[instanceList, instance];
};
IF instanceList=NIL THEN ERROR;
Monitored[];
IF didit THEN
CallGlobalEvent[instance: instance, session: session, event: $InstanceDestroyed];
};
};
CountInstances: PUBLIC PROC [session: Session] RETURNS [n: INT ¬ 0] = {
EachProp: PropList.EachPropProc = {n ¬ n+1};
sessionPrivate: REF SessionPrivateRec ¬ session.private;
[] ¬ PropList.Enumerate[sessionPrivate.instanceList, EachProp];
};
EnumerateInstances: PUBLIC PROC [session: Session, eachInstance: InstanceProc, clientData: REF ¬ NIL] RETURNS [quit: BOOL ¬ FALSE] = {
EachProp: PropList.EachPropProc = {
quit ¬ eachInstance[instance: NARROW[key], clientData: clientData].quit
};
sessionPrivate: REF SessionPrivateRec ¬ session.private;
quit ¬ PropList.Enumerate[sessionPrivate.instanceList, EachProp, clientData].quit
};
CallSessionForAllInstancesOfSession: PUBLIC PROC [session: Session ¬ NIL, event: REF, callData: REF ¬ NIL] = {
EachInstance: InstanceProc = {
CallSessionEvent[instance, session, event, callData]
};
[] ¬ EnumerateInstances[session, EachInstance, callData]
};
CallGlobalForAllInstancesOfSession: PUBLIC PROC [session: Session ¬ NIL, event: REF, callData: REF ¬ NIL] = {
EachInstance: InstanceProc = {
CallGlobalEvent[instance, session, event, callData]
};
[] ¬ EnumerateInstances[session, EachInstance, callData]
};
END.