home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dtswps.zip / DTSFILES.ZIP / SOMAPI.H < prev    next >
C/C++ Source or Header  |  1996-06-24  |  36KB  |  856 lines

  1. /*
  2.  *   COMPONENT_NAME: somk
  3.  *
  4.  *   ORIGINS: 27
  5.  *
  6.  *
  7.  *    25H7912  (C)  COPYRIGHT International Business Machines Corp. 1992,1994,1996
  8.  *   All Rights Reserved
  9.  *   Licensed Materials - Property of IBM
  10.  *   US Government Users Restricted Rights - Use, duplication or
  11.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  12.  */
  13.  
  14. /* @(#) 2.44.2.7 src/somk/somapi.h, somk.api, som2.1 2/29/96 10:19:03 [6/24/96 08:12:03] */
  15.  
  16. /*
  17.  *    SOMAPI.H
  18.  *
  19.  *    Note: Typedefs, function prototypes, and structure fields declared here
  20.  *    explicitly use a star (*) to indicate references to objects that support
  21.  *    IDL interfaces. For example, the first argument in the following
  22.  *    function prototype is typed as pointer to an object that supports the
  23.  *    SOMObject interface:
  24.  *
  25.  *    somMethodProc * SOMLINK somResolve(SOMObject *obj, somMToken mdata)
  26.  *
  27.  *    These types reflect the actual implementation of object references
  28.  *    in SOM as pointers. The CORBA compliant C language bindings are
  29.  *    designed so that programmers don't explicitly indicate pointers when
  30.  *    declaring object reference types, but this header is included into
  31.  *    the CORBA compliant C language binding files before this capability
  32.  *    has been enabled. Thus, at this point in the processing of header files
  33.  *    by a C compiler, it is appropriate that the explicit star appear in
  34.  *    object reference types. You can view the header file som.h to see how
  35.  *    the ability to omit the explicit star is enabled after this header is
  36.  *    processed, but, in any case, you can be assured that the typedefs,
  37.  *    function prototypes, and structure fields declared here all "work"
  38.  *    with the CORBA compliant C language bindings.
  39.  */
  40.  
  41. #ifndef somapi_h
  42. #define somapi_h
  43.  
  44. /*  SOM Version Numbers  */
  45. SOMEXTERN long SOMDLINK SOM_MajorVersion;
  46. SOMEXTERN long SOMDLINK SOM_MinorVersion;
  47.  
  48. /*  SOM Thread Support  */
  49. SOMEXTERN long SOMDLINK SOM_MaxThreads;
  50.  
  51. /*----------------------------------------------------------------------
  52.  *  Typedefs for pointers to functions
  53.  */
  54.  
  55. typedef void    SOMLINK somTD_classInitRoutine(SOMClass *, SOMClass *);
  56. typedef int     SOMLINK somTD_SOMOutCharRoutine(char);
  57. typedef int     SOMLINK somTD_SOMLoadModule(IN string /* className */,
  58.                                         IN string     /* fileName */,
  59.                                         IN string     /* functionName */,
  60.                                         IN long    /* majorVersion */,
  61.                                         IN long    /* minorVersion */,
  62.                                         OUT somToken * /* modHandle */);
  63. typedef int     SOMLINK somTD_SOMDeleteModule(IN somToken /* modHandle */);
  64. typedef string SOMLINK somTD_SOMClassInitFuncName(void);
  65. typedef somToken        SOMLINK somTD_SOMMalloc(IN size_t /* nbytes */);
  66. typedef somToken        SOMLINK somTD_SOMCalloc(IN size_t /* element_count */,
  67.                                         IN size_t /* element_size */);
  68. typedef somToken        SOMLINK somTD_SOMRealloc(IN somToken /* memory */,
  69.                                          IN size_t /* nbytes */);
  70. typedef void    SOMLINK somTD_SOMFree(IN somToken /* memory */);
  71. typedef void    SOMLINK somTD_SOMError(IN int      /* code */,
  72.                                        IN string  /* fileName */,
  73.                                        IN int      /* lineNum */);
  74. typedef unsigned long SOMLINK somTD_SOMCreateMutexSem (OUT somToken *sem);
  75. typedef unsigned long SOMLINK somTD_SOMRequestMutexSem (IN somToken sem);
  76. typedef unsigned long SOMLINK somTD_SOMReleaseMutexSem (IN somToken sem);
  77. typedef unsigned long SOMLINK somTD_SOMDestroyMutexSem (IN somToken sem);
  78. typedef unsigned long SOMLINK somTD_SOMGetThreadId (void);
  79.  
  80. /*----------------------------------------------------------------------
  81.  *  Windows extra procedures:
  82.  */
  83.  
  84. SOMEXTERN void SOMLINK somSetOutChar(somTD_SOMOutCharRoutine *outch);
  85. SOMEXTERN SOMClassMgr * SOMLINK somMainProgram (void);
  86. SOMEXTERN void SOMLINK somEnvironmentEnd (void);
  87. SOMEXTERN boolean SOMLINK somAbnormalEnd (void);
  88.  
  89. /*--------------------------------------------------------*/
  90.  
  91.  
  92. #ifndef SOM_MDT_DEFINED
  93. /* -- Method/Data Tokens -- For locating methods and data members. */
  94. typedef somToken somMToken;
  95. typedef somToken somDToken;
  96. #endif
  97.  
  98. /*----------------------------------------------------------------------
  99.  *  The Method Table Structure
  100.  */
  101.  
  102. #ifndef SOM_MTAB_DEFINED
  103. /* -- to specify an embedded object (or array of objects). */
  104. typedef struct {
  105.     SOMClass     **copp; /* address of class of object ptr */
  106.     long         cnt;    /* object count */
  107.     long         offset; /* Offset to pointer (to embedded objs) */
  108. } somEmbeddedObjStruct;
  109.  
  110. #ifndef SOM_CLASSINFO_DEFINED
  111. typedef somToken somClassInfo;
  112. #endif
  113.  
  114. typedef struct somMethodTabStruct {
  115.     SOMClass        *classObject;
  116.     somClassInfo    *classInfo;
  117.     char            *className;
  118.     long            instanceSize;
  119.     long            dataAlignment;
  120.     long            mtabSize;
  121.     long            protectedDataOffset; /* from class's introduced data */
  122.     somDToken       protectedDataToken;
  123.     somEmbeddedObjStruct *embeddedObjs;
  124.     /* remaining structure is opaque */
  125.     somMethodProc* entries[1];
  126. } somMethodTab, *somMethodTabPtr;
  127. #endif
  128.  
  129.  
  130. /* -- For building lists of method tables */
  131. typedef
  132.     struct somMethodTabList {
  133.         somMethodTab             *mtab;
  134.         struct somMethodTabList  *next;
  135.     } somMethodTabList, *somMethodTabs;
  136.  
  137.  
  138. /* -- For building lists of class objects */
  139. typedef
  140.     struct somClassList {
  141.         SOMClass   *cls;
  142.         struct somClassList *next;
  143.     } somClassList, *somClasses;
  144.  
  145. /* -- For building lists of objects */
  146. typedef struct somObjectList {
  147.     SOMObject   *obj;
  148.     struct somObjectList *next;
  149. } somObjectList, *somObjects;
  150.  
  151. /*---------------------------------------------------------------------
  152.  * C++-style constructors are called initializers in SOM. Initializers
  153.  * are methods that receive a pointer to a somCtrlStruct as an argument.
  154.  */
  155.  
  156. typedef  struct  {
  157.     SOMClass      *cls;  /* the class whose introduced data is to be initialized */
  158.     somMethodProc *defaultInit;
  159.     somMethodProc *defaultCopyInit;
  160.     somMethodProc *defaultConstCopyInit;
  161.     somMethodProc *defaultNCArgCopyInit;
  162.     long          dataOffset;
  163.     somMethodProc *legacyInit;
  164. } somInitInfo;
  165.  
  166. typedef struct {
  167.     SOMClass      *cls;  /* the class whose introduced data is to be destroyed */
  168.     somMethodProc *defaultDestruct;
  169.     long          dataOffset;
  170.     somMethodProc *legacyUninit;
  171. } somDestructInfo;
  172.  
  173. typedef struct {
  174.     SOMClass      *cls;  /* the class whose introduced data is to be assigned */
  175.     somMethodProc *defaultAssign;
  176.     somMethodProc *defaultConstAssign;
  177.     somMethodProc *defaultNCArgAssign;
  178.     somMethodProc *udaAssign;
  179.     somMethodProc *udaConstAssign;
  180.     long          dataOffset;
  181. } somAssignInfo;
  182.  
  183. typedef octet *somBooleanVector;
  184. #ifndef SOM_CTI_DEFINED
  185. typedef somToken somCtrlInfo;
  186. #endif
  187.  
  188. typedef struct somInitCtrlStruct {
  189.     somBooleanVector mask; /* an array of booleans to control ancestor calls */
  190.     somInitInfo     *info; /* an array of structs */
  191.     int              infoSize; /* increment for info access */
  192.     somCtrlInfo      ctrlInfo;
  193. } somInitCtrl,som3InitCtrl;
  194.  
  195. typedef struct somDestructCtrlStruct {
  196.     somBooleanVector  mask; /* an array of booleans to control ancestor calls */
  197.     somDestructInfo  *info; /* an array of structs */
  198.     int               infoSize; /* increment for info access */
  199.     somCtrlInfo       ctrlInfo;
  200. } somDestructCtrl,som3DestructCtrl;
  201.  
  202. typedef struct somAssignCtrlStruct {
  203.     somBooleanVector  mask; /* an array of booleans to control ancestor calls */
  204.     somAssignInfo    *info; /* an array of structs */
  205.     int               infoSize; /* increment for info access */
  206.     somCtrlInfo       ctrlInfo;
  207. } somAssignCtrl,som3AssignCtrl;
  208.  
  209.  
  210.  
  211.  
  212. /*----------------------------------------------------------------------
  213.  *  The Class Data Structures -- these are used to implement static
  214.  *  method and data interfaces to SOM objects.
  215.  */
  216.  
  217. /* -- (Generic) Class data Structure */
  218. typedef struct {
  219.     SOMClass *classObject; /* changed by shadowing */
  220.     somToken tokens[1];    /* method tokens, etc. */
  221. } somClassDataStructure, *somClassDataStructurePtr;
  222.  
  223. /*
  224.  * A special info access structure pointed to by
  225.  * the parentMtab entry of somCClassDataStructure.
  226.  */
  227. typedef void somTP_somRenewNoInitNoZeroThunk(void*);
  228. #if (defined(__IBMC__) && !defined(__cplusplus))
  229. #pragma linkage(somTP_somRenewNoInitNoZeroThunk, system)
  230. #endif
  231. typedef somTP_somRenewNoInitNoZeroThunk *somTD_somRenewNoInitNoZeroThunk;
  232.  
  233. typedef struct {
  234.     somMethodTab    *mtab; /* this class' mtab -- changed by shadowing */
  235.     somMethodTabs   next; /* the parent mtabs -- unchanged by shadowing */
  236.     SOMClass        *classObject; /* unchanged by shadowing */
  237.     somTD_somRenewNoInitNoZeroThunk somRenewNoInitNoZeroThunk; /* changed by shadowing */
  238.     long            instanceSize; /* changed by shadowing */
  239.     somMethodProc   **initializers; /* resolved initializer array in releaseorder */
  240.     somMethodProc   **resolvedMTokens;  /* resolved methods */
  241.     somInitCtrl     initCtrl; /* these fields are filled in if somDTSClass&2 is on */
  242.     somDestructCtrl destructCtrl;
  243.     somAssignCtrl   assignCtrl;
  244.     long            embeddedTotalCount;
  245.     long            hierarchyTotalCount;
  246.     long            unused;
  247. } somParentMtabStruct, *somParentMtabStructPtr;
  248.  
  249. /*
  250.  * (Generic) Auxiliary Class Data Structure
  251.  */
  252. typedef struct {
  253.     somParentMtabStructPtr parentMtab;
  254.     somDToken              instanceDataToken;
  255.     somMethodProc          *wrappers[1]; /* for valist methods */
  256. } somCClassDataStructure, *somCClassDataStructurePtr;
  257.  
  258.  
  259. /*---------------------------------------------------------------------
  260.  *  Offset-based method resolution.
  261.  */
  262.  
  263. SOMEXTERN somMethodProc * SOMLINK somResolve(SOMObject *obj, somMToken mdata);
  264. SOMEXTERN somMethodProc * SOMLINK somParentResolve(somMethodTabs parentMtabs,
  265.                                          somMToken mToken);
  266. SOMEXTERN somMethodProc * SOMLINK somParentNumResolve(somMethodTabs parentMtabs,
  267.                                          int parentNum,
  268.                                          somMToken mToken);
  269. SOMEXTERN somMethodProc * SOMLINK somClassResolve(SOMClass *, somMToken mdata);
  270. SOMEXTERN somMethodProc * SOMLINK somResolveTerminal(SOMClass *, somMToken mdata);
  271. SOMEXTERN somMethodProc * SOMLINK somPCallResolve(SOMObject *obj,
  272.                                                   SOMClass *callingCls,
  273.                                                   somMToken method);
  274. SOMEXTERN somMethodProc * SOMLINK somAncestorResolve(SOMObject *obj, /* the object */
  275.                                            somCClassDataStructure *ccds, /* id the ancestor */
  276.                                            somMToken mToken);
  277. SOMEXTERN somMethodProc * SOMLINK somResolveByName(SOMObject *obj,
  278.                                                    char *methodName);
  279. /*------------------------------------------------------------------------------
  280.  * Offset-based data resolution
  281.  */
  282. SOMEXTERN somToken SOMLINK somDataResolve(SOMObject *obj, somDToken dataId);
  283. SOMEXTERN somToken SOMLINK somDataResolveChk(SOMObject *obj, somDToken dataId);
  284.  
  285.  
  286. /*----------------------------------------------------------------------
  287.  *  Misc. procedures:
  288.  */
  289.  
  290. /*
  291.  *  Create and initialize the SOM environment
  292.  *
  293.  *  Can be called repeatedly
  294.  *
  295.  *  Will be called automatically when first object (including a class
  296.  *  object) is created, if it has not already been done.
  297.  *
  298.  *  Returns the SOMClassMgrObject
  299.  */
  300. SOMEXTERN SOMClassMgr * SOMLINK somEnvironmentNew (void);
  301.  
  302.  
  303. /*
  304.  * Test whether <obj> is a valid SOM object. This test is based solely on
  305.  * the fact that (on this architecture) the first word of a SOM object is a
  306.  * pointer to its method table. The test is therefore most correctly understood
  307.  * as returning true if and only if <obj> is a pointer to a pointer to a
  308.  * valid SOM method table. If so, then methods can be invoked on <obj>.
  309.  */
  310. SOMEXTERN boolean SOMLINK somIsObj(somToken obj);
  311.  
  312. /*
  313.  * Return the class that introduced the method represented by a given method token.
  314.  */
  315. SOMEXTERN SOMClass* SOMLINK somGetClassFromMToken(somMToken mToken);
  316.  
  317.  
  318. /*----------------------------------------------------------------------
  319.  *  String Manager: stem <somsm>
  320.  */
  321. SOMEXTERN somId SOMLINK somCheckId (somId id);
  322. /* makes sure that the id is registered and in normal form, returns */
  323. /* the id */
  324.  
  325. SOMEXTERN int SOMLINK somRegisterId(somId id);
  326. /* Same as somCheckId except returns 1 (true) if this is the first */
  327. /* time the string associated with this id has been registered, */
  328. /* returns 0 (false) otherwise */
  329.  
  330. SOMEXTERN somId SOMLINK somIdFromString (string aString);
  331. /* caller is responsible for freeing the returned id with SOMFree */
  332.  
  333. SOMEXTERN string SOMLINK somStringFromId (somId id);
  334.  
  335. SOMEXTERN int SOMLINK somCompareIds(somId id1, somId id2);
  336. /* returns true (1) if the two ids are equal, else false (0) */
  337.  
  338. SOMEXTERN unsigned long SOMLINK somTotalRegIds(void);
  339. /* Returns the total number of ids that have been registered so far, */
  340. /* you can use this to advise the SOM runtime concerning expected */
  341. /* number of ids in later executions of your program, via a call to */
  342. /* somSetExpectedIds defined below */
  343.  
  344. SOMEXTERN void SOMLINK somSetExpectedIds(unsigned long numIds);
  345. /* Tells the SOM runtime how many unique ids you expect to use during */
  346. /* the execution of your program, this can improve space and time */
  347. /* utilization slightly, this routine must be called before the SOM */
  348. /* environment is created to have any effect */
  349.  
  350. SOMEXTERN unsigned long SOMLINK somUniqueKey(somId id);
  351. /* Returns the unique key for this id, this key will be the same as the */
  352. /* key in another id if and only if the other id refers to the same */
  353. /* name as this one */
  354.  
  355. SOMEXTERN void SOMLINK somBeginPersistentIds(void);
  356. /* Tells the id manager that strings for any new ids that are */
  357. /* registered will never be freed or otherwise modified. This allows */
  358. /* the id manager to just use a pointer to the string in the */
  359. /* unregistered id as the master copy of the ids string. Thus saving */
  360. /* space */
  361. /* Under normal use (where ids are static varibles) the string */
  362. /* associated with an id would only be freed if the code module in */
  363. /* which it occured was unloaded */
  364.  
  365. SOMEXTERN void SOMLINK somEndPersistentIds(void);
  366. /* Tells the id manager that strings for any new ids that are */
  367. /* registered may be freed or otherwise modified.  Therefore the id */
  368. /* manager must copy the strings inorder to remember the name of an */
  369. /* id. */
  370.  
  371. /*----------------------------------------------------------------------
  372.  *  Class Manager: SOMClassMgr, stem <somcm>
  373.  */
  374.  
  375. /* Global class manager object */
  376. SOMEXTERN SOMClassMgr * SOMDLINK SOMClassMgrObject;
  377.  
  378. /* The somRegisterClassLibrary function is provided for use
  379.  * in SOM class libraries on platforms that have loader-invoked
  380.  * entry points associated with shared libraries (DLLs).
  381.  *
  382.  * This function registers a SOM Class Library with the SOM Kernel.
  383.  * The library is identified by its file name and a pointer
  384.  * to its initialization routine.  Since this call may occur
  385.  * prior to the invocation of somEnvironmentNew, its actions
  386.  * are deferred until the SOM environment has been initialized.
  387.  * At that time, the SOMClassMgrObject is informed of all
  388.  * pending library initializations via the _somRegisterClassLibrary
  389.  * method.  The actual invocation of the library's initialization
  390.  * routine will occur during the execution of the SOM_MainProgram
  391.  * macro (for statically linked libraries), or during the _somFindClass
  392.  * method (for libraries that are dynamically loaded).
  393.  */
  394. SOMEXTERN void SOMLINK somRegisterClassLibrary (string libraryName,
  395.     somMethodProc *libraryInitRtn);
  396. SOMEXTERN void SOMLINK somUnregisterClassLibrary (string libraryName);
  397.  
  398. /*----------------------------------------------------------------------
  399.  * Method Stubs -- Signature Support
  400.  *
  401.  *
  402.  * This section defines the structures used to pass method signature
  403.  * ingo to the runtime. This supports selection of generic apply stubs
  404.  * and runtime generation of redispatchstubs when these are needed. The
  405.  * information is registered with the runtime when methods are defined.
  406.  *
  407.  * When calling somAddStaticMethod, if the redispatchStub is -1, then a
  408.  * pointer to a struct of type somApRdInfo is passed as the applyStub.
  409.  * Otherwise, the passed redispatchstub and applystub are taken as given.
  410.  * When calling somAddDynamicMethod, an actual apply stub must be passed.
  411.  * Redispatch stubs for dynamic methods are not available, nor is
  412.  * automated support for dynamic method apply stubs. The following
  413.  * atructures only appropriate in relation to static methods.
  414.  *
  415.  * In SOMr2, somAddStaticMethod can be called with an actual redispatchstub
  416.  * and applystub *ONLY* if the method doesn't return a structure. Recall
  417.  * that no SOMr1 methods returned structures, so SOMr1 binaries obey this
  418.  * restriction. The reason for this rule is that SOMr2 *may* use thunks,
  419.  * and thunks need to know if a structure is returned. We therefore assume
  420.  * that if no signature information is provided for a method through the
  421.  * somAddStaticMethod interface, then the method returns a scalar.
  422.  *
  423.  * If a structure is returned, then a -1 *must* be passed to
  424.  * somAddStaticMethod as a redispatchstub. In any case, if a -1 is passed,
  425.  * then this means that the applystub actually points to a structure of type
  426.  * somApRdInfo. This structure is used to hold and access signature
  427.  * information encoded as follows.
  428.  *
  429.  * If the somApRdInfo pointer is NULL, then, if the runtime was built with
  430.  * SOM_METHOD_STUBS defined, a default signature is assumed (no arguments,
  431.  * and no structure returned); otherwise, the stubs are taken as
  432.  * somDefaultMethod (which produces a runtime error when used) if dynamic
  433.  * stubs are not available.
  434.  *
  435.  * If the somApRdInfo pointer is not NULL, then the structure it points to can
  436.  * either include (non-null) redispatch and applystubs (the method is then
  437.  * assumed to return a structure), or null stubs followed by information needed
  438.  * to generate necessary stubs dynamically.
  439.  */
  440.  
  441. typedef unsigned long somRdAppType; /* method signature code -- see def below */
  442. typedef unsigned long somFloatMap[13]; /* float map -- see def below */
  443. typedef struct somMethodInfoStruct {
  444.     somRdAppType       callType;
  445.     long               va_listSize;
  446.     somFloatMap        *float_map;
  447. } somMethodInfo;
  448.  
  449. typedef struct somApRdInfoStruct {
  450.     somMethodProc *rdStub;
  451.     somMethodProc *apStub;
  452.     somMethodInfo *stubInfo;
  453. } somApRdInfo;
  454.  
  455. /*
  456.  * Values for somRdAppType are generated by summing one from column A and one
  457.  * from column B of the following constants:
  458.  */
  459. /* Column A: return type */
  460. #define SOMRdRetsimple     0 /* Return type is a non-float fullword */
  461. #define SOMRdRetfloat      2 /* Return type is (single) float */
  462. #define SOMRdRetdouble     4 /* Return type is double */
  463. #define SOMRdRetlongdouble 6 /* Return type is long double */
  464. #define SOMRdRetaggregate  8 /* Return type is struct or union */
  465. #define SOMRdRetbyte      10 /* Return type is a byte */
  466. #define SOMRdRethalf      12 /* Return type is a (2 byte) halfword */
  467. /* Column B: are there any floating point scalar arguments? */
  468. #define SOMRdNoFloatArgs   0
  469. #define SOMRdFloatArgs     1
  470.  
  471. /* A somFloatMap is only needed on RS/6000 */
  472. /*
  473.  * This is an array of offsets for up to the first 13 floating point arguments.
  474.  * If there are fewer than 13 floating point arguments, then there will be
  475.  * zero entries following the non-zero entries which represent the float args.
  476.  * A non-zero entry signals either a single- or a double-precision floating point
  477.  * argument. For a double-precision argument, the entry is the stack
  478.  * frame offset. For a single-precision argument the entry is the stack
  479.  * frame offset + 1. For the final floating point argument, add 2 to the
  480.  * code that would otherwise be used.
  481.  */
  482. #define SOMFMSingle 1        /* add to indicate single-precision */
  483. #define SOMFMLast   2        /* add to indicate last floating point arg */
  484.  
  485.  
  486. /*----------------------------------------------------------------------
  487.  * -- somApply --
  488.  *
  489.  * This routine replaces direct use of applyStubs in SOMr1. The reason
  490.  * for the replacement is that the SOMr1 style of applyStub is not
  491.  * generally available in SOMr2, which uses a fixed set of applyStubs,
  492.  * according to method information in the somMethodData. In particular,
  493.  * neither the redispatch stub nor the apply stub found in the method
  494.  * data structure are necessarily useful as such. The method somGetRdStub
  495.  * is the way to get a redispatch stub, and the above function is the
  496.  * way to call an apply stub. If an appropriate apply stub for the
  497.  * method indicated by md is available, then this is invoked and TRUE is
  498.  * returned; otherwise FALSE is returned.
  499.  *
  500.  * The va_list passed to somApply *must* include the target object,
  501.  * somSelf, as its first entry, and any single precision floating point
  502.  * arguments being passed to the the method procedure must be
  503.  * represented on the va_list using double precision values. retVal cannot
  504.  * be NULL.
  505.  */
  506.  
  507. #ifndef SOM_SMD_DEFINED
  508. typedef somToken somSharedMethodData;
  509. #endif
  510.  
  511. typedef struct somMethodDataStruct {
  512.     somId id;
  513.     long type;          /* 0=static, 1=dynamic 2=nonstatic */
  514.     somId descriptor;        /* for use with IR interfaces */
  515.     somMToken mToken;        /* NULL for dynamic methods */
  516.     somMethodPtr method;     /* depends on resolution context */
  517.     somSharedMethodData *shared;
  518. } somMethodData, *somMethodDataPtr;
  519.  
  520.  
  521. SOMEXTERN boolean SOMLINK somApply(SOMObject *somSelf,
  522.                                 somToken *retVal,
  523.                                 somMethodDataPtr mdPtr,
  524.                                 va_list ap);
  525.  
  526. /*---------------------------------------------------------------------
  527.  * -- somBuildClass --
  528.  *
  529.  * This procedure automates construction of a new class object. A variety of
  530.  * special structures are used to allow language bindings to statically define
  531.  * the information necessary to specify a class. Pointers to these static
  532.  * structures are accumulated into an overall "static class information"
  533.  * structure or SCI, passed to somBuildClass. The SCI has evolved over time.
  534.  * The current version is defined here.
  535.  */
  536.  
  537. #define SOM_SCILEVEL 4
  538.  
  539.  
  540. /* The SCI includes the following information:
  541.  *
  542.  * The address of a class's ClassData structure is passed.
  543.  * This structure should have the external name,
  544.  * <className>ClassData. The classObject field should be NULL
  545.  * (if it is not NULL, then a new class will not be built). somBuildClass will
  546.  * set this field to the address of the new class object when it is built.
  547.  *
  548.  * The address of the class's auxiliary ClassData structure is passed.
  549.  * Thi structure should have the external name,
  550.  * <className>CClassData. The parentMtab field will be set by somBuildClass.
  551.  * This field often allows method calls to a class object to be avoided.
  552.  *
  553.  * The other structures referenced by the static class information (SCI)
  554.  * are used to:
  555.  */
  556.  
  557. /*
  558.  * to specify a static method. The methodId used here must be
  559.  * a simple name (i.e., no colons). In all other cases,
  560.  * where a somId is used to identify a registered method,
  561.  * the somId can include explicit scoping. An explicitly-scoped
  562.  * method name is called a method descriptor. For example,
  563.  * the method introduced by SOMObject as somGetClass has the
  564.  * method descriptor "SOMObject::somGetClass". When a
  565.  * class is contained in an IDL module, the descriptor syntax
  566.  * <moduleName>::<className>::<methodName> can be used. Method
  567.  * descriptors can be useful when a class supports different methods
  568.  * that have the same name (note: IDL prevents this from occuring
  569.  * statically, but SOM itself has no problems with this).
  570.  */
  571. typedef struct somStaticMethodStruct {
  572.     somMToken *classData;
  573.     somId *methodId; /* this must be a simple name (no colons) */
  574.     somId *methodDescriptor;
  575.     somMethodProc *method;
  576.     somMethodProc *redispatchStub;
  577.     somMethodProc *applyStub;
  578. } somStaticMethod_t;
  579.  
  580. /* to specify an overridden method */
  581. typedef struct somOverideMethodStruct {
  582.     somId *methodId; /* this can be a method descriptor */
  583.     somMethodProc *method;
  584. } somOverrideMethod_t;
  585.  
  586. /* to inherit a specific parent's method implementation */
  587. typedef struct somInheritedMethodStruct {
  588.     somId     *methodId;  /* identify the method */
  589.     long parentNum;       /* identify the parent */
  590.     somMToken *mToken;    /* for parentNumresolve */
  591. } somInheritedMethod_t;
  592.  
  593. /* to register a method that has been moved from this */
  594. /* class <cls> upwards in the class hierachy to class <dest> */
  595. typedef struct somMigratedMethodStruct {
  596.     somMToken *clsMToken; /* points into the <cls> classdata structure */
  597.                           /* the method token in <dest> will copied here */
  598.     somMToken *destMToken;/* points into the <dest> classdata structure */
  599.                           /* the method token here will be copied to <cls> */
  600. } somMigratedMethod_t;
  601.  
  602. /* to specify non-internal data */
  603. typedef struct somNonInternalDataStruct {
  604.     somDToken *classData;
  605.     char *basisForDataOffset;
  606. } somNonInternalData_t;
  607.  
  608. /* to specify a "procedure" or "classdata" */
  609. typedef struct somProcMethodsStruct {
  610.     somMethodProc **classData, *pEntry;
  611. } somProcMethods_t;
  612.  
  613. /* to specify a general method "action" using somMethodStruct */
  614. /*
  615.   the type of action is specified by loading the type field of the
  616.   somMethodStruct. There are three bit fields in the overall type:
  617.  
  618.   action (in type & 0xFF)
  619.    0: static -- (i.e., virtual) uses somAddStaticMethod
  620.    1: dynamic -- uses somAddDynamicMethod (classData==0)
  621.    2: nonstatic -- (i.e., nonvirtual) uses somAddMethod
  622.    3: udaAssign -- registers a method as the udaAssign (but doesn't add the method)
  623.    4: udaConstAssign -- like 3, this doesn't add the method
  624.    5: somClassResolve Override (using the class pointed to by *classData)
  625.    6: somMToken Override (using the method token pointed to by methodId)
  626.                          (note: classData==0 for this)
  627.    7: classAllocate -- indicates the default heap allocator for this class.
  628.                        If classData == 0, then method is the code address (or NULL)
  629.                        If classData != 0, then *classData is the code address.
  630.                        No other info required (or used)
  631.    8: classDeallocate -- like 7, but indicates the default heap deallocator.
  632.    9: classAllocator -- indicates a non default heap allocator for this class.
  633.                         like 7, but a methodDescriptor can be given.
  634.  
  635.    === the following is not currently supported ===
  636.    binary data access -- in (type & 0x100), valid for actions 0,1,2,5,6
  637.    0: the method procedure doesn't want binary data access
  638.    1: the method procedure does want binary data access
  639.  
  640.    aggregate return -- in (type & 0x200), used when binary data access requested
  641.    0: method procedure doesn't return a structure
  642.    1: method procedure does return a structure
  643. */
  644.  
  645. typedef struct somMethodStruct {
  646.     unsigned long type;
  647.     somMToken *classData;
  648.     somId *methodId;
  649.     somId *methodDescriptor;
  650.     somMethodProc *method;
  651.     somMethodProc *redispatchStub;
  652.     somMethodProc *applyStub;
  653. } somMethods_t;
  654.  
  655. /* to specify a varargs function */
  656. typedef struct somVarargsFuncsStruct {
  657.     somMethodProc **classData, *vEntry;
  658. } somVarargsFuncs_t;
  659.  
  660. /* to specify dynamically computed information (incl. embbeded objs) */
  661. typedef struct {
  662.     int   version;              /* 1 for now */
  663.     long    instanceDataSize;   /* true size (incl. embedded objs) */
  664.     long    dataAlignment;      /* true alignment */
  665.     somEmbeddedObjStruct *embeddedObjs; /* array end == null copp */
  666. } somDynamicSCI;
  667.  
  668.  
  669. /*
  670.    to specify a DTS class, use the somDTSClass entry in the following
  671.    data structure. This entry is a bit vector interpreted as follows:
  672.  
  673.    (somDTSClass & 0x0001) == the class is a DTS C++ class
  674.    (somDTSClass & 0x0002) == the class wants the initCtrl entries
  675.                              of the somParentMtabStruct filled in.
  676.  
  677. */
  678.  
  679.  
  680.  
  681. /*
  682.  *  The Static Class Info Structure passed to somBuildClass
  683.  */
  684.  
  685. typedef struct somStaticClassInfoStruct {
  686.     unsigned long layoutVersion;  /* this struct defines layout version SOM_SCILEVEL */
  687.     unsigned long numStaticMethods;   /* count of smt entries */
  688.     unsigned long numStaticOverrides; /* count of omt entries */
  689.     unsigned long numNonInternalData; /* count of nit entries */
  690.     unsigned long numProcMethods;     /* count of pmt entries */
  691.     unsigned long numVarargsFuncs;    /* count of vft entries */
  692.     unsigned long majorVersion;
  693.     unsigned long minorVersion;
  694.     unsigned long instanceDataSize;   /* instance data introduced by this class */
  695.     unsigned long maxMethods;         /* count numStaticMethods and numMethods */
  696.     unsigned long numParents;
  697.     somId    classId;
  698.     somId    explicitMetaId;
  699.     long implicitParentMeta;
  700.     somId                  *parents;
  701.     somClassDataStructure  *cds;
  702.     somCClassDataStructure *ccds;
  703.     somStaticMethod_t      *smt; /* basic "static" methods for mtab */
  704.     somOverrideMethod_t    *omt; /* overrides for mtab */
  705.     char                   *nitReferenceBase;
  706.     somNonInternalData_t   *nit; /* datatokens for instance data */
  707.     somProcMethods_t       *pmt; /* Arbitrary ClassData members */
  708.     somVarargsFuncs_t      *vft; /* varargs stubs */
  709.     somTP_somClassInitFunc *cif; /* class init function */
  710.     /* end of layout version 1 */
  711.  
  712.     /* begin layout version 2 extensions */
  713.     long dataAlignment; /* the desired byte alignment for instance data */
  714.     /* end of layout version 2 */
  715.  
  716. #define SOMSCIVERSION 1
  717.  
  718.     /* begin layout version 3 extensions */
  719.     long numDirectInitClasses;
  720.     somId *directInitClasses;
  721.     unsigned long numMethods; /* general (including nonstatic) methods for mtab */
  722.     somMethods_t       *mt;
  723.     unsigned long protectedDataOffset; /* access = resolve(instanceDataToken) + offset */
  724.     unsigned long somSCIVersion;  /* used during development. currently = 1 */
  725.     unsigned long numInheritedMethods;
  726.     somInheritedMethod_t *imt; /* inherited method implementations */
  727.     unsigned long numClassDataEntries; /* should always be filled in */
  728.     somId *classDataEntryNames; /* either NULL or ptr to an array of somIds */
  729.     unsigned long numMigratedMethods;
  730.     somMigratedMethod_t *mmt; /* migrated method implementations */
  731.     unsigned long numInitializers; /* the initializers for this class */
  732.     somId *initializers;     /* in order of release */
  733.     unsigned long somDTSClass; /* used to identify a DirectToSOM class */
  734.     somDynamicSCI *dsci;  /* used to register dynamically computed info */
  735.     /* end of layout version 3 */
  736.  
  737. } somStaticClassInfo, *somStaticClassInfoPtr;
  738.  
  739. SOMEXTERN SOMClass * SOMLINK somBuildClass (
  740.                     long inherit_vars,
  741.                     somStaticClassInfo *sci,
  742.                     long majorVersion,
  743.                     long minorVersion);
  744.  
  745.   /*
  746.   The arguments to somBuildClass are as follows:
  747.  
  748.    inherit_vars: a bit mask used to control inheritance of implementation
  749.    Implementation is inherited from parent i iff the bit 1<<i is on, or i>=32.
  750.  
  751.    sci: the somStaticClassInfo defined above.
  752.  
  753.    majorVersion, minorVersion: the version of the class implementation.
  754.  
  755.    */
  756.  
  757.  
  758. /*---------------------------------------------------------------------
  759.  *  Used by old single-inheritance emitters to make class creation
  760.  *  an atomic operation. Kept for backwards compatability.
  761.  */
  762. SOMEXTERN void SOMLINK somConstructClass (
  763.                     somTD_classInitRoutine *classInitRoutine,
  764.                     SOMClass *parentClass,
  765.                     SOMClass *metaClass,
  766.                     somClassDataStructure *cds);
  767.  
  768.  
  769. /*
  770.  * Uses <SOMOutCharRoutine> to output its arguments under control of the ANSI C
  771.  * style format.  Returns the number of characters output.
  772.  */
  773. SOMEXTERN int SOMLINK somPrintf (string fmt, ...);
  774. /*
  775.  * vprint form of somPrintf
  776.  */
  777. SOMEXTERN int SOMLINK somVprintf (string fmt, va_list ap);
  778. /*
  779.  * Outputs (via somPrintf) blanks to prefix a line at the indicated level
  780.  */
  781. SOMEXTERN void SOMLINK somPrefixLevel (long level);
  782. /*
  783.  * Combines somPrefixLevel and somPrintf
  784.  */
  785. SOMEXTERN int SOMLINK somLPrintf (int level, string fmt, ...);
  786.  
  787. /*
  788.  *  Replaceable character output handler.
  789.  *  Points to the character output routine to be used in development
  790.  *  support.  Initialized to <somOutChar>, but may be reset at anytime.
  791.  *  Should return 0 (false) if an error occurs and 1 (true) otherwise.
  792.  */
  793.  
  794. SOMEXTERN somTD_SOMOutCharRoutine * SOMDLINK SOMOutCharRoutine;
  795.  
  796. /*----------------------------------------------------------------------
  797.  * Pointers to routines used to do dynamic code loading and deleting
  798.  */
  799.  
  800. SOMEXTERN somTD_SOMLoadModule     * SOMDLINK SOMLoadModule;
  801. SOMEXTERN somTD_SOMDeleteModule   * SOMDLINK SOMDeleteModule;
  802. SOMEXTERN somTD_SOMClassInitFuncName * SOMDLINK SOMClassInitFuncName;
  803.  
  804. /*----------------------------------------------------------------------
  805.  *  Replaceable SOM Memory Management Interface
  806.  *
  807.  *  External procedure variables SOMCalloc, SOMFree, SOMMalloc, SOMRealloc
  808.  *  have the same interface as their standard C-library analogs.
  809.  */
  810.  
  811. SOMEXTERN somTD_SOMCalloc  * SOMDLINK SOMCalloc;
  812. SOMEXTERN somTD_SOMFree    * SOMDLINK SOMFree;
  813. SOMEXTERN somTD_SOMMalloc  * SOMDLINK SOMMalloc;
  814. SOMEXTERN somTD_SOMRealloc * SOMDLINK SOMRealloc;
  815.  
  816. /*----------------------------------------------------------------------
  817.  *  Replaceable SOM Error handler
  818.  */
  819.  
  820. SOMEXTERN somTD_SOMError * SOMDLINK SOMError;
  821.  
  822. /*----------------------------------------------------------------------
  823.  *  Replaceable SOM Semaphore Operations
  824.  *
  825.  *  These operations are used by the SOM Kernel to make thread-safe
  826.  *  state changes to internal resources.
  827.  */
  828. SOMEXTERN somTD_SOMCreateMutexSem  * SOMDLINK SOMCreateMutexSem;
  829. SOMEXTERN somTD_SOMRequestMutexSem * SOMDLINK SOMRequestMutexSem;
  830. SOMEXTERN somTD_SOMReleaseMutexSem * SOMDLINK SOMReleaseMutexSem;
  831. SOMEXTERN somTD_SOMDestroyMutexSem * SOMDLINK SOMDestroyMutexSem;
  832.  
  833. /*----------------------------------------------------------------------
  834.  *  Replaceable SOM Thread Identifier Operation
  835.  *
  836.  *  This operation is used by the SOM Kernel to index data unique to the
  837.  *  currently executing thread.  It must return a small integer that
  838.  *  uniquely represents the current thread within the current process.
  839.  */
  840. SOMEXTERN somTD_SOMGetThreadId * SOMDLINK SOMGetThreadId;
  841.  
  842. /*----------------------------------------------------------------------
  843.  * Externals used in the implementation of SOM, but not part of the
  844.  * SOM API.
  845.  */
  846.  
  847. SOMEXTERN SOMObject * SOMLINK somTestCls(SOMObject *obj, SOMClass *classObj,
  848.                                          string fileName, int lineNumber);
  849. SOMEXTERN void SOMLINK somTest(int condition, int severity, string fileName,
  850.                                int lineNum, string msg);
  851. SOMEXTERN void SOMLINK somAssert(int condition, int ecode,
  852.                                  string fileName, int lineNum, string msg);
  853.  
  854.  
  855. #endif /* somapi_h */
  856.