/* @(#)Z 1.17.1.14 com/src/core/ODSessn.cpp, odcore, od96nt, odnt9712d 97/03/21 16:44:15 (97/02/26 15:48:35) */


//====START_GENERATED_PROLOG======================================
//
//
//   COMPONENT_NAME: odcore
//
//   CLASSES: none
//
//   ORIGINS: 82,27
//
//
//   (C) COPYRIGHT International Business Machines Corp. 1995,1996
//   All Rights Reserved
//   Licensed Materials - Property of IBM
//   US Government Users Restricted Rights - Use, duplication or
//   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//   	
//   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
//   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
//   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
//   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
//   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
//   OR PERFORMANCE OF THIS SOFTWARE.
//
//====END_GENERATED_PROLOG========================================
//
/*
        File:           ODSessn.cpp

        Contains:       ODSession class implementation

        Owned by:       Nick Pilch

        Copyright:      © 1993 - 1995 by Apple Computer, Inc., all rights reserved.

        Change History (most recent first):

                <50>     10/8/95        TJ              Fixes Recomended by Refball
                <49>     4/10/95        NP              1287722: Change signature of
                                                                        ODSession::GetUserName.
                <48>    25/09/95        NP              1280561: Check results of operator new.
                <47>     8/29/95        DM              1276569: FB3:ODSession::GetUserName can
                                                                        return bogus string
                <46>     8/29/95        RR              # 1276401 Register Mouse Focus
                <45>     8/16/95        NP              1242634: Remove #define PLATFORMFILEVIRTUAL
                                                                        when PlatformFile has no virt. methods.
                <44>      8/3/95        RR              #1257260: Collapse B classes. Remove
                                                                        somInit methods. Don't call IsInitialized
                                                                        or SubclassResponsibility
                <43>     7/27/95        CC              1153788: Use std C library routines rand
                                                                        and srand for generating unique update ids.
                <42>     5/30/95        CG              #1252280 BB: PStrToIntl should not  be used
                                                                        by OpenDoc.
                <41>     5/26/95        DM              1251403: Multithreading naming support.
                <40>     5/24/95        CG              #1239535 BB: Added temporary work around.
                <39>     5/11/95        NP              1242421: Fix exception handling
                <38>     5/11/95        VL              1238421: Implemented Purge.
                <37>     4/26/95        CG              1211082 BB: 5$ Bugs need to be evaluated
                                                                        and removed from Core
                <36>      4/5/95        CG              #1216169 BB, #1221135: When Editors folder
                                                                        or OpenDoc Libraries folder is missing,
                                                                        OpenDoc quits and displays error.
                <35>     3/27/95        CC              1231902: Pass ODSession to
                                                                        InitTranslation().
                <34>      3/7/95        RR              #1220929 Caching of foci in ODWindowState
                                                                        necessitated reordering of Inits
                <33>     2/16/95        CG              #1207793: defined resource id constant.
                <32>     2/10/95        CG              #1177475: Need to initialize translation
                                                                        object before nameSpaceManager.
                <31>    12/13/94        SS              1205663 - changed ODQD to gODQD
                <30>     12/5/94        jpa             Added global ODQD & initialization code
                                                                        [1203926]
                <29>    11/30/94        RR              Include time.h
                <28>    11/15/94        NP              1200193-The Shell should instantiate its
                                                                        Semantic Interface.
                <27>    11/15/94        NP              1200132-Removed instantiation of Shell
                                                                        Semantic Interface from here.
                <26>     10/7/94        CC              1191489 - Moved UniqueUpdateID() in from
                                                                        base class.
                <25>      9/9/94        NP              1184043: Change to InitSemanticInterface.
                <24>     8/22/94        T‚              #1182448 System Process quits when no
                                                                        OpenDoc documents are running
                <23>     8/19/94        NP              1181622: Ownership fix.
                <22>     8/13/94        T‚              #1180814 Added support for ODPartWrapper
                                                                        API and removed a chr(16) on line #288
                                                                        which was randomly introduced by projector?
                <21>     8/12/94        NP              1180762-added setters for getters. moved
                                                                        stuff to B file. Removed GetSemtInterface.
                <20>      8/3/94        CC              Register the clipboard focus.
                <19>      8/3/94        VL              1153123: Storage to ODStor.
                <18>      8/2/94        T‚              bug# for #17 right below was #1178167
                <17>      8/2/94        T‚              added TOKENTABLECORRUPTED to work around
                                                                        heap corruption occuring when fTokenTable
                                                                        was deleted.  Changed deletes to
                                                                        ODDeleteObject.
                <16>     7/29/94        CG              Removed Object registration APIs from
                                                                        session.
                <15>     7/21/94        T‚              explicitly create & delete a PlatformFile
                                                                        to make sure it is not deadstripped, added
                                                                        #define PLATFORMFILEVIRTUAL
                <14>     7/11/94        T‚              added GetInfo, SetInfo, set _fInfo in
                                                                        InitSession
                <13>     7/11/94        NP              Fixed compile problem in GetUserName.
                <12>      7/8/94        NP              Fix GetUserName.
                <11>      7/7/94        RR              Initialize dispatcher AFTER token table
                <10>      7/1/94        NP              Change to InitSIHelper.
                 <9>      7/1/94        CG              Uncommented code in GetUserName.
                 <8>     6/30/94        CG              Uncommented messaging-related fields and
                                                                        methods, moved StdDisp initialization to
                                                                        Dispatch.cpp.
                 <7>     6/28/94        VL              Use DragDrp.
                 <6>     6/28/94        VL              Fixed parameters to InitStorageSystem.
                 <5>     6/24/94        CG              Initialization clean up.
                 <4>     6/23/94        CG              Somverted original implementation.
                 <3>     6/19/94        MB              Implement GetDefaultHeap
                 <2>     6/18/94        MB              Add memory component
                 <1>     6/14/94        CG              first checked in
                ------------------------------------------------------------
                 <7>      6/6/94        jpa             Eliminate spurious ASLM header include.
                                                                        [1153437]
                 <6>      6/1/94        CG              Moved fPreferences to nameSpaceManager and
                                                                        changed session to use public binding
                                                                        object.
                 <5>     5/27/94        CG              #1165186: Abstracted prefs out of binding.
                 <4>      5/9/94        MB              #1162181: Changes necessary to install MMM.
                 <3>      4/1/94        T‚              #1154941: Get OpenDoc source to actually
                                                                        compile for PowerPC
                 <2>     3/31/94        eeh             bug #1153999: PStrToIntl interface changed.
                 <1>     3/28/94        CG              first checked in
                 <6>     3/26/94        NP              1153512. Object Registration API needed.
                 <5>     3/26/94        NP              1153504. InitSemanticInterface.
                 <4>     3/25/94        CC              Change name of included file to
                                                                        <LinkMgr.xh>. (1153348)
                 <3>     3/15/94        MB              Changes to support SCpp/ASLM builds,
                                                                        #1150864.
                 <2>     2/28/94        CG              (no bug #) Changed call to GetSystemPool()
                                                                        to XMPGetSystemHeap().
                <39>      2/9/94        T‚              Throw to THROW
                <38>      2/7/94        T‚              more PPC header fixes
                <37>      2/4/94        T‚              fixes to compile with PPC Universal headers
                <36>      2/3/94        CG              System Session gets created in InitSession.
                <35>      2/1/94        RR              Call InitSessionForPlatform in InitSession
                <34>     1/28/94        CC              Added UniqueUpdateID().
                <33>     1/15/94        RR              WinState.h->WinStat.h,
                                                                        Dispatch.h->Disptch.h
                <32>     1/14/94        NP              Init changes.
                <31>     1/14/94        CG              Added include for new NmSpcMgr.h.
                <30>     1/12/94        CG              Added fBinding field and calls to new
                                                                        ODBinding and InitBinding.
                <29>     1/12/94        VL              Init changes.
                <28>    12/20/93        RR              New constructor/init interface
                <27>    12/15/93        T‚              more InitObject changes, rename
                                                                        Initialize() method call for ClipBoard and
                                                                        NameSpaceManager
                <26>     12/8/93        CC              Create and Initialize Link Manager object
                <25>     12/3/93        T‚              Stop including ODError.h, it is included
                                                                        as ErrorDef.h inside Except.h
                <24>     12/2/93        CC              Call InitClipboard().
                <23>    11/16/93        RR              Register stddispatchmodule for
                                                                        kHighLevelEvent
                <22>    11/15/93        NP              Changed XMPSymbols to ODNameSpaceManager.
                <21>    10/28/93        NP              GetType returns a boolean instead of
                                                                        throwing an exception.
                <20>    10/22/93        NP              Added session parameter to ODNameResolver
                                                                        constructor.
                <19>    10/20/93        CC              Added session parameter to ODClipboard
                                                                        constructor
                <18>     9/20/93        NP              Changed order of ODMessageInterface and
                                                                        ODNameResolver initialization.
                <17>     8/11/93        RR              Added code to install standard dispatch
                                                                        module (moved from dispatcher)
                <16>     7/28/93        NP              Added GetSession function.
                <15>     7/21/93        T‚              change destructor to delete fTokenTable
                                                                        before deleting fNameSpaceManager (~TokenTable
                                                                        seemed to need fNameSpaceManager)
                <14>     7/12/93        CG              Added fShellSemtInterface and
                                                                        AcquireShellSemtInterface() to Session class.
                <13>     6/23/93        RCR             Initialize TokenTable before arbitrator.
                <12>     6/22/93        NP              Added Tokenize methods.
                <11>     5/18/93        NP              Changed call to ODMessageInterface
                                                                        constructor.
                <10>     4/28/93        NP              File name changes.
                 <9>     4/27/93        NP              Uncommented last comments.
                 <8>     4/27/93        NP              Commented out the construction of some
                                                                        objects. Fixed OpenODSession.
                 <7>     4/23/93        NP              Removed warning from Purge.
                 <6>     4/23/93        NP              Fixed GetStorageSystem.
                 <5>     4/23/93        NP              Fixed Purge.
                 <4>     4/23/93        NP              Fixed call to ODSemanticInterface
                                                                        constructor.
                 <3>     4/23/93        NP              Fixed Initialize to call Initialize members
                                                                        for objects it creates. Uncommented
                                                                        constructor and zeroed out fields in it.
                 <2>     4/22/93        RCR             Add Session:: to Initialize. Remove ODMethod
                 <1>     4/21/93        NP              first checked in

        To Do: 1276569: when name is not found return empty string from GetUserName()
*/

