home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / IndHdr.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  17KB  |  439 lines

  1. /* @(#)Z 1.7 com/src/bento/IndHdr.cpp, odstorage, od96os2, odos29712d 97/03/21 17:19:19 (96/10/29 09:12:47) */
  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:        IndHdr.cpp
  31.  
  32.     Contains:    Indirect Handler for Bento Container Suite
  33.  
  34.     Owned by:    Vincent Lo
  35.  
  36.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  37.  
  38.     Change History (most recent first):
  39.  
  40.          <7>    10/22/95    EL        1294623: Indirect value contains endian-
  41.                                     specific name length.
  42.          <6>    10/13/95    EL        1287340: Use standard ISO prefix
  43.          <5>      8/8/95    jpa        Fixed DebugStrs [1265584]
  44.          <4>     5/26/95    VL        1251403: Multithreading naming support.
  45.          <3>      7/5/94    CC        Type cast pascal strings.
  46.          <2>     6/18/94    MB        Correct memory includes, still problems
  47.          <1>     5/27/94    VL        first checked in
  48.  
  49.     To Do:
  50.     In Progress:
  51.         
  52. */
  53.  
  54. #ifndef _ODTYPES_
  55. #include "ODTypes.h"
  56. #endif
  57.  
  58. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_AIX_)
  59. #ifndef _ODDEBUG_
  60. #include <ODDebug.h>
  61. #endif
  62. #endif // _PLATFORM_WIN32_ _PLATFORM_OS2_ _PLATFORM_AIX_
  63.  
  64. #ifndef _SESSHDR_
  65. #include "SessHdr.h"
  66. #endif
  67.  
  68. #ifndef _INDHDR_
  69. #include "IndHdr.h"
  70. #endif
  71.  
  72. #ifndef _ODMEMORY_
  73. #include "ODMemory.h"
  74. #endif
  75.  
  76. #ifndef _FLIPEND_
  77. #include "FlipEnd.h"
  78. #endif
  79.  
  80. #ifndef __CM_API__
  81. #include "CMAPI.h"
  82. #endif
  83.  
  84. #ifndef som_xh
  85. #include "som.xh"
  86. #endif
  87.  
  88. #include <stddef.h>
  89. #include <stdlib.h>
  90. #include <stdio.h>
  91. #include <string.h>
  92. #include <errno.h>
  93. #include <stdarg.h>
  94.  
  95. #ifndef _FILECTR_
  96. #include "FileCtr.xh"
  97. #endif
  98.  
  99. //==============================================================================
  100. // Constants
  101. //==============================================================================
  102.  
  103. const CMGlobalName kODIndirectValueGlobalName = "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Bento Container Suite:Type:IndirectValue";
  104. const ODType    kODEmbeddedContainerProperty = "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Bento Container Suite:Property:EmbeddedContainer";
  105. const ODType    kODEmbeddedContainerType = "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Bento Container Suite:Type:EmbeddedContainer";
  106.  
  107. //==============================================================================
  108. // Scalar Types
  109. //==============================================================================
  110. typedef struct {
  111.     CMValue        targetValue;
  112.     CMSession    sessionData;
  113.     ODType        objectName;
  114. } IndirectValueRefCon;
  115. typedef IndirectValueRefCon *IndirectValueRefConPtr;
  116.  
  117. //------------------------------------------------------------------------------
  118. // For IndirectValueMetahandler
  119. //------------------------------------------------------------------------------
  120.     CM_CFUNCTIONS
  121.  
  122.  static CMHandlerAddr IndirectValueMetahandler(CMType targetType, const CMGlobalName operationType);
  123.                                                     
  124.  static CMSize getValueSize_Handler(CMValue value);
  125.  static CMSize readValueData_Handler(CMValue value, CMPtr buffer, CMCount offset, CMSize maxSize);
  126.  static void writeValueData_Handler(CMValue value, CMPtr buffer, CMCount offset, CMSize size);
  127.  static void insertValueData_Handler(CMValue value, CMPtr buffer, CMCount offset, CMSize size);
  128.  static void deleteValueData_Handler(CMValue value, CMCount offset, CMSize size);
  129.  static void getValueInfo_Handler(CMValue value, CMContainer *container, CMObject *object,
  130.                                                                     CMProperty *property, CMType *type, 
  131.                                                                     CMGeneration *generation);
  132.  static void setValueType_Handler(CMValue value, CMType type);
  133.  static void setValueGeneration_Handler(CMValue value, CMGeneration generation);
  134.  static void releaseValue_Handler(CMValue value);
  135.                                                                   
  136. //------------------------------------------------------------------------------
  137. // For IndirectDynamicValueMetahandler
  138. //------------------------------------------------------------------------------
  139.  
  140.  static CMMetaData metaData_Handler(CMType type);
  141.  static CMBoolean newValue_Handler(CMValue dynamicBaseValue, 
  142.                                      CMType type,
  143.                                      CMDataPacket dataPacket);
  144.  static CMBoolean useValue_Handler(CMValue dynamicBaseValue,
  145.                                      CMType type,
  146.                                      CMMetaHandler *metahandler,
  147.                                     CMRefCon *refCon);
  148.     CM_END_CFUNCTIONS
  149.  
  150.  
  151. //==============================================================================
  152. // IndirectDynamicValueMetahandler
  153. //==============================================================================
  154.                                                                                                                                                                                  
  155. CMHandlerAddr CM_FIXEDARGS IndirectDynamicValueMetahandler(CMType targetType, CMconst_CMGlobalName operationType)
  156. {
  157.     CMType ignored = targetType;
  158.     
  159.     if (strcmp((ODSByte*) operationType, CMDefineMetaDataOpType)==0)
  160.         return ((CMHandlerAddr) metaData_Handler);
  161.     else if (strcmp((ODSByte*) operationType, CMNewValueOpType) == 0)
  162.         return ((CMHandlerAddr) newValue_Handler);
  163.     else if (strcmp((ODSByte*) operationType, CMUseValueOpType) == 0)
  164.         return ((CMHandlerAddr) useValue_Handler);
  165.     else                                                                                                            
  166.         return (kODNULL);
  167. }
  168.  
  169. //------------------------------------------------------------------------------
  170. // metaData_Handler
  171. //------------------------------------------------------------------------------
  172.  
  173. static CMMetaData metaData_Handler(CMType type)
  174. {
  175.     CMType unused = type;
  176.     
  177.     return ((CMMetaData)"%p(=remoteObject)");    
  178. }
  179.  
  180. //------------------------------------------------------------------------------
  181. // newValue_Handler
  182. //------------------------------------------------------------------------------
  183.  
  184. static CMBoolean newValue_Handler(CMValue dynamicBaseValue, CMType type, CMDataPacket dataPacket)
  185. {
  186.     CMContainer    container   = CMGetObjectContainer(type);
  187.     CMSession    sessionData = CMGetSession(container);
  188.     CMCount     i;    
  189.     ODType        objectName;
  190.     ODULong        objectNameSize, stdNameSize;
  191.         
  192.     i = CMScanDataPacket(type, metaData_Handler(type), dataPacket, &objectName);
  193.     
  194.     if (i != 1) {
  195.         CMError(sessionData,
  196.                 "Unable to get all of CMNewValue()'s parameter in container \"^0\"",
  197.                 CMReturnContainerName(container));
  198.         return (kODFalse);
  199.     }
  200.     
  201.     if (objectName == kODNULL) {
  202.         objectNameSize = 0;
  203.     }
  204.     else {
  205.         objectNameSize = strlen(objectName) + 1;
  206.     }
  207.     stdNameSize = ConvertODULongToStd(objectNameSize);
  208.     CMWriteValueData(dynamicBaseValue, &stdNameSize, 0, sizeof(ODULong));
  209.     if (objectName == kODNULL)
  210.         CMWriteValueData(dynamicBaseValue, "", sizeof(ODULong), 1);
  211.     else
  212.         CMWriteValueData(dynamicBaseValue, objectName, sizeof(ODULong), objectNameSize);
  213.     
  214.     return (kODTrue);
  215. }
  216.  
  217.  
  218. //------------------------------------------------------------------------------
  219. // useValue_Handler
  220. //------------------------------------------------------------------------------
  221.  
  222. static CMBoolean useValue_Handler(CMValue dynamicBaseValue,
  223.                                 CMType type,
  224.                                 CMMetaHandler *metahandler,
  225.                                 CMRefCon *refCon)
  226. {
  227.     CMContainer              container      = CMGetObjectContainer(type);
  228.     CMSession                sessionData = CMGetSession(container);
  229.     IndirectValueRefConPtr    myRefCon;
  230.     CMProperty                targetProperty,
  231.                             embeddedContainerProperty;
  232.     CMType                    embeddedContainerType;
  233.     CMObject                targetObject;
  234.     CMValue                    targetValue;
  235.     ODULong                objectNameSize;
  236.     ODFileContainer*        parentContainer;
  237.     ODSessionRefCon*        sessionRefCon;
  238.  
  239.     sessionRefCon = (ODSessionRefCon*) CMGetSessionRefCon(container);
  240.     if (sessionRefCon == kODNULL)
  241.         WARNMSG(WARN_INDEX(AMSG_360),"No Session.");
  242.  
  243.     objectNameSize = CMGetValueSize(dynamicBaseValue);
  244.     if (objectNameSize < sizeof(ODULong)) {
  245.         CMError(sessionData, 
  246.             "Incorrect byte length read while reading indirect value data in container \"^0\"", 
  247.             CMReturnContainerName(container));
  248.         return (kODFalse);
  249.     }
  250.     else
  251.         objectNameSize -= sizeof(ODULong);
  252.     
  253.     /* Allocate the refCon that we will pass among the handlers.  Since we are doing a        */
  254.     /* dynamic allocation here we will use the "malloc" handler defined for the container.*/
  255.     
  256.     myRefCon = (IndirectValueRefConPtr) ODNewPtr(sizeof(IndirectValueRefCon), sessionRefCon->heap);
  257.     
  258.     myRefCon->objectName = (ODType) ODNewPtr(objectNameSize, sessionRefCon->heap);
  259.     if (CMReadValueData(dynamicBaseValue, myRefCon->objectName, sizeof(ODULong), objectNameSize) != objectNameSize) {
  260.         CMError(sessionData, 
  261.             "Incorrect byte length read while reading indirect value data in container \"^0\"", 
  262.             CMReturnContainerName(container));
  263.         return (kODFalse);
  264.     }
  265.     
  266.     myRefCon->sessionData = sessionData;                                /* save the current session ptr        */
  267.         
  268.     parentContainer = (ODFileContainer*) sessionRefCon->container;
  269.     if (parentContainer == kODNULL)
  270.         WARNMSG(WARN_INDEX(AMSG_370),"No File Container.");
  271.         
  272.     Environment* ev = somGetGlobalEnvironment();
  273.     targetProperty = CMRegisterProperty(parentContainer->GetCMContainer(ev), myRefCon->objectName);
  274.     embeddedContainerProperty = CMRegisterProperty(parentContainer->GetCMContainer(ev), kODEmbeddedContainerProperty);
  275.     embeddedContainerType = CMRegisterType(parentContainer->GetCMContainer(ev), kODEmbeddedContainerType);
  276.     targetObject = CMGetNextObjectWithProperty(parentContainer->GetCMContainer(ev), kODNULL, targetProperty);
  277.     targetValue = CMUseValue(targetObject, embeddedContainerProperty, embeddedContainerType);
  278.     
  279.     if (targetValue != kODNULL)
  280.         myRefCon->targetValue = targetValue;
  281.     else
  282.         WARNMSG(WARN_INDEX(AMSG_380),"No target value.");
  283.         
  284.     *metahandler = (CMMetaHandler) IndirectValueMetahandler;            /* return metahandler            */
  285.     *refCon    = (CMRefCon) myRefCon;                                        /* ...and refCon                */
  286.         
  287.     return (kODTrue);
  288. }
  289.  
  290. //==============================================================================
  291. // IndirectValueMetahandler
  292. //==============================================================================
  293.  
  294. static CMHandlerAddr IndirectValueMetahandler(CMType targetType, const CMGlobalName operationType)
  295. {
  296.     static char *operationTypes[] = {CMGetValueSizeOpType,            /* 0 */ /* Operation Types    */
  297.                                         CMReadValueDataOpType,        /* 1 */
  298.                                          CMWriteValueDataOpType,        /* 2 */
  299.                                         CMInsertValueDataOpType,    /* 3 */
  300.                                         CMDeleteValueDataOpType,    /* 4 */
  301.                                         CMGetValueInfoOpType,        /* 5 */
  302.                                         CMSetValueTypeOpType,        /* 6 */
  303.                                         CMSetValueGenOpType,        /* 7 */
  304.                                         CMReleaseValueOpType,        /* 8 */
  305.                                         NULL};
  306.     char      **t;
  307.     CMType ignored = targetType;
  308.     
  309.     /* Look up the operation type in the operationTypes table above...    */
  310.     
  311.     t = operationTypes - 1;
  312.     while (*++t) if (strcmp((char *)operationType, *t) == 0) break;
  313.  
  314.     /* Now that we got it (hopefully), return the appropriate routine address...*/
  315.     
  316.     switch (t - operationTypes) {
  317.         case  0:    return ((CMHandlerAddr)getValueSize_Handler);        /* CMGetValueSizeOpType     */
  318.         case  1:    return ((CMHandlerAddr)readValueData_Handler);        /* CMReadValueDataOpType     */
  319.         case  2:    return ((CMHandlerAddr)writeValueData_Handler);        /* CMWriteValueDataOpType */
  320.         case  3:    return ((CMHandlerAddr)insertValueData_Handler);    /* CMInsertValueDataOpType*/
  321.         case  4:    return ((CMHandlerAddr)deleteValueData_Handler);    /* CMDeleteValueDataOpType*/
  322.         case  5:    return (NULL);/* use inherited handler or API */    /* CMGetValueInfoOpType     */
  323.         case  6:    return (NULL);/* use inherited handler or API */    /* CMSetValueTypeOpType     */
  324.         case  7:    return (NULL);/* use inherited handler or API */    /* CMSetValueGenOpType         */
  325.         case  8:    return ((CMHandlerAddr)releaseValue_Handler);        /* CMReleaseValueOpType     */
  326.         
  327.         default:    return (NULL);
  328.     }
  329. }
  330.  
  331. //------------------------------------------------------------------------------
  332. // getValueSize_Handler
  333. //------------------------------------------------------------------------------
  334. static CMSize getValueSize_Handler(CMValue value)
  335. {
  336.     IndirectValueRefConPtr    myRefCon = (IndirectValueRefConPtr) CMGetValueRefCon(value);
  337.  
  338.     return (CMGetValueSize(myRefCon->targetValue));
  339. }
  340.  
  341.  
  342. //------------------------------------------------------------------------------
  343. // readValueData_Handler
  344. //------------------------------------------------------------------------------
  345. static CMSize readValueData_Handler(CMValue value, CMPtr buffer, CMCount offset, CMSize maxSize)
  346. {
  347.     IndirectValueRefConPtr    myRefCon = (IndirectValueRefConPtr) CMGetValueRefCon(value);
  348.     
  349.     return CMReadValueData(myRefCon->targetValue, buffer, offset, maxSize);
  350. }
  351.  
  352.  
  353. //------------------------------------------------------------------------------
  354. // writeValueData_Handler
  355. //------------------------------------------------------------------------------
  356. static void writeValueData_Handler(CMValue value, CMPtr buffer, CMCount offset, CMSize size)
  357. {
  358.     IndirectValueRefConPtr    myRefCon = (IndirectValueRefConPtr) CMGetValueRefCon(value);
  359.     
  360.     CMWriteValueData(myRefCon->targetValue, buffer, offset, size);
  361. }
  362.  
  363.  
  364. //------------------------------------------------------------------------------
  365. // insertValueData_Handler
  366. //------------------------------------------------------------------------------
  367. static void insertValueData_Handler(CMValue value, CMPtr buffer, CMCount offset, CMSize size)
  368. {
  369.     IndirectValueRefConPtr refCon = (IndirectValueRefConPtr)CMGetValueRefCon(value);
  370.     CMCount                unused1 = offset;
  371.     CMSize                unused2 = size;
  372.     CMPtr                unused3 = buffer;
  373.  
  374.     CMError(refCon->sessionData,
  375.                 "Insertions into an embedded container \"^0\" are not supported",
  376.                 CMReturnContainerName(CMGetValueContainer(value)));
  377. }
  378.  
  379.  
  380. //------------------------------------------------------------------------------
  381. // deleteValueData_Handler
  382. //------------------------------------------------------------------------------
  383. static void deleteValueData_Handler(CMValue value, CMCount offset, CMSize size)
  384. {
  385.     IndirectValueRefConPtr refCon = (IndirectValueRefConPtr)CMGetValueRefCon(value);
  386.     CMCount                unused1 = offset;
  387.     CMSize                unused2 = size;
  388.  
  389.     CMError(refCon->sessionData,
  390.             "Deletions of data in an embedded container \"^0\" are not supported",
  391.             CMReturnContainerName(CMGetValueContainer(value)));
  392. }
  393.  
  394.  
  395. //------------------------------------------------------------------------------
  396. // getValueInfo_Handler
  397. //------------------------------------------------------------------------------
  398. static void getValueInfo_Handler(CMValue value, CMContainer *container, CMObject *object,
  399.                                     CMProperty *property, CMType *type,
  400.                                     CMGeneration *generation)
  401. {    
  402.     CMGetValueInfo(CMGetBaseValue(value), container, object, property, type, generation);
  403. }
  404.  
  405.  
  406. //------------------------------------------------------------------------------
  407. // setValueType_Handler
  408. //------------------------------------------------------------------------------
  409. static void setValueType_Handler(CMValue value, CMType type)
  410. {    
  411.     CMSetValueType(CMGetBaseValue(value), type);
  412. }
  413.  
  414.  
  415. //------------------------------------------------------------------------------
  416. // setValueGeneration_Handler
  417. //------------------------------------------------------------------------------
  418. static void setValueGeneration_Handler(CMValue value, CMGeneration generation)
  419. {
  420.     CMSetValueGeneration(CMGetBaseValue(value), generation);
  421. }
  422.  
  423.  
  424. //------------------------------------------------------------------------------
  425. // releaseValue_Handler
  426. //------------------------------------------------------------------------------
  427. static void releaseValue_Handler(CMValue value)
  428. {
  429.     IndirectValueRefConPtr myRefCon = (IndirectValueRefConPtr)CMGetValueRefCon(value);
  430.     CMSession            sessionData = myRefCon->sessionData;
  431.     
  432.     CMReleaseValue(myRefCon->targetValue);
  433.     if (myRefCon != kODNULL) {
  434.         if (myRefCon->objectName != kODNULL)
  435.             ODDisposePtr(myRefCon->objectName);
  436.         ODDisposePtr(myRefCon);
  437.     }
  438. }
  439.