CodeFragments.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:22k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       CodeFragments.h
  3.  
  4.      Contains:   Public Code Fragment Manager Interfaces.
  5.  
  6.      Version:    Technology: Mac OS 8.1
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1992-2001 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. /*
  18.    o
  19.    ===========================================================================================
  20.    The Code Fragment Manager API
  21.    =============================
  22. */
  23. #ifndef __CODEFRAGMENTS__
  24. #define __CODEFRAGMENTS__
  25. #ifndef __MACTYPES__
  26. #include "MacTypes.h"
  27. #endif
  28. #ifndef __FILES__
  29. #include "Files.h"
  30. #endif
  31. #if PRAGMA_ONCE
  32. #pragma once
  33. #endif
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. #if PRAGMA_IMPORT
  38. #pragma import on
  39. #endif
  40. #if PRAGMA_STRUCT_ALIGN
  41.     #pragma options align=mac68k
  42. #elif PRAGMA_STRUCT_PACKPUSH
  43.     #pragma pack(push, 2)
  44. #elif PRAGMA_STRUCT_PACK
  45.     #pragma pack(2)
  46. #endif
  47. /*
  48.    .
  49.    ===========================================================================================
  50.    General Types and Constants
  51.    ===========================
  52. */
  53. enum {
  54.     kCFragResourceType          = FOUR_CHAR_CODE('cfrg'),
  55.     kCFragResourceID            = 0,
  56.     kCFragLibraryFileType       = FOUR_CHAR_CODE('shlb'),
  57.     kCFragAllFileTypes          = (long)0xFFFFFFFF
  58. };
  59. typedef OSType                          CFragArchitecture;
  60. enum {
  61.     kPowerPCCFragArch           = FOUR_CHAR_CODE('pwpc'),
  62.     kMotorola68KCFragArch       = FOUR_CHAR_CODE('m68k'),
  63.     kAnyCFragArch               = 0x3F3F3F3F
  64. };
  65. #if TARGET_CPU_PPC
  66. enum {
  67.     kCompiledCFragArch          = kPowerPCCFragArch
  68. };
  69. #endif  /* TARGET_CPU_PPC */
  70. #if TARGET_CPU_68K
  71. enum {
  72.     kCompiledCFragArch          = kMotorola68KCFragArch
  73. };
  74. #endif  /* TARGET_CPU_68K */
  75. typedef UInt32                          CFragVersionNumber;
  76. enum {
  77.     kNullCFragVersion           = 0,
  78.     kWildcardCFragVersion       = (long)0xFFFFFFFF
  79. };
  80. typedef UInt8                           CFragUsage;
  81. enum {
  82.     kImportLibraryCFrag         = 0,                            /* Standard CFM import library.*/
  83.     kApplicationCFrag           = 1,                            /* MacOS application.*/
  84.     kDropInAdditionCFrag        = 2,                            /* Application or library private extension/plug-in*/
  85.     kStubLibraryCFrag           = 3,                            /* Import library used for linking only*/
  86.     kWeakStubLibraryCFrag       = 4                             /* Import library used for linking only and will be automatically weak linked*/
  87. };
  88. enum {
  89.     kIsCompleteCFrag            = 0,                            /* A "base" fragment, not an update.*/
  90.     kFirstCFragUpdate           = 1                             /* The first update, others are numbered 2, 3, ...*/
  91. };
  92. enum {
  93.     kCFragGoesToEOF             = 0
  94. };
  95. typedef UInt8                           CFragLocatorKind;
  96. enum {
  97.     kMemoryCFragLocator         = 0,                            /* Container is already addressable.*/
  98.     kDataForkCFragLocator       = 1,                            /* Container is in a file's data fork.*/
  99.     kResourceCFragLocator       = 2,                            /* Container is in a file's resource fork.*/
  100.     kNamedFragmentCFragLocator  = 4                             /* ! Reserved for possible future use!*/
  101. };
  102. /*
  103.    --------------------------------------------------------------------------------------
  104.    A 'cfrg' resource consists of a header followed by a sequence of variable length
  105.    members.  The constant kDefaultCFragNameLen only provides for a legal ANSI declaration
  106.    and for a reasonable display in a debugger.  The actual name field is cut to fit.
  107.    There may be "extensions" after the name, the memberSize field includes them.  The
  108.    general form of an extension is a 16 bit type code followed by a 16 bit size in bytes.
  109.    Only one standard extension type is defined at present, it is used by SOM's searching
  110.    mechanism.
  111. */
  112. union CFragUsage1Union {                                        /* ! Meaning differs depending on value of "usage".*/
  113.     UInt32                          appStackSize;               /* If the fragment is an application. (Not used by CFM!)*/
  114. };
  115. typedef union CFragUsage1Union          CFragUsage1Union;
  116. union CFragUsage2Union {                                        /* ! Meaning differs depending on value of "usage".*/
  117.     SInt16                          appSubdirID;                /* If the fragment is an application.*/
  118.     UInt16                          libFlags;                   /* If the fragment is an import library.*/
  119. };
  120. typedef union CFragUsage2Union          CFragUsage2Union;
  121. enum {
  122.                                                                 /* Bit masks for the CFragUsage2Union libFlags variant.*/
  123.     kCFragLibUsageMapPrivatelyMask = 0x0001                     /* Put container in app heap if necessary.*/
  124. };
  125. union CFragWhere1Union {                                        /* ! Meaning differs depending on value of "where".*/
  126.     UInt32                          spaceID;                    /* If the fragment is in memory.  (Actually an AddressSpaceID.)*/
  127.     OSType                          forkKind;                   /* If the fragment is in an arbitrary byte stream fork.*/
  128. };
  129. typedef union CFragWhere1Union          CFragWhere1Union;
  130. union CFragWhere2Union {                                        /* ! Meaning differs depending on value of "where".*/
  131.     UInt16                          forkInstance;               /* If the fragment is in an arbitrary byte stream fork.*/
  132. };
  133. typedef union CFragWhere2Union          CFragWhere2Union;
  134. enum {
  135.     kDefaultCFragNameLen        = 16
  136. };
  137. struct CFragResourceMember {
  138.     CFragArchitecture               architecture;
  139.     UInt16                          reservedA;                  /* ! Must be zero!*/
  140.     UInt8                           reservedB;                  /* ! Must be zero!*/
  141.     UInt8                           updateLevel;
  142.     CFragVersionNumber              currentVersion;
  143.     CFragVersionNumber              oldDefVersion;
  144.     CFragUsage1Union                uUsage1;
  145.     CFragUsage2Union                uUsage2;
  146.     CFragUsage                      usage;
  147.     CFragLocatorKind                where;
  148.     UInt32                          offset;
  149.     UInt32                          length;
  150.     CFragWhere1Union                uWhere1;
  151.     CFragWhere2Union                uWhere2;
  152.     UInt16                          extensionCount;             /* The number of extensions beyond the name.*/
  153.     UInt16                          memberSize;                 /* Size in bytes, includes all extensions.*/
  154.     unsigned char                   name[16];                   /* ! Actually a sized PString.*/
  155. };
  156. typedef struct CFragResourceMember      CFragResourceMember;
  157. typedef CFragResourceMember *           CFragResourceMemberPtr;
  158. struct CFragResourceExtensionHeader {
  159.     UInt16                          extensionKind;
  160.     UInt16                          extensionSize;
  161. };
  162. typedef struct CFragResourceExtensionHeader CFragResourceExtensionHeader;
  163. typedef CFragResourceExtensionHeader *  CFragResourceExtensionHeaderPtr;
  164. struct CFragResourceSearchExtension {
  165.     CFragResourceExtensionHeader    header;
  166.     OSType                          libKind;
  167.     unsigned char                   qualifiers[1];              /* ! Actually four PStrings.*/
  168. };
  169. typedef struct CFragResourceSearchExtension CFragResourceSearchExtension;
  170. typedef CFragResourceSearchExtension *  CFragResourceSearchExtensionPtr;
  171. enum {
  172.     kCFragResourceSearchExtensionKind = 0x30EE
  173. };
  174. struct CFragResource {
  175.     UInt32                          reservedA;                  /* ! Must be zero!*/
  176.     UInt32                          reservedB;                  /* ! Must be zero!*/
  177.     UInt16                          reservedC;                  /* ! Must be zero!*/
  178.     UInt16                          version;
  179.     UInt32                          reservedD;                  /* ! Must be zero!*/
  180.     UInt32                          reservedE;                  /* ! Must be zero!*/
  181.     UInt32                          reservedF;                  /* ! Must be zero!*/
  182.     UInt32                          reservedG;                  /* ! Must be zero!*/
  183.     UInt16                          reservedH;                  /* ! Must be zero!*/
  184.     UInt16                          memberCount;
  185.     CFragResourceMember             firstMember;
  186. };
  187. typedef struct CFragResource            CFragResource;
  188. typedef CFragResource *                 CFragResourcePtr;
  189. typedef CFragResourcePtr *              CFragResourceHandle;
  190. enum {
  191.     kCurrCFragResourceVersion   = 1
  192. };
  193. #define AlignToFour(aValue) (((aValue) + 3) & ~3)
  194. #define kBaseCFragResourceMemberSize    (offsetof ( CFragResourceMember, name ) )
  195. #define kBaseCFragResourceSize          (offsetof ( CFragResource, firstMember.name ) )
  196. #define NextCFragResourceMemberPtr(aMemberPtr)  
  197.         ((CFragResourceMemberPtr) ((BytePtr)aMemberPtr + aMemberPtr->memberSize))
  198. #define FirstCFragResourceExtensionPtr(aMemberPtr)                                          
  199.         ((CFragResourceExtensionHeaderPtr) ((BytePtr)aMemberPtr +                           
  200.                                             AlignToFour ( kBaseCFragResourceMemberSize +    
  201.                                                           aMemberPtr->name[0] + 1 ) ))
  202. #define NextCFragResourceExtensionPtr(anExtensionPtr)                   
  203.         ((CFragResourceExtensionHeaderPtr) ((BytePtr)anExtensionPtr +   
  204.                                             ((CFragResourceExtensionHeaderPtr)anExtensionPtr)->extensionSize ))
  205. #define FirstCFragResourceSearchQualifier(searchExtensionPtr)                   
  206.         ((StringPtr) ((BytePtr)searchExtensionPtr +                             
  207.                       offsetof ( CFragResourceSearchExtension, qualifiers ) ))
  208. #define NextCFragResourceSearchQualifier(searchQualifierPtr)    
  209.         ((StringPtr) ((BytePtr)searchQualifierPtr + searchQualifierPtr[0] + 1))
  210. typedef struct OpaqueCFragConnectionID*  CFragConnectionID;
  211. typedef struct OpaqueCFragClosureID*    CFragClosureID;
  212. typedef struct OpaqueCFragContainerID*  CFragContainerID;
  213. typedef struct OpaqueCFragContextID*    CFragContextID;
  214. typedef UInt32                          CFragLoadOptions;
  215. enum {
  216.     kReferenceCFrag             = 0x0001,                       /* Try to use existing copy, increment reference counts.*/
  217.     kFindCFrag                  = 0x0002,                       /* Try find an existing copy, do not increment reference counts.*/
  218.     kPrivateCFragCopy           = 0x0005                        /* Prepare a new private copy.  (kReferenceCFrag | 0x0004)*/
  219. };
  220. enum {
  221.     kUnresolvedCFragSymbolAddress = 0
  222. };
  223. typedef UInt8                           CFragSymbolClass;
  224. enum {
  225.     kCodeCFragSymbol            = 0,
  226.     kDataCFragSymbol            = 1,
  227.     kTVectorCFragSymbol         = 2,
  228.     kTOCCFragSymbol             = 3,
  229.     kGlueCFragSymbol            = 4
  230. };
  231. /*
  232.    .
  233.    ===========================================================================================
  234.    Macros and Functions
  235.    ====================
  236. */
  237. #define CFragHasFileLocation(where) 
  238.         ( ((where) == kDataForkCFragLocator) || ((where) == kResourceCFragLocator) )
  239. EXTERN_API( OSErr )
  240. GetSharedLibrary                (ConstStr63Param        libName,
  241.                                  CFragArchitecture      archType,
  242.                                  CFragLoadOptions       loadFlags,
  243.                                  CFragConnectionID *    connID, /* can be NULL */
  244.                                  Ptr *                  mainAddr, /* can be NULL */
  245.                                  Str255                 errMessage) /* can be NULL */       THREEWORDINLINE(0x3F3C, 0x0001, 0xAA5A);
  246. EXTERN_API( OSErr )
  247. GetDiskFragment                 (const FSSpec *         fileSpec,
  248.                                  UInt32                 offset,
  249.                                  UInt32                 length,
  250.                                  ConstStr63Param        fragName, /* can be NULL */
  251.                                  CFragLoadOptions       loadFlags,
  252.                                  CFragConnectionID *    connID, /* can be NULL */
  253.                                  Ptr *                  mainAddr, /* can be NULL */
  254.                                  Str255                 errMessage) /* can be NULL */       THREEWORDINLINE(0x3F3C, 0x0002, 0xAA5A);
  255. EXTERN_API( OSErr )
  256. GetMemFragment                  (void *                 memAddr,
  257.                                  UInt32                 length,
  258.                                  ConstStr63Param        fragName, /* can be NULL */
  259.                                  CFragLoadOptions       loadFlags,
  260.                                  CFragConnectionID *    connID, /* can be NULL */
  261.                                  Ptr *                  mainAddr, /* can be NULL */
  262.                                  Str255                 errMessage) /* can be NULL */       THREEWORDINLINE(0x3F3C, 0x0003, 0xAA5A);
  263. EXTERN_API( OSErr )
  264. CloseConnection                 (CFragConnectionID *    connID)                             THREEWORDINLINE(0x3F3C, 0x0004, 0xAA5A);
  265. EXTERN_API( OSErr )
  266. FindSymbol                      (CFragConnectionID      connID,
  267.                                  ConstStr255Param       symName,
  268.                                  Ptr *                  symAddr, /* can be NULL */
  269.                                  CFragSymbolClass *     symClass) /* can be NULL */         THREEWORDINLINE(0x3F3C, 0x0005, 0xAA5A);
  270. EXTERN_API( OSErr )
  271. CountSymbols                    (CFragConnectionID      connID,
  272.                                  long *                 symCount)                           THREEWORDINLINE(0x3F3C, 0x0006, 0xAA5A);
  273. EXTERN_API( OSErr )
  274. GetIndSymbol                    (CFragConnectionID      connID,
  275.                                  long                   symIndex,
  276.                                  Str255                 symName, /* can be NULL */
  277.                                  Ptr *                  symAddr, /* can be NULL */
  278.                                  CFragSymbolClass *     symClass) /* can be NULL */         THREEWORDINLINE(0x3F3C, 0x0007, 0xAA5A);
  279. /*
  280.    .
  281.    ===========================================================================================
  282.    Initialization & Termination Routines
  283.    =====================================
  284. */
  285. /*
  286.    -----------------------------------------------------------------------------------------
  287.    A fragment's initialization and termination routines are called when a new incarnation of
  288.    the fragment is created or destroyed, respectively.  Exactly when this occurs depends on
  289.    what kinds of section sharing the fragment has and how the fragment is prepared.  Import
  290.    libraries have at most one incarnation per process.  Fragments prepared with option
  291.    kPrivateCFragCopy may have many incarnations per process.
  292.    The initialization function is passed a pointer to an initialization information structure
  293.    and returns an OSErr.  If an initialization function returns a non-zero value the entire
  294.    closure of which it is a part fails.  The C prototype for an initialization function is:
  295.         OSErr   CFragInitFunction   ( const CFragInitBlock *    initBlock );
  296.    The termination procedure takes no parameters and returns nothing.  The C prototype for a
  297.    termination procedure is:
  298.         void    CFragTermProcedure  ( void );
  299.    Note that since the initialization and termination routines are themselves "CFM"-style
  300.    routines whether or not they have the "pascal" keyword is irrelevant.
  301. */
  302. /*
  303.    -----------------------------------------------------------------------------------------
  304.    ! Note:
  305.    ! The "System7" portion of these type names was introduced during the evolution towards
  306.    ! the now defunct Copland version of Mac OS.  Copland was to be called System 8 and there
  307.    ! were slightly different types for System 7 and System 8.  The "generic" type names were
  308.    ! conditionally defined for the desired target system.
  309.    ! Always use the generic types, e.g. CFragInitBlock!  The "System7" names have been kept
  310.    ! only to avoid perturbing code that (improperly) used the target specific type.
  311. */
  312. struct CFragSystem7MemoryLocator {
  313.     LogicalAddress                  address;
  314.     UInt32                          length;
  315.     Boolean                         inPlace;
  316.     UInt8                           reservedA;                  /* ! Must be zero!*/
  317.     UInt16                          reservedB;                  /* ! Must be zero!*/
  318. };
  319. typedef struct CFragSystem7MemoryLocator CFragSystem7MemoryLocator;
  320. struct CFragSystem7DiskFlatLocator {
  321.     FSSpecPtr                       fileSpec;
  322.     UInt32                          offset;
  323.     UInt32                          length;
  324. };
  325. typedef struct CFragSystem7DiskFlatLocator CFragSystem7DiskFlatLocator;
  326. /* ! This must have a file specification at the same offset as a disk flat locator!*/
  327. struct CFragSystem7SegmentedLocator {
  328.     FSSpecPtr                       fileSpec;
  329.     OSType                          rsrcType;
  330.     SInt16                          rsrcID;
  331.     UInt16                          reservedA;                  /* ! Must be zero!*/
  332. };
  333. typedef struct CFragSystem7SegmentedLocator CFragSystem7SegmentedLocator;
  334. struct CFragSystem7Locator {
  335.     SInt32                          where;
  336.     union {
  337.         CFragSystem7DiskFlatLocator     onDisk;
  338.         CFragSystem7MemoryLocator       inMem;
  339.         CFragSystem7SegmentedLocator    inSegs;
  340.     }                                 u;
  341. };
  342. typedef struct CFragSystem7Locator      CFragSystem7Locator;
  343. typedef CFragSystem7Locator *           CFragSystem7LocatorPtr;
  344. struct CFragSystem7InitBlock {
  345.     CFragContextID                  contextID;
  346.     CFragClosureID                  closureID;
  347.     CFragConnectionID               connectionID;
  348.     CFragSystem7Locator             fragLocator;
  349.     StringPtr                       libName;
  350.     UInt32                          reservedA;                  /* ! Must be zero!*/
  351. };
  352. typedef struct CFragSystem7InitBlock    CFragSystem7InitBlock;
  353. typedef CFragSystem7InitBlock *         CFragSystem7InitBlockPtr;
  354. typedef CFragSystem7InitBlock           CFragInitBlock;
  355. typedef CFragSystem7InitBlockPtr        CFragInitBlockPtr;
  356. /* These init/term routine types are only of value to CFM itself.*/
  357. typedef CALLBACK_API_C( OSErr , CFragInitFunction )(const CFragInitBlock *initBlock);
  358. typedef CALLBACK_API_C( void , CFragTermProcedure )(void );
  359. /*
  360.    .
  361.    ===========================================================================================
  362.    Old Name Spellings
  363.    ==================
  364. */
  365. /*
  366.    -------------------------------------------------------------------------------------------
  367.    We've tried to reduce the risk of name collisions in the future by introducing the phrase
  368.    "CFrag" into constant and type names.  The old names are defined below in terms of the new.
  369. */
  370. enum {
  371.     kLoadCFrag                  = kReferenceCFrag
  372. };
  373. #if OLDROUTINENAMES
  374. #define IsFileLocation      CFragHasFileLocation
  375. typedef CFragConnectionID               ConnectionID;
  376. typedef CFragLoadOptions                LoadFlags;
  377. typedef CFragSymbolClass                SymClass;
  378. typedef CFragInitBlock                  InitBlock;
  379. typedef CFragInitBlockPtr               InitBlockPtr;
  380. typedef CFragSystem7MemoryLocator       MemFragment;
  381. typedef CFragSystem7DiskFlatLocator     DiskFragment;
  382. typedef CFragSystem7SegmentedLocator    SegmentedFragment;
  383. typedef CFragSystem7Locator             FragmentLocator;
  384. typedef CFragSystem7LocatorPtr          FragmentLocatorPtr;
  385. typedef CFragSystem7MemoryLocator       CFragHFSMemoryLocator;
  386. typedef CFragSystem7DiskFlatLocator     CFragHFSDiskFlatLocator;
  387. typedef CFragSystem7SegmentedLocator    CFragHFSSegmentedLocator;
  388. typedef CFragSystem7Locator             CFragHFSLocator;
  389. typedef CFragSystem7LocatorPtr          CFragHFSLocatorPtr;
  390. enum {
  391.     kPowerPCArch                = kPowerPCCFragArch,
  392.     kMotorola68KArch            = kMotorola68KCFragArch,
  393.     kAnyArchType                = kAnyCFragArch,
  394.     kNoLibName                  = 0,
  395.     kNoConnectionID             = 0,
  396.     kLoadLib                    = kLoadCFrag,
  397.     kFindLib                    = kFindCFrag,
  398.     kNewCFragCopy               = kPrivateCFragCopy,
  399.     kLoadNewCopy                = kPrivateCFragCopy,
  400.     kUseInPlace                 = 0x80,
  401.     kCodeSym                    = kCodeCFragSymbol,
  402.     kDataSym                    = kDataCFragSymbol,
  403.     kTVectSym                   = kTVectorCFragSymbol,
  404.     kTOCSym                     = kTOCCFragSymbol,
  405.     kGlueSym                    = kGlueCFragSymbol,
  406.     kInMem                      = kMemoryCFragLocator,
  407.     kOnDiskFlat                 = kDataForkCFragLocator,
  408.     kOnDiskSegmented            = kResourceCFragLocator,
  409.     kIsLib                      = kImportLibraryCFrag,
  410.     kIsApp                      = kApplicationCFrag,
  411.     kIsDropIn                   = kDropInAdditionCFrag,
  412.     kFullLib                    = kIsCompleteCFrag,
  413.     kUpdateLib                  = kFirstCFragUpdate,
  414.     kWholeFork                  = kCFragGoesToEOF,
  415.     kCFMRsrcType                = kCFragResourceType,
  416.     kCFMRsrcID                  = kCFragResourceID,
  417.     kSHLBFileType               = kCFragLibraryFileType,
  418.     kUnresolvedSymbolAddress    = kUnresolvedCFragSymbolAddress
  419. };
  420. enum {
  421.     kPowerPC                    = kPowerPCCFragArch,
  422.     kMotorola68K                = kMotorola68KCFragArch
  423. };
  424. #endif  /* OLDROUTINENAMES */
  425. #if PRAGMA_STRUCT_ALIGN
  426.     #pragma options align=reset
  427. #elif PRAGMA_STRUCT_PACKPUSH
  428.     #pragma pack(pop)
  429. #elif PRAGMA_STRUCT_PACK
  430.     #pragma pack()
  431. #endif
  432. #ifdef PRAGMA_IMPORT_OFF
  433. #pragma import off
  434. #elif PRAGMA_IMPORT
  435. #pragma import reset
  436. #endif
  437. #ifdef __cplusplus
  438. }
  439. #endif
  440. #endif /* __CODEFRAGMENTS__ */