home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / HANDLERS.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  12KB  |  234 lines

  1. /* @(#)Z 1.4 com/src/cm/Handlers.h, odstorage, od96os2, odos29646d 96/11/15 15:27:12 (96/10/29 09:18:52) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odstorage
  6.  *
  7.  *   CLASSES: none
  8.  *
  9.  *   ORIGINS: 82,27
  10.  *
  11.  *
  12.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13.  *   All Rights Reserved
  14.  *   Licensed Materials - Property of IBM
  15.  *   US Government Users Restricted Rights - Use, duplication or
  16.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17.  *       
  18.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24.  *   OR PERFORMANCE OF THIS SOFTWARE.
  25.  */
  26. /*====END_GENERATED_PROLOG========================================
  27.  */
  28.  
  29. /*
  30.     File:        Handlers.h
  31.  
  32.     Contains:    Container Manager Handlers Interfaces
  33.  
  34.     Written by:    Ira L. Ruben
  35.  
  36.     Owned by:    Ed Lai
  37.  
  38.     Copyright:    ⌐ 1991-1994 by Apple Computer, Inc., all rights reserved.
  39.  
  40.     Change History (most recent first):
  41.  
  42.          <2>     8/26/94    EL        #1182319 Matches Handlers.c
  43.          <4>      5/9/94    MB        #1162181: Changes necessary to install MMM.
  44.          <3>      2/3/94    EL        Bento File names are now eight chars or
  45.                                     less.
  46.          <2>    11/22/93    EL        Add refcon for alloc and free handers.
  47.  
  48.     To Do:
  49. */
  50.  
  51. /*---------------------------------------------------------------------------*
  52.  |                                                                           |
  53.  |                            <<< Handlers.h >>>                             |
  54.  |                                                                           |
  55.  |                   Container Manager Handlers Interfaces                   |
  56.  |                                                                           |
  57.  |                               Ira L. Ruben                                |
  58.  |                                 11/18/91                                  |
  59.  |                                                                           |
  60.  |                  Copyright Apple Computer, Inc. 1991-1994                 |
  61.  |                           All rights reserved.                            |
  62.  |                                                                           |
  63.  *---------------------------------------------------------------------------*
  64.  
  65.  Containers (files, memory, or whatever) are always access through handlers, to provide
  66.  platform independence.  Handlers are responsible for doing all the I/O operations,
  67.  including opening and closing, to containers.  They are also responsible for reading and
  68.  writing the container label.
  69.  
  70.  The routines defined by this header are the API interfaces to allow the Container Manager
  71.  to determine what handlers it should use for a particular container.  The Container
  72.  Manager handler routines defined here maintain container type name/metahandler
  73.  associations.
  74. */
  75.  
  76. #ifndef __HANDLERS__
  77. #define __HANDLERS__
  78.  
  79. #include <stdio.h>
  80.  
  81. #ifndef __CMTYPES__
  82. #include "CMTypes.h"
  83. #endif
  84. #ifndef __CM_API_TYPES__
  85. #include "CMAPITyp.h"
  86. #endif
  87. #ifndef __SYMMGR__
  88. #include "SymTbMgr.h"      
  89. #endif
  90. #ifndef __SESSIONDATA__
  91. #include "Session.h"          
  92. #endif
  93.  
  94. struct SessionGlobalData;
  95.  
  96.                                                                     CM_CFUNCTIONS
  97.  
  98. /* The metahandler symbol table contains the associations between type names and meta-    */
  99. /* handler routine addresses.                                                                                                                     */
  100.  
  101. struct MetaHandler {                                        /* Layout for a metahandler symbol table entry:    */
  102.     SymbolLinks     theTreeLinks;                        /*         standard right/left links (must be 1st)        */
  103.     CMMetaHandler     metaHandler;                    /*        ptr to the metahandler                                        */
  104.     CM_UCHAR        typeName[1];                            /*        start of type name for this handler                */
  105. };
  106. typedef struct MetaHandler MetaHandler, *MetaHandlerPtr;
  107.  
  108.  
  109. /* The following defines the vector of handler routines which is built as part of every    */
  110. /* container control block.    The vector is filled in when a container is opened by                */
  111. /* calling a metahandler proc which returns the handler addresses.                                            */
  112.  
  113. struct HandlerOps {                                            /* Basic I/O operations and their prototypes        */
  114.     CMRefCon (*cmfopen)(CMRefCon attributes, CMOpenMode mode);    
  115.     void (*cmfclose)(CMRefCon refCon);
  116.     CMSize (*cmfflush)(CMRefCon refCon);
  117.     CMSize (*cmfseek)(CMRefCon refCon, CM_LONG posOff, CMSeekMode mode);
  118.     CMSize (*cmftell)(CMRefCon refCon);
  119.     CMSize (*cmfread)(CMRefCon refCon, CMPtr buffer,  CMSize elementSize, CMCount theCount);
  120.     CMSize (*cmfwrite)(CMRefCon refCon, CMPtr buffer, CMSize elementSize, CMCount theCount);
  121.     CMEofStatus (*cmfeof)(CMRefCon refCon);
  122.     CMBoolean (*cmftrunc)(CMRefCon refCon, CMSize containerSize);
  123.     CMSize (*cmgetContainerSize)(CMRefCon refCon);
  124.     void (*cmreadLabel)(CMRefCon refCon, CMMagicBytes magicByteSequence, CMContainerFlags *flags,
  125.                                           CM_USHORT *bufSize, CM_USHORT *majorVersion, CM_USHORT *minorVersion,
  126.                                           CMSize *tocOffset, CMSize *tocSize);
  127.     void (*cmwriteLabel)(CMRefCon refCon, CMMagicBytes magicByteSequence, CMContainerFlags flags,
  128.                                            CM_USHORT bufSize, CM_USHORT majorVersion, CM_USHORT minorVersion,
  129.                                               CMSize tocOffset, CMSize tocSize);
  130.     CMValue (*cmreturnParentValue)(CMRefCon refCon);
  131.     char *(*cmreturnContainerName)(CMRefCon refCon);
  132.     CMType (*cmreturnTargetType)(CMRefCon refCon, CMContainer container);
  133.     void (*cmextractData)(CMRefCon refCon, CMDataBuffer updateBuffer, CMSize size,
  134.                                                 CMPrivateData data);
  135.     void (*cmformatData)(CMRefCon refCon, CMDataBuffer updateBuffer, CMSize size,
  136.                                              CMPrivateData data);
  137. };
  138. typedef struct HandlerOps HandlerOps;
  139.  
  140.  
  141. /* To make it easier and more readable for the Container Manager to call the handlers,    */
  142. /* the following macros are defined.  The "refCon" is located in the container control     */
  143. /* block.     Note the container is always an explicit parameter to these macros since in    */
  144. /* some places we may be dealing with more than one container due to updating.                    */
  145.  
  146. #define CMfopen(container, refCon, m)           (*((ContainerPtr)container)->handler.cmfopen)((void *)refCon, (CMOpenMode)(m))
  147. #define CMfclose(container)                                 (*((ContainerPtr)container)->handler.cmfclose)(((ContainerPtr)container)->refCon)
  148. #define CMfflush(container)                                 (*((ContainerPtr)container)->handler.cmfflush)(((ContainerPtr)container)->refCon)
  149. #define CMfseek(container, p, m)                         (*((ContainerPtr)container)->handler.cmfseek)(((ContainerPtr)container)->refCon, (CM_LONG)(p), (CMSeekMode)(m))
  150. #define CMftell(container)                                     (*((ContainerPtr)container)->handler.cmftell)(((ContainerPtr)container)->refCon)
  151. #define CMfread(container, b, e, c)                  (*((ContainerPtr)container)->handler.cmfread)(((ContainerPtr)container)->refCon, (CMPtr)(b), (CMSize)(e), (CMCount)(c))
  152. #define CMfwrite(container, b, e, c)                 (*((ContainerPtr)container)->handler.cmfwrite)(((ContainerPtr)container)->refCon, (CMPtr)(b), (CMSize)(e), (CMCount)(c))
  153. #define CMfeof(container)                                     (*((ContainerPtr)container)->handler.cmfeof)(((ContainerPtr)container)->refCon)
  154. #define CMftrunc(container, s)                            (*((ContainerPtr)container)->handler.cmftrunc)(((ContainerPtr)container)->refCon, (CMSize)(s))
  155. #define CMgetContainerSize(container)                (*((ContainerPtr)container)->handler.cmgetContainerSize)(((ContainerPtr)container)->refCon)
  156. #define CMreadLabel(container, m, f, n, v1, v2, t, l)  (*((ContainerPtr)container)->handler.cmreadLabel)(((ContainerPtr)container)->refCon, (CMMagicBytes)(m), (CMContainerFlags*)(f), (CM_USHORT*)(n), (CM_USHORT*)(v1), (CM_USHORT*)(v2), (CMSize*)(t), (CMSize*)(l))
  157. #define CMwriteLabel(container, m, f, n, v1, v2, t, l) (*((ContainerPtr)container)->handler.cmwriteLabel)(((ContainerPtr)container)->refCon, (CMMagicBytes)(m), (CMContainerFlags)(f), (CM_USHORT)(n), (CM_USHORT)(v1), (CM_USHORT)(v2), (CMSize)(t), (CMSize)(l))
  158. #define CMreturnParentValue(container)            (TOCValueHdrPtr)(*((ContainerPtr)container)->handler.cmreturnParentValue)(((ContainerPtr)container)->refCon)
  159. #define CMreturnContainerName(container)        (*((ContainerPtr)container)->handler.cmreturnContainerName)(((ContainerPtr)container)->refCon)
  160. #define CMreturnTargeType(container)                (*((ContainerPtr)container)->handler.cmreturnTargetType)(((ContainerPtr)container)->refCon, (CMContainer)container)
  161. #define CMextractData(container, b, n, d)         (*((ContainerPtr)container)->handler.cmextractData)(((ContainerPtr)container)->refCon, (CMDataBuffer)(b), (CMSize)(n), (CMPrivateData)(d))
  162. #define CMformatData(container, b, n, d)         (*((ContainerPtr)container)->handler.cmformatData)(((ContainerPtr)container)->refCon, (CMDataBuffer)(b), (CMSize)(n), (CMPrivateData)(d))
  163.  
  164. /* Sorry about the length of these lines.  The casts make them that way.  That is done    */
  165. /* because some of the Container Manager routines that use these pass values coming in    */
  166. /* from external (i.e., "CM...") calls.  The external types are generic and have to be    */
  167. /* converted to the "real thing" (if you know what I mean).                                                            */
  168.  
  169. /* NOTE: Currently CMfeof() is NOT used by the container manager...                                            */
  170.  
  171.  
  172. /* Just like the container specific handlers, we have macros for calling the memory         */
  173. /* management handlers.  These all use the session data pointer via the current                 */
  174. /* container whose pointer is assumed to be the variable name "container".                             */
  175.  
  176. #define CMmalloc(size)                         (*(SESSION->cmMalloc))((CMSize)size,SESSION->refCon)
  177. #define CMfree(ptr)                                 (*(SESSION->cmFree))((CMPtr)ptr,SESSION->refCon)
  178.  
  179.  
  180. MetaHandlerPtr cmDefineMetaHandler(CMMetaHandler metaHandler, 
  181.                                                                       const CM_UCHAR *typeName,
  182.                                                                         CMBoolean *dup,
  183.                                                                      struct SessionGlobalData *sessionData);
  184.     /*
  185.   Define a new metahandler with the specifed type (a C string). The function returns a
  186.   pointer to the new handler or, if dup is true, a pointer to a previously defined entry.
  187.     
  188.     If NULL is returned then there was an allocation failure and the new type could not be
  189.     created.
  190.     
  191.     Note, the global data session pointer created by CMStartSession() is passed since
  192.     methandlers are global to all containers and thus the root of the metahandler symbol
  193.     table is kept as part of the session data.
  194.     */
  195.  
  196.  
  197. MetaHandlerPtr cmLookupMetaHandler(const CM_UCHAR *typeName,
  198.                                                                      struct SessionGlobalData *sessionData);
  199.     /*
  200.     Find a metahandler associated with the specified type.  If found, the HandlerPtr to the 
  201.     found entry is returned (which includes the handler proc and type).  If not found NULL
  202.     is returned.
  203.     
  204.     Note, we allocate a temporary handler table entry here and then free it.   If the
  205.     allocation fails, SessionSuccess, a session status switch, is returned false.  Otherwise
  206.     SessionSuccess is true.
  207.     
  208.     The global data session pointer created by CMStartSession() is passed since methandlers
  209.     are global to all containers and thus the root of the metahandler symbol table is kept
  210.     as part of the session data.
  211.     */
  212.     
  213.  
  214. void cmForEachMetaHandler(CMRefCon refCon, 
  215.                                                     void (*action)(MetaHandlerPtr aHandler, CMRefCon refCon),
  216.                                                     struct SessionGlobalData *sessionData);    
  217.     /*
  218.     Do (call) the specified action for each defined metahandler in the current session. The
  219.     pointer to each metahandler entry is passed to the action routine along with a "refCon"
  220.     which the caller can use as a communication facility to convey additional info to the
  221.     action routine.
  222.     */
  223.  
  224.  
  225. void cmFreeAllMetaHandlers(struct SessionGlobalData *sessionData);
  226.     /*
  227.   This routine is called to remove the definitions of ALL previously defined metahandlers
  228.   for the current session.
  229.     */
  230.     
  231.  
  232.                                                           CM_END_CFUNCTIONS
  233. #endif
  234.