#ifndef _ALTPOINT_
#include "AltPoint.h"                   // Use C++ savvy ODPoint and ODRect
#endif

#ifndef _PLFMDEF_
#include "PlfmDef.h"
#endif

#ifndef SOM_ODStorageSystem_xh
#include <ODStor.xh>
#endif

#ifndef SOM_ODWindowState_xh
#include <WinStat.xh>
#endif

#ifndef SOM_ODDispatcher_xh
#include <Disptch.xh>
#endif

#ifndef SOM_ODArbitrator_xh
#include <Arbitrat.xh>
#endif

#ifndef SOM_ODInfo_xh
#include <Info.xh>
#endif

#ifndef SOM_ODTranslation_xh
#include <Translt.xh>
#endif

#ifndef SOM_ODClipboard_xh
#include <Clipbd.xh>
#endif

#ifndef SOM_ODDragAndDrop_xh
#include <DragDrp.xh>
#endif

#ifndef SOM_ODLinkManager_xh
#include <LinkMgr.xh>
#endif

#ifndef SOM_ODNameSpaceManager_xh
#include <NmSpcMg.xh>
#endif

#ifndef SOM_ODUndo_xh
#include <Undo.xh>
#endif

#ifdef _TOOLSPACE_
#ifndef SOM_ODToolSpaceManager_xh
#include <ODTlSpc.xh>
#endif
#endif

