home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / toolkt21 / c / os2h / som.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-12  |  11.6 KB  |  304 lines

  1. /*
  2.  *    SOM.H
  3.  *    First level include file for System Object Model
  4.  *
  5.  *    Copyright (c) International Business Machines Corporation
  6.  *                  1991, 1992, 1993
  7.  *
  8.  *    @(#)som.h 1.20 3/17/93 19:48:07 [3/17/93] (c)IBM Corp. 1993
  9.  */
  10.  
  11. #ifndef som_h
  12. #define som_h
  13.  
  14. #include <somnames.h>
  15.  
  16. #ifdef __cplusplus
  17. #define SOMEXTERN extern "C"
  18. #else
  19. #define SOMEXTERN extern
  20. #endif
  21.  
  22. /*  Define SOMLINK unless it is already defined
  23.  */
  24. #ifndef SOMLINK
  25.   #ifdef __IBMCPP__ 
  26.     #define SOMLINK _System
  27.   #else
  28.     #ifdef _CL386
  29.       #define SOMLINK _syscall
  30.     #else
  31.       #define SOMLINK
  32.     #endif
  33.   #endif
  34. #endif
  35.  
  36. #ifdef __IBMC__
  37.   #pragma linkage(somAssert                 , system)
  38.   #pragma linkage(somBeginPersistentIds     , system)
  39.   #pragma linkage(somCheckId                , system)
  40.   #pragma linkage(somCompareIds             , system)
  41.   #pragma linkage(somConstructClass         , system)
  42.   #pragma linkage(somDataResolve            , system)
  43.   #pragma linkage(somEndPersistentIds       , system)
  44.   #pragma linkage(somEnvironmentNew         , system)
  45.   #pragma linkage(somGenericApply           , system)
  46.   #pragma linkage(somGetClass               , system)
  47.   #pragma linkage(somIdFromString           , system)
  48.   #pragma linkage(somLPrintf                , system)
  49.   #pragma linkage(somParentResolve          , system)
  50.   #pragma linkage(somPrefixLevel            , system)
  51.   #pragma linkage(somPrintf                 , system)
  52.   #pragma linkage(somRegisterId             , system)
  53.   #pragma linkage(somResolve                , system)
  54.   #pragma linkage(somSetExpectedIds         , system)
  55.   #pragma linkage(somStringFromId           , system)
  56.   #pragma linkage(somTest                   , system)
  57.   #pragma linkage(somTestCls                , system)
  58.   #pragma linkage(somTotalRegIds            , system)
  59.   #pragma linkage(somUniqueKey              , system)
  60.   #pragma linkage(somVprintf                , system)
  61.   #pragma linkage(somTD_classInitRoutine    , system)
  62.   #pragma linkage(somTD_SOMCalloc           , system)
  63.   #pragma linkage(somTD_SOMClassInitFuncName, system)
  64.   #pragma linkage(somTD_SOMDeleteModule     , system)
  65.   #pragma linkage(somTD_SOMError            , system)
  66.   #pragma linkage(somTD_SOMFree             , system)
  67.   #pragma linkage(somTD_SOMLoadModule       , system)
  68.   #pragma linkage(somTD_SOMMalloc           , system)
  69.   #pragma linkage(somTD_SOMOutCharRoutine   , system)
  70.   #pragma linkage(somTD_SOMRealloc          , system)
  71. #endif
  72.  
  73. #include <stdarg.h>
  74. #include <stddef.h>
  75. #include <somtypes.h>
  76. #include <somerr.h>
  77. #include <somcdev.h>
  78.  
  79. /*----------------------------------------------------------------------
  80.  *  Typedefs for pointers to functions
  81.  */
  82.  
  83. typedef void    SOMLINK somTD_classInitRoutine(SOMClass *, SOMClass *);
  84. typedef int     SOMLINK somTD_SOMOutCharRoutine(char);
  85. typedef int     SOMLINK somTD_SOMLoadModule(IN zString /* className */,
  86.                                         IN zString     /* fileName */,
  87.                                         IN zString     /* functionName */,
  88.                                         IN integer4    /* majorVersion */,
  89.                                         IN integer4    /* minorVersion */,
  90.                                         OUT somToken * /* modHandle */);
  91. typedef int     SOMLINK somTD_SOMDeleteModule(IN somToken /* modHandle */);
  92. typedef zString SOMLINK somTD_SOMClassInitFuncName(void);
  93. typedef void *  SOMLINK somTD_SOMMalloc(IN size_t /* nbytes */);
  94. typedef void *  SOMLINK somTD_SOMCalloc(IN size_t /* element_count */,
  95.                                         IN size_t /* element_size */);
  96. typedef void *  SOMLINK somTD_SOMRealloc(IN void * /* memory */,
  97.                                          IN size_t /* nbytes */);
  98. typedef void    SOMLINK somTD_SOMFree(IN void * /* memory */);
  99. typedef void    SOMLINK somTD_SOMError(IN int      /* code */,
  100.                                        IN zString  /* fileName */,
  101.                                        IN int      /* lineNum */);
  102.  
  103. /*----------------------------------------------------------------------
  104.  *  Misc. procedures:
  105.  */
  106.  
  107. /*
  108.  *  Create and initialize the SOM environment
  109.  *
  110.  *  Can be called repeatedly
  111.  *
  112.  *  Will be called automatically when first object (including a class
  113.  *  object) is created, if it has not already been done.
  114.  *
  115.  *  Returns the SOMClassMgrObject
  116.  */
  117.  
  118. SOMEXTERN SOMClassMgr * SOMLINK somEnvironmentNew (void);
  119.  
  120. /*----------------------------------------------------------------------
  121.  *  String Manager: stem <somsm>
  122.  */
  123. /* makes sure that the id is registered and in normal form, returns */
  124. /* the id */
  125. SOMEXTERN somId SOMLINK somCheckId (somId id);
  126.  
  127. /* Same as somCheckId except returns 1 (true) if this is the first */
  128. /* time the string associated with this id has been registered, */
  129. /* returns 0 (false) otherwise */
  130. SOMEXTERN int SOMLINK somRegisterId(somId id);
  131.  
  132. SOMEXTERN somId SOMLINK somIdFromString (zString aString);
  133.  
  134. SOMEXTERN zString SOMLINK somStringFromId (somId id);
  135.  
  136. SOMEXTERN int SOMLINK somCompareIds(somId id1, somId id2);
  137.  
  138. /* Returns the total number of ids that have been registered so far, */
  139. /* you can use this to advise the SOM runtime concerning expected */
  140. /* number of ids in later executions of your program, via a call to */
  141. /* somSetExpectedIds defined below */
  142. SOMEXTERN unsigned long SOMLINK somTotalRegIds(void);
  143.  
  144. /* Tells the SOM runtime how many unique ids you expect to use during */
  145. /* the execution of your program, this can improve space and time */
  146. /* utilization slightly, this routine must be called before the SOM */
  147. /* environment is created to have any effect */
  148. SOMEXTERN void SOMLINK somSetExpectedIds(unsigned long numIds);
  149.  
  150. /* Returns the unique key for this id, this key will be the same as the */
  151. /* key in another id if and only if the other id refers to the same */
  152. /* name as this one */
  153. SOMEXTERN unsigned long SOMLINK somUniqueKey(somId id);
  154.  
  155. /* Tells the id manager that strings for any new ids that are */
  156. /* registered will never be freed or otherwise modified. This allows */
  157. /* the id manager to just use a pointer to the string in the */
  158. /* unregistered id as the master copy of the ids string. Thus saving */
  159. /* space */
  160. /* Under normal use (where ids are static varibles) the string */
  161. /* associated with an id would only be freed if the code module in */
  162. /* which it occured was unloaded */
  163. SOMEXTERN void SOMLINK somBeginPersistentIds(void);
  164.  
  165. /* Tells the id manager that strings for any new ids that are */
  166. /* registered may be freed or otherwise modified.  Therefore the id */
  167. /* manager must copy the strings inorder to remember the name of an */
  168. /* id. */
  169. SOMEXTERN void SOMLINK somEndPersistentIds(void);
  170.  
  171. /*----------------------------------------------------------------------
  172.  *  Root object: SOMObject, stem <somob>
  173.  */
  174. #include <somobj.h>
  175.  
  176. /*----------------------------------------------------------------------
  177.  *  Root meta class: SOMClass, stem <sommc>
  178.  */
  179. #include <somcls.h>
  180.  
  181. /*----------------------------------------------------------------------
  182.  *  Class Manager: SOMClassMgr, stem <somcm>
  183.  */
  184. #include <somcm.h>
  185.  
  186. /* Global class manager object */
  187. SOMEXTERN SOMClassMgr *SOMClassMgrObject;
  188.  
  189. /*----------------------------------------------------------------------
  190.  *  Dispatch meta class: SOMClassDispatch, stem <sommd>
  191.  */
  192.  
  193. /*---------------------------------------------------------------------
  194.  *  Basic offset based method resolution, this is used in every method
  195.  *  class that uses offset resolution
  196.  *  It returns the appropriate method procedure for the method
  197.  *  identified by <mdata>, Mdata id the 32 bit value stored in the
  198.  *  class data structure in the entry with the methods name. I.e., if
  199.  *  a object, obj, of class, Foo, has a method, bar, then:
  200.  *      somResolve(obj, FooClassData.bar)
  201.  *  will return the appropriate method procedure for bar.
  202.  *  The way that <mdata> identifies a method and the algorithm used by
  203.  *  somResolve to locate the appropriate method procedure is not part
  204.  *  of the visible SOM architecture and is subject to change in
  205.  *  subsequent releases.
  206.  */
  207. SOMEXTERN somMethodProc * SOMLINK somResolve(SOMAny *obj, somMToken mdata);
  208. SOMEXTERN somMethodProc * SOMLINK somParentResolve(somMethodTab *parentMtab,
  209.                                          somMToken mdata);
  210. SOMEXTERN void * SOMLINK somDataResolve(SOMAny *obj, somDToken dataId);
  211.  
  212. /*---------------------------------------------------------------------
  213.  *  Used to make class object creation an atomic operation, this is
  214.  *  called by the generated <class name>NewClass routine.  You should
  215.  *  never call this routine directly.
  216.  */
  217. SOMEXTERN void SOMLINK somConstructClass (
  218.                     somTD_classInitRoutine *classInitRoutine,
  219.                     SOMClass *parentClass,
  220.                     SOMClass *metaClass,
  221.                     somClassDataStructure *cds);
  222.  
  223. /*---------------------------------------------------------------------
  224.  *  Generic apply function
  225.  */
  226. SOMEXTERN void SOMLINK somGenericApply (SOMAny *obj,
  227.            somId methodID,
  228.            somId methodDescriptor,
  229.            va_list ap);
  230.  
  231. /*
  232.  * Convenience function to obtain the class object for a given object
  233.  */
  234. #ifndef SOMObject_Class_Source
  235. SOMEXTERN SOMClass * SOMLINK somGetClass (SOMAny *self);
  236. #endif
  237.  
  238. /*
  239.  * Uses <SOMOutCharRoutine> to output its arguments under control of the ANSI C
  240.  * style format.  Returns the number of characters output.
  241.  */
  242. SOMEXTERN int SOMLINK somPrintf (zString fmt, ...);
  243. /*
  244.  * vprint form of somPrintf
  245.  */
  246. SOMEXTERN int SOMLINK somVprintf (zString fmt, va_list ap);
  247. /*
  248.  * Outputs (via somPrintf) blanks to prefix a line at the indicated level
  249.  */
  250. SOMEXTERN void SOMLINK somPrefixLevel (int level);
  251. /*
  252.  * Combines somPrefixLevel and somPrintf
  253.  */
  254. SOMEXTERN int SOMLINK somLPrintf (int level, zString fmt, ...);
  255.  
  256. /*
  257.  *  Replaceable character output handler.
  258.  *  Points to the character output routine to be used in development
  259.  *  support.  Initialized to <somOutChar>, but may be reset at anytime.
  260.  *  Should return 0 (false) if an error occurs and 1 (true) otherwise.
  261.  */
  262.  
  263. SOMEXTERN somTD_SOMOutCharRoutine *SOMOutCharRoutine;
  264.  
  265. /*----------------------------------------------------------------------
  266.  * Pointers to routines used to do dynamic code loading and deleting
  267.  */
  268.  
  269. SOMEXTERN somTD_SOMLoadModule     *SOMLoadModule;
  270. SOMEXTERN somTD_SOMDeleteModule   *SOMDeleteModule;
  271. SOMEXTERN somTD_SOMClassInitFuncName *SOMClassInitFuncName;
  272.  
  273. /*----------------------------------------------------------------------
  274.  *  Replaceable SOM Memory Management Interface
  275.  *
  276.  *  External procedure variables SOMCalloc, SOMFree, SOMMalloc, SOMRealloc
  277.  *  have the same interface as their standard C-library analogs.
  278.  */
  279.  
  280. SOMEXTERN somTD_SOMCalloc       *SOMCalloc;
  281. SOMEXTERN somTD_SOMFree *SOMFree;
  282. SOMEXTERN somTD_SOMMalloc       *SOMMalloc;
  283. SOMEXTERN somTD_SOMRealloc *SOMRealloc;
  284.  
  285. /*----------------------------------------------------------------------
  286.  *  Replaceable SOM Error handler
  287.  */
  288.  
  289. SOMEXTERN somTD_SOMError *SOMError;
  290.  
  291. /*----------------------------------------------------------------------
  292.  * Externals used in the implementation of SOM, but not part of the
  293.  * SOM API.
  294.  */
  295.  
  296. SOMEXTERN SOMAny * SOMLINK somTestCls(SOMAny *obj, SOMClass *classObj,
  297.                                    zString fileName, int lineNumber);
  298. SOMEXTERN void SOMLINK somTest(int condition, int severity, zString fileName,
  299.                             int lineNum, zString msg);
  300. SOMEXTERN void SOMLINK somAssert(int condition, int ecode,
  301.                                  zString fileName, int lineNum, zString msg);
  302.  
  303. #endif
  304.