home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 20.3 KB | 470 lines | [TEXT/MPS ] |
- {
- File: LibraryManagerUtilities.p
-
- Contains: Interfaces file for ASLM utilities
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- }
-
-
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := 0}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT LibraryManagerUtilities;
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED UsingLibraryManagerUtilities}
- {$SETC UsingLibraryManagerUtilities := 1}
-
- {$I+}
- {$SETC LibraryManagerUtilitiesIncludes := UsingIncludes}
- {$SETC UsingIncludes := 1}
- {$IFC UNDEFINED UsingLibraryManager}
- {$I LibraryManager.p}
- {$ENDC}
- {$SETC UsingIncludes := LibraryManagerUtilitiesIncludes}
-
- {******************************************************************************
- ** Forward class declarations
- *******************************************************************************}
-
- TYPE
- TNotifierPtr = Ptr;
- TLibraryFilePtr = Ptr;
- TLibraryPtr = Ptr;
- TFunctionSetInfoPtr = Ptr;
- TMemoryPoolPtr = Ptr;
-
- {******************************************************************************
- ** Routines for loading and unloading the ASLM.
- **
- ** UnloadLibraryManager and LoadLibraryManager can be bad for your health!
- ** They should only be used for testing purposes.
- *******************************************************************************}
-
- FUNCTION IsLibraryManagerLoaded: Boolean; C;
- FUNCTION LoadLibraryManager: Boolean; C; { returns true if successful or already loaded }
- PROCEDURE UnloadLibraryManager ; C;
-
- {*******************************************************************************
- ** Routines for allocating memory out of TMemoryPools.
- **
- ** The following routines allow Pascal users to allocate memory from TMemoryPools.
- ** SLMNewOperator is used for doing allocations and SLMDeleteOperator is
- ** used for freeing memory. SLMNewOperator will allocate memory out of
- ** the specified pool. If you pass in NULL for the pool then it will use
- ** default memory allocation. The default memory allocation is to allocate
- ** out of the the library's local pool if the library was built with
- ** memory=local, and out of the client's local pool if the library was built
- ** with memory=client. If you don't want to use default memory allocation then
- ** you can call GetLocalPool to get the library's local pool, and GetClientPool
- ** to get the current client's local pool.
- ********************************************************************************}
-
- FUNCTION SLMNewOperator(memsize : LONGINT; pool : TMemoryPoolPtr) : Ptr; C;
- PROCEDURE SLMDeleteOperator(memory : Ptr); C;
-
- {******************************************************************************
- ** GetSLMVersion
- **
- ** Returns the version of the installed ASLM in the 'vers'
- ** resource format (the first 4 bytes only). Returns 0 if the
- ** ASLM is not installed.
- *******************************************************************************}
-
- FUNCTION GetSLMVersion: LONGINT; C;
-
- {*******************************************************************************
- ** Trace
- **
- ** Used to send output to the Trace Montior's Window.
- ********************************************************************************}
-
- PROCEDURE Trace(outString : StringPtr); C;
-
- {******************************************************************************
- ** Utility functions for getting high and low bytes and words
- *******************************************************************************}
-
- FUNCTION HighWord(l : LongInt): INTEGER; INLINE
- $201F, { move.l (sp)+,d0 }
- $4840, { swap d0 }
- $3E80; { move.w d0,(sp) }
-
- FUNCTION LowWord(l : LongInt): INTEGER; INLINE
- $201F, { move.l (sp)+,d0 }
- $3E80; { move.w d0,(sp) }
-
- FUNCTION HighByte(i : INTEGER): Byte; INLINE
- $301F, { move.w (sp)+,d0 }
- $E048, { lsr.w #8,d0 }
- $3E80; { move.w d0,(sp) }
-
- FUNCTION LowByte(i : INTEGER): Byte; INLINE
- $301F, { move.w (sp)+,d0 }
- $0240, $00FF, { andi.w #$0FF,d0 }
- $3E80; { move.w d0,(sp) }
-
- {******************************************************************************
- ** Atomic Bit functions
- **
- ** These functions atomically set and clear bits, and return what value the
- ** bit previously had
- *******************************************************************************}
-
- FUNCTION SetBit(mem : Ptr; bitno : LONGINT): Boolean; C;
- FUNCTION ClearBit(mem : Ptr; bitno : LONGINT): Boolean; C;
- FUNCTION TestBit(mem : Ptr; bitno : LONGINT): Boolean; C;
-
- {******************************************************************************
- ** Memory Functions
- **
- ** SLMmemcpy, SLMmemmove, and SLMmemset are equivalent to the C memcpy, memmove,
- ** and memset routines. They are exported by SLM and are faster then the C versions.
- *******************************************************************************}
-
- PROCEDURE ZeroMem(destPtr : Ptr; nBytes : LONGINT); C;
- FUNCTION SLMmemcpy(destPtr : Ptr; src : Ptr; nBytes : LONGINT): Ptr; C;
- FUNCTION SLMmemmove(destPtr : Ptr; src : Ptr; nBytes : LONGINT): Ptr; C;
- FUNCTION SLMmemset(destPtr : Ptr; c : LONGINT; nBytes : LONGINT): Ptr; C;
-
- {**********************************************************************
- ** TFileSpec
- **
- ** TFileSpec is a structure for specifying the location of a library
- ** file (TLibraryFile) in a file system or OS independent way. The
- ** "subclasses" contain the details and the "base class" is used to compare
- ** them or to pass them around without worry about the contents.
- **
- ** Currently only the TMacFileSpec is supported since this is how the
- ** SLM tracks library files on the Mac OS. There is a chance that in the
- ** furture it may track files under System 7.0 using TFileIDFileSpec so
- ** you should write your 7.0 code to handle either type. The
- ** IsFileSpecTypeSupported() routine will tell you if the specified
- ** TFileSpec subclass is supported.
- **
- ** Generally you don't need to be concerned with with TFileSpecs unless
- ** you are going to call RegisterLibraryFile(), RegisterLibraryFileFolder(),
- ** or GetFileSpec().
- ***********************************************************************}
-
- { Different types of TFileSpecs we can have. }
- TYPE FileSpecType =
- (
- kUnknownType, kMacType, kFileIDType
- );
-
- FUNCTION IsFileSpecTypeSupported(theType : FileSpecType): Boolean; C;
- FUNCTION CompareFileSpecs(f1 : Ptr; f2 : Ptr): Boolean; C;
-
- TYPE TFileSpec = RECORD
- fType: FileSpecType; { FileSpectype }
- fSize: Byte; { size of struct }
- END;
- TYPE TFileSpecPtr = ^TFileSpec;
-
- {**********************************************************************
- ** TMacFileSpec
- **
- ** TMacFileSpec keeps track of the file by using an file name, volume
- ** refNum, and directory id. You must use InitMacFileSpec to make
- ** sure that the length is set properly.
- ***********************************************************************}
-
- TYPE TMacFileSpec = RECORD
- fType: FileSpecType; { FileSpectype }
- fSize: Byte; { size of struct }
- fVRefNum: INTEGER; { volume refNum of volume file is on }
- fParID: LONGINT; { dirID of the folder file is in }
- fName: Str63; { name of the file }
- END;
- TYPE TMacFileSpecPtr = ^TMacFileSpec;
-
- PROCEDURE InitMacFileSpec(spec : TMacFileSpecPtr; vRefNum : INTEGER;
- parID : LONGINT; name : Str63); C;
-
- {**********************************************************************
- ** TFileIDFileSpec
- **
- ** TFileIDFileSpec keeps track of library files by fileID and vRefNum.
- ** You must use InitFileIDFileSpec to make sure that the length is set
- ** properly.
- ***********************************************************************}
-
- TYPE TFileIDFileSpec = RECORD
- fType: FileSpecType; { FileSpectype }
- fSize: Byte; { size of struct }
- fVRefNum: INTEGER; { volume refNum }
- fFileID: LONGINT; { FileID }
- END;
- TYPE TFileIDFileSpecPtr = ^TFileIDFileSpec;
-
- PROCEDURE InitFileIDFileSpec(spec : TFileIDFileSpecPtr; vRefNum : INTEGER; fileID : LONGINT); C;
-
-
- {*******************************************************************************
- ** RegisterLibraryFile/UnregisterLibraryFile
- **
- ** Used to register or unregister a library file. Currently only the
- ** TMacFileSpec is supported. You'll get a kASLMNotSupportedErr error for anything else.
- **
- ** RegisterLibraryFile returns kNoError if successful or kASLMFileNotFoundErr if
- ** an error ocurred while trying to access the file. Other error codes are also
- ** possible if there was trouble processing the file such as kASLMOutOfMemoryErr.
- **
- ** UnregisterLibraryFile accepts a "forceUnload" parameter. If true is passed
- ** then it will force all loaded libraries in the library file to be
- ** unloaded even if they are in use. Unless you are sure that loaded libraries
- ** can be safely unloaded you should pass false. In this case the library file
- ** will not be deleted until all of its libraries are unloaded.
- ** kNoError will be returned if successful and wil be returend kASLMNotSupportedErr if
- ** the folder was never registered.
- ********************************************************************************}
-
- FUNCTION RegisterLibraryFile(fileSpec : TFileSpecPtr; VAR libFile : TLibraryFilePtr): OSErr; C;
- FUNCTION UnregisterLibraryFile(fileSpec : TFileSpecPtr; forceUnload : Boolean): OSErr; C;
- FUNCTION UnregisterLibraryFileByFileSpec(libFile : TLibraryFilePtr;
- forceUnload : Boolean): OSErr; C;
-
- {******************************************************************************
- ** RegisterLibraryFileFolder/UnregisterLibraryFileFolder
- **
- ** Used to register a folder that contains library files in it. The SLM will keep
- ** track of library files dragged into and out of this folder. Currently only the
- ** TMacFileSpec is supported. You'll get a kASLMNotSupportedErr error for anything else.
- **
- ** RegisterLibraryFileFolder returns kNoError if successful or kASLMFileNotFoundErr if
- ** an error ocurred while trying to access the folder.
- **
- ** UnregisterLibraryFileFolder accepts a "forceUnload" parameter. If true is passed
- ** then it will unregister the folder and force all loaded libraries to be
- ** unloaded even if they are in use. Unless you are sure that loaded libraries
- ** can be safely unloaded you should pass false. kNoError will be returned if
- ** successful, kASLMFolderNotFoundErr if the folder was never registered, and
- ** kASLMFolderInUseErr if any libraries in the folder were loaded and false was passed
- ** in the forceUnload parameter.
- *******************************************************************************}
-
- FUNCTION RegisterLibraryFileFolder(fileSpec : TFileSpecPtr): OSErr; C;
- FUNCTION UnregisterLibraryFileFolder(fileSpec : TFileSpecPtr; forceUnload : Boolean): OSErr; C;
-
- {******************************************************************************
- ** EnterSystemMode/LeaveSystemMode
- **
- ** These functions should bracket calls that open files or get memory that needs
- ** to hang around after an application quits
- *******************************************************************************}
-
- FUNCTION EnterSystemMode: Ptr; C;
- PROCEDURE LeaveSystemMode(saveRef : Ptr); C;
-
- {******************************************************************************
- ** Death Notification
- *******************************************************************************}
-
- FUNCTION InstallDeathWatcher(notifier : TNotifierPtr): Boolean; C;
- FUNCTION RemoveDeathWatcher(notifier : TNotifierPtr): Boolean; C;
-
- {******************************************************************************
- ** EnterInterrupt/LeaveInterrupt
- **
- ** These functions should be called when you are in an interrupt service routine
- ** or a deferred task and you want to do something that will cause ASLM
- ** code to be executed such as allocating pool memory or newing an object. The
- ** ASLM needs to know that it is at interrupt time so it doesn't do
- ** anything stupid like try to allocate memory or load library code. This doesn't
- ** mean that all ASLM calls are safe at interrupt time, just that the
- ** ones that claim to be safe will only be safe if you do an EnterInterrupt call
- ** first.
- **
- ** You don't need to use these routines when your interrupt service routine is
- ** scheduling an operation on a TInterruptScheduler, when the operation gets
- ** executed at deferred task time, or when a TTimeScheduler operation gets
- ** executed. In the former case the ASLM is smart enough to realize
- ** that you are at interrupt time and in the later two cases the
- ** ASLM does an EnterInterrupt before calling your operation and a
- ** LeaveInterrupt when your operation returns.
- *******************************************************************************}
-
- PROCEDURE EnterInterrupt; C;
- PROCEDURE LeaveInterrupt; C;
-
- {******************************************************************************
- ** AtInterruptLevel
- **
- ** This function returns true if we are currently executing at non-system-task
- ** time.
- *******************************************************************************}
-
- FUNCTION AtInterruptLevel: Boolean; C;
-
- {******************************************************************************
- ** InInterruptScheduler
- **
- ** This function returns true if we are currently running an interrupt scheduler
- *******************************************************************************}
-
- FUNCTION InInterruptScheduler: Boolean; C;
-
- {*********************************************************************
- ** GlobalWorld routines
- **
- ** InitGlobalWorld will create and initialize the global world for
- ** standalone code on the MacOS such as INITs and CDEVs. It also does
- ** a SetCurrentGlobalWorld. FreeGlobalWorld will free the memory used
- ** by the global world created by InitGlobalWorld.
- **
- ** EnterCodeResource is also used by stand alone code resources. It is
- ** most useful when the code resource only calls InitLibraryManager once
- ** but may then be reentered multiple times before calling CleanupLibraryManager.
- ** EnterCodeResoruce will set the current global world to the code resources
- ** global world and set the code resource as the current client.
- ** LeaveCodeResource will undo what EnterCodeResource does. These routines
- ** are NOT reentrant. You must call InitCodeResource before calling
- ** EnterCodeResource. It will call InitGlobalWorld and save the global world
- ** pointer in a PC-relative location so EnterCodeResource can access it.
- **
- ** SetCurrentGlobalWorld and GetCurrentGlobalWorld used for getting and
- ** setting A5 on the MacOS.
- **
- ** GetGlobalWorld is used to get the global world pointer for a Library.
- ** OpenGlobalWorld will make the library's global world the current global
- ** world. It's the same as calling SetCurrentGlobalWorld(GetGlobalWorld).
- ** CloseGlobalWorld is used to revert back to the global world that was
- ** current before calling OpenGlobalWorld. It's the same as calling
- ** SetCurrentGlobalWorld(oldWorld) except that it doesn't return a
- ** global world.
- **
- ** Since libraries are always compiled with model far, it's
- ** not necessary to do an OpenGlobalWorld before accessing globals or
- ** making intersegment calls. Their only purpose is to make the library
- ** the current "Client" since the client is determined by the current
- ** value of A5 on the MacOS.
- **
- ** ONLY LIBRARIES AND MODEL FAR CLIENTS SHOULD CALL Get/Open/CloseGlobalWorld.
- *******************************************************************************}
-
- FUNCTION SetCurrentGlobalWorld(world: GlobalWorld): GlobalWorld; INLINE
- $2F4D,$0004, { MOVE A5,4(A7) }
- $2A5F; { MOVE.A A7+,A5 }
- FUNCTION GetCurrentGlobalWorld: GlobalWorld; INLINE
- $200D; { MOVE.l A5,D0 }
-
- FUNCTION InitGlobalWorld: OSErr; C; { called by standalone code only!!! }
- PROCEDURE FreeGlobalWorld; C; { called by standalone code only!!! }
-
- FUNCTION InitCodeResource: OSErr; C; { called by standalone code only!!! }
- PROCEDURE EnterCodeResource; C; { called by standalone code only!!! }
- PROCEDURE LeaveCodeResource; C; { called by standalone code only!!! }
-
- FUNCTION GetCurrentClient: TLibraryManagerPtr; C;
- FUNCTION SetCurrentClient(libMgr : TLibraryManagerPtr): TLibraryManagerPtr; C;
- FUNCTION SetSelfAsClient: TLibraryManagerPtr; C; { set owner of code making call as current client }
- FUNCTION SetClientToWorld: TLibraryManagerPtr; C; { set owner of current global world as current }
-
-
- FUNCTION GetGlobalWorld: GlobalWorld; C;
- FUNCTION OpenGlobalWorld: GlobalWorld; C;
- PROCEDURE CloseGlobalWorld(newA5 : LONGINT); INLINE
- $2A5F; { MOVE.A A7+,A5 }
-
- {*********************************************************************
- ** TLibraryFile Pascal interface
- **
- ** The Pascal interface to the TLibraryFile class defined in
- ** LibraryManagerClasses.h. Used mainly to get resources out of a library file.
- *******************************************************************************}
-
- FUNCTION GetLocalLibraryFile: TLibraryFilePtr; C;
-
- FUNCTION GetSharedResource(libFile : TLibraryFilePtr; theType : ResType;
- theID : INTEGER; VAR err : OSErr): Ptr; C;
- FUNCTION GetSharedIndResource(libFile : TLibraryFilePtr; theType : ResType;
- index : INTEGER; VAR err : OSErr): Ptr; C;
- FUNCTION GetSharedNamedResource(libFile : TLibraryFilePtr; theType : ResType;
- name : Str255; VAR err : OSErr): Ptr; C;
-
- PROCEDURE ReleaseSharedResource(libFile : TLibraryFilePtr; resource : Ptr); C;
- FUNCTION CountSharedResources(libFile : TLibraryFilePtr; theType : ResType): LONGINT; C;
-
- FUNCTION GetSharedResourceUseCount(libFile : TLibraryFilePtr; resource : Ptr): LONGINT; C;
- FUNCTION GetSharedResourceInfo(libFile : TLibraryFilePtr; resource : Ptr;
- VAR theSize : LONGINT; VAR theID : INTEGER;
- VAR theType : ResType; VAR theName : Str255): OSErr; C;
-
- FUNCTION GetFileSpec(libFile : TLibraryFilePtr): TFileSpecPtr; C;
- FUNCTION GetRefNum(libFile : TLibraryFilePtr): LONGINT; C;
-
- FUNCTION OpenLibraryFile(libFile : TLibraryFilePtr): OSErr; C;
- FUNCTION CloseLibraryFile(libFile : TLibraryFilePtr): OSErr; C;
-
- FUNCTION Preflight(libFile : TLibraryFilePtr; VAR savedRefNum : LONGINT): OSErr; C;
- FUNCTION Postflight(libFile : TLibraryFilePtr; savedRefNum : LONGINT): OSErr; C;
-
- {**********************************************************************
- ** TClassInfo Pascal interface
- **
- ** The C interface to the TClassInfo class. Used mainly to get information
- ** about function sets. It is most useful for iterating over all function sets
- ** with a common interface. This can be done by giving the functions sets the
- ** same "parent id" when exporting each function set.
- **
- ** Note, TClassInfo can also be used to iterate over function sets and
- ** the routines given below can also be used iterate over classes.
- ***********************************************************************}
-
- FUNCTION GetFunctionSetInfo(id : TFunctionSetID; VAR err : OSErr): TFunctionSetInfoPtr; C;
- PROCEDURE FreeFunctionSetInfo(info : TFunctionSetInfoPtr); C;
-
- PROCEDURE FSInfoReset(info : TFunctionSetInfoPtr); C;
- FUNCTION FSInfoNext(info : TFunctionSetInfoPtr): TFunctionSetID; C;
- FUNCTION FSInfoIterationComplete(info : TFunctionSetInfoPtr): Boolean; C;
-
- FUNCTION FSInfoGetFunctionSetID(info : TFunctionSetInfoPtr): TFunctionSetID; C;
- FUNCTION FSInfoGetInterfaceID(info : TFunctionSetInfoPtr; idx : LONGINT): TFunctionSetID; C;
- FUNCTION FSInfoGetLibrary(info : TFunctionSetInfoPtr): TLibraryPtr; C;
- FUNCTION FSInfoGetLibraryFile(info : TFunctionSetInfoPtr): TLibraryFilePtr; C;
- FUNCTION FSInfoGetVersion(info : TFunctionSetInfoPtr): INTEGER; C;
- FUNCTION FSInfoGetMinVersion(info : TFunctionSetInfoPtr): INTEGER; C;
-
-
- {*********************************************************************
- ** TLibrary Pascal interface
- **
- ** The Pascal interface to the TLibrary class. Used mainly to manipulate
- ** code segments in a library.
- **********************************************************************}
-
- FUNCTION GetLibraryFile(lib : TLibraryPtr): TLibraryFilePtr ; C;
- FUNCTION LoadCodeSegmentByNumber(lib : TLibraryPtr; segmentNumber : INTEGER): OSErr; C;
- FUNCTION LoadCodeSegmentByRoutine(lib : TLibraryPtr; routine : ProcPtr): OSErr; C;
- FUNCTION UnloadCodeSegmentByNumber(lib : TLibraryPtr; segmentNumber : INTEGER): OSErr; C;
- FUNCTION UnloadCodeSegmentByRoutine(lib : TLibraryPtr; routine : ProcPtr): OSErr; C;
-
- {*********************************************************************
- ** Routines that will get a TLibrary object
- **********************************************************************}
-
- FUNCTION GetLocalLibrary: TLibraryPtr; C;
- FUNCTION LookupLibrary(libraryID : TLibraryID): TLibraryPtr; C;
- FUNCTION LookupLibraryWithClassID(classID : TClassID): TLibraryPtr; C;
- FUNCTION LookupLibraryWithFunctionSetID(functionSetID : TFunctionSetID): TLibraryPtr; C;
-
- {*********************************************************************
- ** Per Client data routines
- **********************************************************************}
-
- FUNCTION GetClientData: Ptr; C;
- FUNCTION GetLibraryClientData(library : TLibraryPtr): Ptr ; C;
-
- {$ENDC} { UsingLibraryManagerUtilities }
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-
-