#ifndef SOM_ODBinding_xh
#include <ODBindng.xh>
#endif

#ifndef SOM_Module_OpenDoc_Foci_defined
#include <Foci.xh>
#endif

#ifndef _PLFMFILE_
#include <PlfmFile.h>
#endif

#ifndef _ODUTILS_
#include <ODUtils.h>
#endif

#ifdef _PLATFORM_MACINTOSH_
#ifndef _PASCLSTR_
#include "PasclStr.h"
#endif
#endif

#ifndef _TOKNTABL_
#include "ToknTabl.h"
#endif

#ifdef _PLATFORM_MACINTOSH_
#ifndef __RESOURCES__
#include <Resources.h>
#endif
#endif

#ifdef _PLATFORM_MACINTOSH_
#ifndef __TEXTUTILS__
#include <TextUtils.h>
#endif
#endif

#ifndef __TIME_H__
#include <time.h>
#endif

#ifdef _PLATFORM_MACINTOSH_
#ifndef __SCRIPT__
#include <script.h>
#endif
#endif

#ifndef _PLATFORM_OS2_
#ifndef SOM_ODHelp_xh
#include <odhelp.xh>
#endif
#endif //not _PLATFORM_OS2_

#ifndef __STDLIB__
#include <stdlib.h>
#endif

