home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Core / ODSessn.cpp < prev    next >
Encoding:
Text File  |  1997-02-13  |  20.0 KB  |  614 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ODSessn.cpp
  3.  
  4.     Contains:    ODSession class implementation
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <8>      10/14/96    RA        1386083: Make sure that session knows
  13.                                     whether it's inited or not.
  14.          <7>    03.10.1996    NP        Reverting last change. SOM apparently
  15.                                     didn't like the IDL change.
  16.          <6>    02.10.1996    NP        1386083: Make sure that session knows
  17.                                     whether it's inited or not.
  18.          <5>     9/23/96    EL        1383104: InitSession need to initialize
  19.                                     semantic interface in correct order
  20.          <4>    19.07.1996    NP        1370120: don't purge objects that don't
  21.                                     exist!
  22.          <3>     6/21/96    RA        T10025: Set Binding before InitBinding
  23.                                     because Binding needs to call session for
  24.                                     ref to itself
  25.         <50>     10/8/95    TJ        Fixes Recomended by Refball
  26.         <49>     4/10/95    NP        1287722: Change signature of
  27.                                     ODSession::GetUserName.
  28.         <48>    25/09/95    NP        1280561: Check results of operator new.
  29.         <47>     8/29/95    DM        1276569: FB3:ODSession::GetUserName can
  30.                                     return bogus string
  31.         <46>     8/29/95    RR        # 1276401 Register Mouse Focus
  32.         <45>     8/16/95    NP        1242634: Remove #define PLATFORMFILEVIRTUAL
  33.                                     when PlatformFile has no virt. methods.
  34.         <44>      8/3/95    RR        #1257260: Collapse B classes. Remove
  35.                                     somInit methods. Don't call IsInitialized
  36.                                     or SubclassResponsibility
  37.         <43>     7/27/95    CC        1153788: Use std C library routines rand
  38.                                     and srand for generating unique update ids.
  39.         <42>     5/30/95    CG        #1252280 BB: PStrToIntl should not  be used
  40.                                     by OpenDoc.
  41.         <41>     5/26/95    DM        1251403: Multithreading naming support.
  42.         <40>     5/24/95    CG        #1239535 BB: Added temporary work around.
  43.         <39>     5/11/95    NP        1242421: Fix exception handling
  44.         <38>     5/11/95    VL        1238421: Implemented Purge.
  45.         <37>     4/26/95    CG        1211082 BB: 5$ Bugs need to be evaluated
  46.                                     and removed from Core
  47.         <36>      4/5/95    CG        #1216169 BB, #1221135: When Editors folder
  48.                                     or OpenDoc Libraries folder is missing,
  49.                                     OpenDoc quits and displays error.
  50.         <35>     3/27/95    CC        1231902: Pass ODSession to
  51.                                     InitTranslation().
  52.         <34>      3/7/95    RR        #1220929 Caching of foci in ODWindowState
  53.                                     necessitated reordering of Inits
  54.         <33>     2/16/95    CG        #1207793: defined resource id constant.
  55.         <32>     2/10/95    CG        #1177475: Need to initialize translation
  56.                                     object before nameSpaceManager.
  57.         <31>    12/13/94    SS        1205663 - changed ODQD to gODQD
  58.         <30>     12/5/94    jpa        Added global ODQD & initialization code
  59.                                     [1203926]
  60.         <29>    11/30/94    RR        Include time.h
  61.         <28>    11/15/94    NP        1200193-The Shell should instantiate its
  62.                                     Semantic Interface.
  63.         <27>    11/15/94    NP        1200132-Removed instantiation of Shell
  64.                                     Semantic Interface from here.
  65.         <26>     10/7/94    CC        1191489 - Moved UniqueUpdateID() in from
  66.                                     base class.
  67.         <25>      9/9/94    NP        1184043: Change to InitSemanticInterface.
  68.         <24>     8/22/94    TÇ        #1182448 System Process quits when no
  69.                                     OpenDoc documents are running
  70.         <23>     8/19/94    NP        1181622: Ownership fix.
  71.         <22>     8/13/94    TÇ        #1180814 Added support for ODPartWrapper
  72.                                     API and removed a chr(16) on line #288
  73.                                     which was randomly introduced by projector?
  74.         <21>     8/12/94    NP        1180762-added setters for getters. moved
  75.                                     stuff to B file. Removed GetSemtInterface.
  76.         <20>      8/3/94    CC        Register the clipboard focus.
  77.         <19>      8/3/94    VL        1153123: Storage to ODStor.
  78.         <18>      8/2/94    TÇ        bug# for #17 right below was #1178167
  79.         <17>      8/2/94    TÇ        added TOKENTABLECORRUPTED to work around
  80.                                     heap corruption occuring when fTokenTable
  81.                                     was deleted.  Changed deletes to
  82.                                     ODDeleteObject.
  83.         <16>     7/29/94    CG        Removed Object registration APIs from
  84.                                     session.
  85.         <15>     7/21/94    TÇ        explicitly create & delete a PlatformFile
  86.                                     to make sure it is not deadstripped, added
  87.                                     #define PLATFORMFILEVIRTUAL
  88.         <14>     7/11/94    TÇ        added GetInfo, SetInfo, set _fInfo in
  89.                                     InitSession
  90.         <13>     7/11/94    NP        Fixed compile problem in GetUserName.
  91.         <12>      7/8/94    NP        Fix GetUserName.
  92.         <11>      7/7/94    RR        Initialize dispatcher AFTER token table
  93.         <10>      7/1/94    NP        Change to InitSIHelper.
  94.          <9>      7/1/94    CG        Uncommented code in GetUserName.
  95.          <8>     6/30/94    CG        Uncommented messaging-related fields and
  96.                                     methods, moved StdDisp initialization to
  97.                                     Dispatch.cpp.
  98.          <7>     6/28/94    VL        Use DragDrp.
  99.          <6>     6/28/94    VL        Fixed parameters to InitStorageSystem.
  100.          <5>     6/24/94    CG        Initialization clean up.
  101.          <4>     6/23/94    CG        Somverted original implementation.
  102.          <3>     6/19/94    MB        Implement GetDefaultHeap
  103.          <2>     6/18/94    MB        Add memory component
  104.          <1>     6/14/94    CG        first checked in
  105.         ------------------------------------------------------------
  106.          <7>      6/6/94    jpa        Eliminate spurious ASLM header include.
  107.                                     [1153437]
  108.          <6>      6/1/94    CG        Moved fPreferences to nameSpaceManager and
  109.                                     changed session to use public binding
  110.                                     object.
  111.          <5>     5/27/94    CG        #1165186: Abstracted prefs out of binding.
  112.          <4>      5/9/94    MB        #1162181: Changes necessary to install MMM.
  113.          <3>      4/1/94    TÇ        #1154941: Get OpenDoc source to actually
  114.                                     compile for PowerPC
  115.          <2>     3/31/94    eeh        bug #1153999: PStrToIntl interface changed.
  116.          <1>     3/28/94    CG        first checked in
  117.          <6>     3/26/94    NP        1153512. Object Registration API needed.
  118.          <5>     3/26/94    NP        1153504. InitSemanticInterface.
  119.          <4>     3/25/94    CC        Change name of included file to
  120.                                     <LinkMgr.xh>. (1153348)
  121.          <3>     3/15/94    MB        Changes to support SCpp/ASLM builds,
  122.                                     #1150864.
  123.          <2>     2/28/94    CG        (no bug #) Changed call to GetSystemPool()
  124.                                     to XMPGetSystemHeap().
  125.         <39>      2/9/94    TÇ        Throw to THROW
  126.         <38>      2/7/94    TÇ        more PPC header fixes
  127.         <37>      2/4/94    TÇ        fixes to compile with PPC Universal headers
  128.         <36>      2/3/94    CG        System Session gets created in InitSession.
  129.         <35>      2/1/94    RR        Call InitSessionForPlatform in InitSession
  130.         <34>     1/28/94    CC        Added UniqueUpdateID().
  131.         <33>     1/15/94    RR        WinState.h->WinStat.h,
  132.                                     Dispatch.h->Disptch.h
  133.         <32>     1/14/94    NP        Init changes.
  134.         <31>     1/14/94    CG        Added include for new NmSpcMgr.h.
  135.         <30>     1/12/94    CG        Added fBinding field and calls to new
  136.                                     ODBinding and InitBinding.
  137.         <29>     1/12/94    VL        Init changes.
  138.         <28>    12/20/93    RR        New constructor/init interface
  139.         <27>    12/15/93    TÇ        more InitObject changes, rename
  140.                                     Initialize() method call for ClipBoard and
  141.                                     NameSpaceManager
  142.         <26>     12/8/93    CC        Create and Initialize Link Manager object
  143.         <25>     12/3/93    TÇ        Stop including ODError.h, it is included
  144.                                     as ErrorDef.h inside Except.h
  145.         <24>     12/2/93    CC        Call InitClipboard().
  146.         <23>    11/16/93    RR        Register stddispatchmodule for
  147.                                     kHighLevelEvent
  148.         <22>    11/15/93    NP        Changed XMPSymbols to ODNameSpaceManager.
  149.         <21>    10/28/93    NP        GetType returns a boolean instead of
  150.                                     throwing an exception.
  151.         <20>    10/22/93    NP        Added session parameter to ODNameResolver
  152.                                     constructor.
  153.         <19>    10/20/93    CC        Added session parameter to ODClipboard
  154.                                     constructor
  155.         <18>     9/20/93    NP        Changed order of ODMessageInterface and
  156.                                     ODNameResolver initialization.
  157.         <17>     8/11/93    RR        Added code to install standard dispatch
  158.                                     module (moved from dispatcher)
  159.         <16>     7/28/93    NP        Added GetSession function.
  160.         <15>     7/21/93    TÇ        change destructor to delete fTokenTable
  161.                                     before deleting fNameSpaceManager (~TokenTable
  162.                                     seemed to need fNameSpaceManager)
  163.         <14>     7/12/93    CG        Added fShellSemtInterface and
  164.                                     AcquireShellSemtInterface() to Session class.
  165.         <13>     6/23/93    RCR        Initialize TokenTable before arbitrator.
  166.         <12>     6/22/93    NP        Added Tokenize methods.
  167.         <11>     5/18/93    NP        Changed call to ODMessageInterface
  168.                                     constructor.
  169.         <10>     4/28/93    NP        File name changes.
  170.          <9>     4/27/93    NP        Uncommented last comments.
  171.          <8>     4/27/93    NP        Commented out the construction of some
  172.                                     objects. Fixed OpenODSession.
  173.          <7>     4/23/93    NP        Removed warning from Purge.
  174.          <6>     4/23/93    NP        Fixed GetStorageSystem.
  175.          <5>     4/23/93    NP        Fixed Purge.
  176.          <4>     4/23/93    NP        Fixed call to ODSemanticInterface
  177.                                     constructor.
  178.          <3>     4/23/93    NP        Fixed Initialize to call Initialize members
  179.                                     for objects it creates. Uncommented
  180.                                     constructor and zeroed out fields in it.
  181.          <2>     4/22/93    RCR        Add Session:: to Initialize. Remove ODMethod
  182.          <1>     4/21/93    NP        first checked in
  183.  
  184.     To Do: 1276569: when name is not found return empty string from GetUserName()
  185. */
  186.  
  187. #ifndef _PLFMDEF_
  188. #include "PlfmDef.h"
  189. #endif
  190.  
  191. #ifndef SOM_ODStorageSystem_xh
  192. #include <ODStor.xh>
  193. #endif
  194.  
  195. #ifndef SOM_ODWindowState_xh
  196. #include <WinStat.xh>
  197. #endif
  198.  
  199. #ifndef SOM_ODDispatcher_xh
  200. #include <Disptch.xh>
  201. #endif
  202.  
  203. #ifndef SOM_ODArbitrator_xh
  204. #include <Arbitrat.xh>
  205. #endif
  206.  
  207. #ifndef SOM_ODInfo_xh
  208. #include <info.xh>
  209. #endif
  210.  
  211. #ifndef SOM_ODTranslation_xh
  212. #include <Translt.xh>
  213. #endif
  214.  
  215. #ifndef SOM_ODClipboard_xh
  216. #include <Clipbd.xh>
  217. #endif
  218.  
  219. #ifndef SOM_ODDragAndDrop_xh
  220. #include <DragDrp.xh>
  221. #endif
  222.  
  223. #ifndef SOM_ODLinkManager_xh
  224. #include <LinkMgr.xh>
  225. #endif
  226.  
  227. #ifndef SOM_ODNameSpaceManager_xh
  228. #include <NmSpcMg.xh>
  229. #endif
  230.  
  231. #ifndef SOM_ODMessageInterface_xh
  232. #include <MssgIntf.xh>
  233. #endif
  234.  
  235. #ifndef SOM_ODNameResolver_xh
  236. #include <NamRslvr.xh>
  237. #endif
  238.  
  239. #ifndef _SIHELPER_
  240. #include "SIHelper.h"
  241. #endif
  242.  
  243. #ifndef SOM_ODUndo_xh
  244. #include <undo.xh>
  245. #endif
  246.  
  247. #ifndef SOM_ODBinding_xh
  248. #include <ODBindng.xh>
  249. #endif
  250.  
  251. #ifndef SOM_Module_OpenDoc_Foci_defined
  252. #include <Foci.xh>
  253. #endif
  254.  
  255. #ifndef _PLFMFILE_
  256. #include <PlfmFile.h>
  257. #endif
  258.  
  259. #ifndef _ODUTILS_
  260. #include <ODUtils.h>
  261. #endif
  262.  
  263. #ifndef _PASCLSTR_
  264. #include "PasclStr.h"
  265. #endif
  266.  
  267. #ifndef _TOKNTABL_
  268. #include "ToknTabl.h"
  269. #endif
  270.  
  271. #ifndef __RESOURCES__
  272. #include <Resources.h>
  273. #endif
  274.  
  275. #ifndef __TEXTUTILS__
  276. #include <TextUtils.h>
  277. #endif
  278.  
  279. #ifndef __TIME_H__
  280. #include <time.h>
  281. #endif
  282.  
  283. #ifndef __SCRIPT__
  284. #include <script.h>
  285. #endif
  286.  
  287. #ifndef __STDLIB__
  288. #include <StdLib.h>
  289. #endif
  290.  
  291. #define ODSession_Class_Source
  292. #define VARIABLE_MACROS
  293. #include <ODSessn.xih>
  294.  
  295. #pragma segment ODSession
  296.  
  297.  
  298. //------------------------------------------------------------------------------
  299. // Globals
  300. //------------------------------------------------------------------------------
  301.  
  302. QDGlobals * const gODQD = kODNULL;        // Declared in PlfmDef.h
  303.  
  304. //------------------------------------------------------------------------------
  305. // Constants
  306. //------------------------------------------------------------------------------
  307.  
  308. #define kMacUserNameResID -16096    // this Macintosh system resource id is not 
  309.                                     // defined in universal headers as of 2/13/95
  310.  
  311. //==============================================================================
  312. // ODSession
  313. //==============================================================================
  314.  
  315. //------------------------------------------------------------------------------
  316. // ODSession: InitSession
  317. //------------------------------------------------------------------------------
  318.  
  319. SOM_Scope void     SOMLINK ODSessionInitSession(ODSession *somSelf, Environment *ev)
  320. {
  321.     ODSessionMethodDebug("ODSession","InitSession");
  322.  
  323.     SOM_TRY
  324.  
  325.     somSelf->InitBaseSession(ev);
  326.     // Initialize ODQDGlobals, a pointer to the QuickDraw globals. The variable
  327.     // is declared as const so nobody else can modify it, so to initialize it
  328.     // we have to do some fancy casting. (We can't initialize it statically since
  329.     // the QD globals aren't set up at that point.)
  330.     *(QDGlobals**)&gODQD
  331.         = (QDGlobals*)( *(char**)LMGetCurrentA5()
  332.                                             - sizeof(QDGlobals) + sizeof(GrafPtr));
  333.  
  334.     // Initialize the random number seed for UniqueUpdateID
  335.     srand(time((time_t *) kODNULL));
  336.  
  337.     ODStorageSystem* storageSystem = new ODStorageSystem;
  338.     THROW_IF_NULL(storageSystem);
  339.     storageSystem->InitStorageSystem(ev, somSelf);
  340.     somSelf->SetStorageSystem(ev, storageSystem);
  341.     ODClipboard* clipboard = new ODClipboard;
  342.     THROW_IF_NULL(clipboard);
  343.     clipboard->InitClipboard(ev, somSelf);
  344.     somSelf->SetClipboard(ev, clipboard);
  345.     ODInfo* info = new ODInfo;
  346.     THROW_IF_NULL(info);
  347.     info->InitInfo(ev, somSelf);
  348.     somSelf->SetInfo(ev, info);
  349.     ODLinkManager* linkManager = new ODLinkManager;
  350.     THROW_IF_NULL(linkManager);
  351.     linkManager->InitLinkManager(ev, somSelf);
  352.     somSelf->SetLinkManager(ev, linkManager);
  353.  
  354.     ODTranslation* translation = new ODTranslation;
  355.     THROW_IF_NULL(translation);
  356.     translation->InitTranslation(ev, somSelf);
  357.     somSelf->SetTranslation(ev, translation);
  358.  
  359.     ODNameResolver* nameResolver = new ODNameResolver;
  360.     THROW_IF_NULL(nameResolver);
  361.     nameResolver->InitNameResolver(ev, somSelf);
  362.     somSelf->SetNameResolver(ev, nameResolver);
  363.     ODMessageInterface* messageInterface = new ODMessageInterface;
  364.     THROW_IF_NULL(messageInterface);
  365.     somSelf->SetMessageInterface(ev, messageInterface);
  366.     messageInterface->InitMessageInterface(ev, somSelf);
  367.     
  368.     ODUndo* undo = new ODUndo;
  369.     THROW_IF_NULL(undo);
  370.     undo->InitUndo(ev);
  371.     somSelf->SetUndo(ev, undo);
  372.  
  373.     ODNameSpaceManager* nameSpaceManager = new ODNameSpaceManager;
  374.     THROW_IF_NULL(nameSpaceManager);
  375.     // Note that InitNameSpaceManager needs to ask the session for itself
  376.     //    during init time!
  377.     somSelf->SetNameSpaceManager(ev, nameSpaceManager);
  378.     nameSpaceManager->InitNameSpaceManager(ev, somSelf);
  379.     ODBinding* binding = new ODBinding;
  380.     THROW_IF_NULL(binding);
  381.     somSelf->SetBinding(ev, binding);
  382.     binding->InitBinding(ev, somSelf);
  383.     // Note that InitBinding needs to ask the session for itself
  384.     //    during init time to support the BndNSUtils.
  385.  
  386.     TokenTable* tt = new TokenTable(somSelf->GetNameSpaceManager(ev));
  387.     THROW_IF_NULL(tt);
  388.     tt->Initialize();
  389.     somSelf->SetTokenTable(ev, tt);
  390.  
  391.     ODWindowState* windowState = new ODWindowState; // Must be after token table
  392.     THROW_IF_NULL(windowState);
  393.     windowState->InitWindowState(ev, somSelf); 
  394.     somSelf->SetWindowState(ev, windowState);
  395.     ODDragAndDrop* dragAndDrop = new ODDragAndDrop;
  396.     THROW_IF_NULL(dragAndDrop);
  397.     dragAndDrop->InitDragAndDrop(ev, somSelf); // Must be after Window State
  398.     somSelf->SetDragAndDrop(ev, dragAndDrop);
  399.     ODArbitrator* arbitrator = new ODArbitrator; // Must be after token table
  400.     THROW_IF_NULL(arbitrator);
  401.     arbitrator->InitArbitrator(ev, somSelf);
  402.     somSelf->SetArbitrator(ev, arbitrator);
  403.     ODDispatcher* dispatcher = new ODDispatcher; // Must be after token table
  404.     THROW_IF_NULL(dispatcher);
  405.     // Note that InitDispatcher needs to ask the session for itself
  406.     //    during init time!
  407.     somSelf->SetDispatcher(ev, dispatcher);
  408.     dispatcher->InitDispatcher(ev, somSelf);
  409.  
  410.         // temporary work around for #1239535
  411.     somSelf->GetNameSpaceManager(ev)->SynchNSTable(ev);  // Must be after dispatcher
  412.  
  413.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODKeyFocus),kODNULL);    
  414.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMenuFocus),kODNULL);    
  415.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODSelectionFocus),kODNULL);    
  416.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODModalFocus),kODNULL);
  417.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMouseFocus),kODNULL);
  418.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODScrollingFocus),kODNULL);
  419.     arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODClipboardFocus),kODNULL);
  420.  
  421.     somSelf->SetSuccessfullyInitialized(ev);
  422.  
  423.     SOM_CATCH_ALL
  424.     SOM_ENDTRY
  425. }
  426. #if 0
  427. //------------------------------------------------------------------------------
  428. // ODSession: ~ODSession
  429. //------------------------------------------------------------------------------
  430.  
  431. SOM_Scope void  SOMLINK ODSessionsomUninit(ODSession *somSelf)
  432. {
  433.     ODSessionMethodDebug("ODSession","somUninit");
  434.  
  435.     ODSession_parents_somUninit(somSelf);
  436. }
  437. #endif /* 0 */
  438. //------------------------------------------------------------------------------
  439. // ODSession: Purge
  440. //------------------------------------------------------------------------------
  441.  
  442. SOM_Scope ODSize  SOMLINK ODSessionPurge(ODSession *somSelf, Environment *ev,
  443.         ODSize size)
  444. {
  445.     ODSessionMethodDebug("ODSession","Purge");
  446.  
  447.     // dh - Wrap all purge calls in a SOM_TRY block. Also aggregate the total of the
  448.     // amount purged in each call and return that value.
  449.     // You might wonder why I wraped each individual call to the session object's Purge
  450.     // method in another nested TRY block. This is necessary because I cannot 
  451.     // guarantee that each session object, which can be replaced or patched, will not
  452.     // throw, thus stopping purging for the other objects. This also makes the code
  453.     // harder to read.
  454.     ODSize purged = 0; ODVolatile( purged );
  455.     
  456.     SOM_TRY
  457.         TRY
  458.             ODArbitrator*    Arbitrator = somSelf->GetArbitrator(ev);
  459.             if (Arbitrator)
  460.                 purged += somSelf->GetArbitrator(ev)->Purge(ev, size);
  461.         CATCH_ALL
  462.         ENDTRY
  463.  
  464.         TRY
  465.             ODBinding*    Binding = somSelf->GetBinding(ev);
  466.             if (Binding)
  467.                 purged += somSelf->GetBinding(ev)->Purge(ev, size);
  468.         CATCH_ALL
  469.         ENDTRY
  470.  
  471.         TRY
  472.             ODClipboard*    Clipboard = somSelf->GetClipboard(ev);
  473.             if (Clipboard)
  474.                 purged += somSelf->GetClipboard(ev)->Purge(ev, size);
  475.         CATCH_ALL
  476.         ENDTRY
  477.  
  478.         TRY
  479.             ODDispatcher*    Dispatcher = somSelf->GetDispatcher(ev);
  480.             if (Dispatcher)
  481.                 purged += somSelf->GetDispatcher(ev)->Purge(ev, size);
  482.         CATCH_ALL
  483.         ENDTRY
  484.  
  485.         TRY
  486.             ODDragAndDrop*    DragAndDrop = somSelf->GetDragAndDrop(ev);
  487.             if (DragAndDrop)
  488.                 purged += somSelf->GetDragAndDrop(ev)->Purge(ev, size);
  489.         CATCH_ALL
  490.         ENDTRY
  491.  
  492.         TRY
  493.             ODLinkManager*    LinkManager = somSelf->GetLinkManager(ev);
  494.             if (LinkManager)
  495.                 purged += somSelf->GetLinkManager(ev)->Purge(ev, size);
  496.         CATCH_ALL
  497.         ENDTRY
  498.  
  499.         TRY
  500.             ODMessageInterface*    MessageInterface = somSelf->GetMessageInterface(ev);
  501.             if (MessageInterface)
  502.                 purged += somSelf->GetMessageInterface(ev)->Purge(ev, size);
  503.         CATCH_ALL
  504.         ENDTRY
  505.  
  506.         TRY
  507.             ODNameResolver*    NameResolver = somSelf->GetNameResolver(ev);
  508.             if (NameResolver)
  509.                 purged += somSelf->GetNameResolver(ev)->Purge(ev, size);
  510.         CATCH_ALL
  511.         ENDTRY
  512.  
  513.         TRY
  514.             ODNameSpaceManager*    NameSpaceManager = somSelf->GetNameSpaceManager(ev);
  515.             if (NameSpaceManager)
  516.                 purged += somSelf->GetNameSpaceManager(ev)->Purge(ev, size);
  517.         CATCH_ALL
  518.         ENDTRY
  519.  
  520.         TRY
  521.             ODStorageSystem*    StorageSystem = somSelf->GetStorageSystem(ev);
  522.             if (StorageSystem)
  523.                 purged += somSelf->GetStorageSystem(ev)->Purge(ev, size);
  524.         CATCH_ALL
  525.         ENDTRY
  526.  
  527.         TRY
  528.             ODTranslation*    Translation = somSelf->GetTranslation(ev);
  529.             if (Translation)
  530.                 purged += somSelf->GetTranslation(ev)->Purge(ev, size);
  531.         CATCH_ALL
  532.         ENDTRY
  533.  
  534.         TRY
  535.             ODUndo*    Undo = somSelf->GetUndo(ev);
  536.             if (Undo)
  537.                 purged += somSelf->GetUndo(ev)->Purge(ev, size);
  538.         CATCH_ALL
  539.         ENDTRY
  540.  
  541.         TRY
  542.             ODWindowState*    WindowState = somSelf->GetWindowState(ev);
  543.             if (WindowState)
  544.                 purged += somSelf->GetWindowState(ev)->Purge(ev, size);
  545.         CATCH_ALL
  546.         ENDTRY
  547.  
  548.  
  549.         purged += parent_Purge(somSelf, ev, size);
  550.     
  551.     SOM_CATCH_ALL
  552.         WARN("Error %ld trying to purge in ODSessionPurge",ErrorCode());
  553.         SetErrorCode(kODNoError);        // Eat the exception; Purge should not 
  554.                                         // propagate it because clients function
  555.                                         // fine whether memory was purged or not.
  556.     SOM_ENDTRY
  557.  
  558.     return purged;
  559. }
  560.  
  561. //------------------------------------------------------------------------------
  562. // ODSession: GetUserName
  563. //------------------------------------------------------------------------------
  564.  
  565. SOM_Scope void  SOMLINK ODSessionGetUserName(ODSession *somSelf, Environment *ev,
  566.         ODIText* name)
  567. {
  568.     ODSessionMethodDebug("ODSession","GetUserName");
  569.  
  570.     StringHandle    userName;
  571.  
  572.     SOM_TRY
  573.         ASSERT(name, kODErrIllegalNullInput);
  574.  
  575.         //ODScriptCode script = GetScriptManagerVariable(smSysScript);
  576.         ODScriptCode script = FontToScript(GetAppFont());
  577.         ODLangCode lang = GetScriptVariable(script, smScriptLang);
  578.  
  579.         name->format = kODTraditionalMacText;
  580.         name->text._buffer = kODNULL;
  581.         SetITextBufferSize(name, sizeof(ODTradITextDataHeader), kODFalse);
  582.         SetITextScriptCode(name, script);
  583.         SetITextLangCode(name, lang);
  584.  
  585.         userName = GetString(kMacUserNameResID);
  586.         if (userName)
  587.         {
  588.             ODLockHandle((ODHandle)userName);
  589.             SetITextString(name, (StringPtr)*userName);
  590. //            name = CreateITextPString(script, lang, (StringPtr)(*userName));    
  591.         
  592.             ODUnlockHandle((ODHandle)userName);
  593.             ReleaseResource((Handle)userName);
  594.         }
  595.         else
  596.             SetITextString(name, "");
  597. //            name = CreateITextPString(script, lang, (StringPtr) "");
  598.         
  599.         *name = *name;
  600.     SOM_CATCH_ALL
  601.     SOM_ENDTRY
  602. }
  603.  
  604. //------------------------------------------------------------------------------
  605. // ODSession: UniqueUpdateID
  606. //------------------------------------------------------------------------------
  607.  
  608. SOM_Scope ODUpdateID  SOMLINK ODSessionUniqueUpdateID(ODSession *somSelf, Environment *ev)
  609. {
  610.     ODSessionMethodDebug("ODSession","UniqueUpdateID");
  611.  
  612.     return (ODUpdateID) rand();
  613. }
  614.