#ifdef _PLATFORM_WIN32_
#include <olemgrw.h>
#endif

#define ODSession_Class_Source
#define VARIABLE_MACROS
#include <ODSessn.xih>

#pragma segment ODSession


//------------------------------------------------------------------------------
// Globals
//------------------------------------------------------------------------------

#ifdef _PLATFORM_MACINTOSH_
QDGlobals * const gODQD = kODNULL;              // Declared in PlfmDef.h
#endif

//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------

#ifdef _PLATFORM_MACINTOSH_
#define kMacUserNameResID -16096        // this Macintosh system resource id is not
                                        // defined in universal headers as of 2/13/95
#endif

//==============================================================================
// ODSession
//==============================================================================

//------------------------------------------------------------------------------
// ODSession: InitSession
//------------------------------------------------------------------------------

#ifdef _PLATFORM_WIN32_   // Need shell pointer on Win32 to give to OLEManager
        SOM_Scope void   SOMLINK ODSessionInitSession(ODSession *somSelf,
                                                        Environment *ev,
                                                        OpenDocShell *shell)
#else
        SOM_Scope void   SOMLINK ODSessionInitSession(ODSession *somSelf,
                                                        Environment *ev)
#endif
{
    ODSessionMethodDebug("ODSession","InitSession");

         try {

        somSelf->InitBaseSession(ev);

        // Initialize the random number seed for UniqueUpdateID
        srand(time((time_t *) kODNULL));

        ODStorageSystem* storageSystem = new ODStorageSystem;
        THROW_IF_NULL(storageSystem);
        storageSystem->InitStorageSystem(ev, somSelf);
        somSelf->SetStorageSystem(ev, storageSystem);

#ifdef _PLATFORM_WIN32_
        // Create and Initialize the OLEManager
        ODOLEManager *OLEManager = new ODOLEManager;
        THROW_IF_NULL(OLEManager);
        OLEManager->Initialize(shell);
        somSelf->SetOleManager(ev, OLEManager);
#endif

        ODInfo* info = new ODInfo;
        THROW_IF_NULL(info);
        info->InitInfo(ev, somSelf);
        somSelf->SetInfo(ev, info);

        ODLinkManager* linkManager = new ODLinkManager;
        THROW_IF_NULL(linkManager);
        linkManager->InitLinkManager(ev, somSelf);
        somSelf->SetLinkManager(ev, linkManager);
#ifdef _PLATFORM_UNIX_
	ODSessionData *somThis = ODSessionGetData(somSelf);
	_SessionLinkDstList = new XLinkInfoList;
	_SessionLinkSrcList = new XLinkInfoList;
#endif

        ODTranslation* translation = new ODTranslation;
        THROW_IF_NULL(translation);
        translation->InitTranslation(ev, somSelf);
        somSelf->SetTranslation(ev, translation);

#if 0 // do not instantiate OSA global objects for WIN32, OS2, AIX
        ODNameResolver* nameResolver = new ODNameResolver;
        THROW_IF_NULL(nameResolver);
        nameResolver->InitNameResolver(ev, somSelf);
        somSelf->SetNameResolver(ev, nameResolver);
        ODMessageInterface* messageInterface = new ODMessageInterface;
        THROW_IF_NULL(messageInterface);
        messageInterface->InitMessageInterface(ev, somSelf);
        somSelf->SetMessageInterface(ev, messageInterface);
#endif

        ODUndo* undo = new ODUndo;
        THROW_IF_NULL(undo);
        undo->InitUndo(ev);
        somSelf->SetUndo(ev, undo);

        ODNameSpaceManager* nameSpaceManager = new ODNameSpaceManager;
        THROW_IF_NULL(nameSpaceManager);
        // Note that InitNameSpaceManager needs to ask the session for itself
        //      during init time!
        somSelf->SetNameSpaceManager(ev, nameSpaceManager);
        nameSpaceManager->InitNameSpaceManager(ev, somSelf);

        ODBinding* binding = new ODBinding;
        THROW_IF_NULL(binding);
        binding->InitBinding(ev, somSelf);
        somSelf->SetBinding(ev, binding);

        TokenTable* tt = new TokenTable(somSelf->GetNameSpaceManager(ev));
        THROW_IF_NULL(tt);
        tt->Initialize();
        somSelf->SetTokenTable(ev, tt);

	// Must be after token table
        ODWindowState* windowState = new ODWindowState; 
        THROW_IF_NULL(windowState);
        windowState->InitWindowState(ev, somSelf);
        somSelf->SetWindowState(ev, windowState);

	// Must be after WindowState (AIX)
        ODClipboard* clipboard = new ODClipboard;
        THROW_IF_NULL(clipboard);
        clipboard->InitClipboard(ev, somSelf);
        somSelf->SetClipboard(ev, clipboard);

        ODDragAndDrop* dragAndDrop = new ODDragAndDrop;
        THROW_IF_NULL(dragAndDrop);
#if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
        dragAndDrop->InitDragAndDrop(ev, somSelf); // Must be after Window State
#endif
        somSelf->SetDragAndDrop(ev, dragAndDrop);

	// Must be after token table
        ODArbitrator* arbitrator = new ODArbitrator; 
        THROW_IF_NULL(arbitrator);
        arbitrator->InitArbitrator(ev, somSelf);
        somSelf->SetArbitrator(ev, arbitrator);

	// Must be after token table
        ODDispatcher* dispatcher = new ODDispatcher; 
        THROW_IF_NULL(dispatcher);
        // Note that InitDispatcher needs to ask the session for itself
        //      during init time!
        somSelf->SetDispatcher(ev, dispatcher);
        dispatcher->InitDispatcher(ev, somSelf);

#ifdef _TOOLSPACE_
        // Added for Toolspace support
        ODToolSpaceManager* toolspacemgr = new ODToolSpaceManager;
        THROW_IF_NULL(toolspacemgr);
        toolspacemgr->InitToolSpaceManager(ev, somSelf);
        somSelf->SetToolSpaceManager(ev, toolspacemgr);
#endif

	// Must be after dispatcher
        somSelf->GetNameSpaceManager(ev)->SynchNSTable(ev);  

        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODKeyFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMenuFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODSelectionFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODModalFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODMouseFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODScrollingFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODClipboardFocus),kODNULL);

        // Toolspace support
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODDeskTopToolFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODDocumentToolFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODRootToolFocus),kODNULL);
        arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODPartFrameToolFocus),kODNULL);
        // These two calls are not needed if a status line is not supported.
        //arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODStatusToolFocus),kODNULL);
        //arbitrator->RegisterFocus(ev,somSelf->Tokenize(ev,kODStatusTextFocus),kODNULL);

        }       
        catch (ODException _exception) {
            SetErrorCode(kODNoError);
        }
}

//------------------------------------------------------------------------------
// ODSession: ~ODSession
//------------------------------------------------------------------------------

SOM_Scope void  SOMLINK ODSessionsomUninit(ODSession *somSelf)
{
#ifndef _PLATFORM_OS2_
    ODSessionData *somThis = ODSessionGetData(somSelf);
#endif  //not _PLATFORM_OS2_
    ODSessionMethodDebug("ODSession","somUninit");

#ifndef _PLATFORM_OS2_
    Environment* ev = SOM_CreateLocalEnvironment();
     try {
      if (_fHelp)
      {
        _fHelp->TerminateHelp(ev);
        _fHelp = kODNULL;
      }
    }       
    catch (ODException _exception) {
            SetErrorCode(kODNoError);
    }
    // Destroy local SOM environment we created.
    SOM_DestroyLocalEnvironment(ev);
#endif  //not _PLATFORM_OS2_

    ODSession_parents_somUninit(somSelf);
}

//------------------------------------------------------------------------------
// ODSession: Purge
//------------------------------------------------------------------------------

SOM_Scope ODSize  SOMLINK ODSessionPurge(ODSession *somSelf, Environment *ev,
                ODSize size)
{
    ODSessionMethodDebug("ODSession","Purge");

        ODSize purged;

        try {

        somSelf->GetArbitrator(ev)->Purge(ev, size);
        somSelf->GetBinding(ev)->Purge(ev, size);
        somSelf->GetClipboard(ev)->Purge(ev, size);
        somSelf->GetDispatcher(ev)->Purge(ev, size);
        somSelf->GetDragAndDrop(ev)->Purge(ev, size);
        somSelf->GetLinkManager(ev)->Purge(ev, size);
//      somSelf->GetMessageInterface(ev)->Purge(ev, size);
//      somSelf->GetNameResolver(ev)->Purge(ev, size);
        somSelf->GetNameSpaceManager(ev)->Purge(ev, size);
        somSelf->GetStorageSystem(ev)->Purge(ev, size);
        somSelf->GetTranslation(ev)->Purge(ev, size);
        somSelf->GetUndo(ev)->Purge(ev, size);
        somSelf->GetWindowState(ev)->Purge(ev, size);

        purged= parent_Purge(somSelf, ev, size);

        }       
        catch (ODException _exception) {
            purged = 0;
            SetErrorCode(kODNoError);
        }
        return purged;
}

//------------------------------------------------------------------------------
// ODSession: GetUserName
//------------------------------------------------------------------------------

SOM_Scope void  SOMLINK ODSessionGetUserName
                (ODSession *somSelf, Environment *ev,
                ODIText** name)

{
    ODSessionMethodDebug("ODSession","GetUserName");

        StringHandle    userName;

        try {
		if (!name) ODSetSOMException(ev,kODErrIllegalNullInput);

#ifdef _PLATFORM_MACINTOSH_
                //ODScriptCode script = GetScriptManagerVariable(smSysScript);
                ODScriptCode script = FontToScript(GetAppFont());
                ODLangCode lang = GetScriptVariable(script, smScriptLang);

                name->format = kODTraditionalMacText;
                name->text._buffer = kODNULL;
                SetITextBufferSize(name, sizeof(ODTradITextDataHeader), kODFalse);
                SetITextScriptCode(name, script);
                SetITextLangCode(name, lang);

                userName = GetString(kMacUserNameResID);
                if (userName)
                {
                        ODLockHandle((ODHandle)userName);
                        SetITextString(name, (StringPtr)*userName);
//                      name = CreateITextPString(script, lang, (StringPtr)(*userName));

                        ODUnlockHandle((ODHandle)userName);
                        ReleaseResource((Handle)userName);
                }
                else
//                      name = CreateITextPString(script, lang, (StringPtr) "");
#endif

#ifdef _PLATFORM_UNIX_
        char* buffer = getlogin();
#endif

#ifdef _PLATFORM_NT_
        char *buffer = getenv("USERNAME");
#endif
        if (!buffer) {
            *name = CreateITextCString(0,0,"");
        }
        else {
            char *login_name =(char* )  SOMMalloc(strlen(buffer)+1);
            strcpy(login_name, buffer);
            *name = CreateITextFromCharPtr(login_name);
        }
        }       
        catch (ODException _exception) {
            SetErrorCode(kODNoError);
        }
}

//------------------------------------------------------------------------------
// ODSession: UniqueUpdateID
//------------------------------------------------------------------------------

SOM_Scope ODUpdateID  SOMLINK ODSessionUniqueUpdateID
                (ODSession *somSelf, Environment *ev)
{
    ODSessionMethodDebug("ODSession","UniqueUpdateID");

        return (ODUpdateID) rand();
}

#ifndef _PLATFORM_OS2_
//------------------------------------------------------------------------------
// ODSession: GetHelp
//------------------------------------------------------------------------------
// returns a pointer to the help instance. if the help instance is not initialized
// it will do it here.  Help is not initialized till call made to help
SOM_Scope ODHelp*  SOMLINK ODSessionGetHelp(ODSession *somSelf,
                                             Environment *ev)
{
    ODSessionData *somThis = ODSessionGetData(somSelf);
    ODSessionMethodDebug("ODSession","ODSessionGetHelp");
    if (! _fHelp )
    {
       _fHelp = new ODHelp;
       _fHelp->InitHelp(ev, somSelf);
    } /* endif */
    return _fHelp;
}
#endif  //not _PLATFORM_OS2_


#ifdef _PLATFORM_UNIX_
//------------------------------------------------------------------------------
// ODSession: GetSessionLinkSrcList
//------------------------------------------------------------------------------
SOM_Scope XLinkInfoList*  SOMLINK ODSessionGetSessionLinkSrcList
					(ODSession *somSelf,
					 Environment *ev)
{
	ODSessionData *somThis = ODSessionGetData(somSelf);
	ODSessionMethodDebug("ODSession","ODSessionGetSessionLinkSrcList");

	return _SessionLinkSrcList;
}

//------------------------------------------------------------------------------
// ODSession: GetSessionLinkDstList
//------------------------------------------------------------------------------
SOM_Scope XLinkInfoList*  SOMLINK ODSessionGetSessionLinkDstList
					(ODSession *somSelf,
					 Environment *ev)
{
	ODSessionData *somThis = ODSessionGetData(somSelf);
	ODSessionMethodDebug("ODSession","ODSessionGetSessionLinkDstList");

	return _SessionLinkDstList;
}
#endif  //_PLATFORM_UNIX_

//------------------------------------------------------------------------------
// ODSession: GetRegistry
//------------------------------------------------------------------------------

SOM_Scope ODPartHandlerRegistryInt*  SOMLINK ODSessionGetRegistry
                (ODSession *somSelf, Environment *ev)
{
    ODSessionData *somThis = ODSessionGetData(somSelf);
    ODSessionMethodDebug("ODSession","GetRegistry");

        return _fODRegistry;
}

//------------------------------------------------------------------------------
// ODSession: SetRegistry
//------------------------------------------------------------------------------

SOM_Scope void  SOMLINK ODSessionSetRegistry
                (ODSession *somSelf, Environment *ev,
                ODPartHandlerRegistryInt* registry)
{
    ODSessionData *somThis = ODSessionGetData(somSelf);
    ODSessionMethodDebug("ODSession","ODSessionSetRegistry");

        _fODRegistry = registry;
}

