home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ODDesUtl.cpp
-
- Contains: xxx put contents here xxx
-
- Owned by: Nick Pilch
-
- Copyright:
-
- Change History (most recent first):
-
- <2> .03.1996 NP Added debugging code (turned off).
-
- To Do:
- */
-
- /*
- File: ODDesUtl.cpp
-
- Contains: Implementation of ODDesc<->AEDesc conversion utilities
-
- Owned by: Nick Pilch
-
- Copyright: © 1995 - 1996 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODDESUTL_
- #include <ODDesUtl.h>
- #endif
-
- #ifndef SOM_ODDesc_xh
- #include "ODDesc.xh"
- #endif
-
- #ifndef SOM_Module_OpenDoc_ODRegistry_defined
- #include "ODRgstry.xh"
- #endif
-
- #ifndef _BARRAY_
- #include "BArray.h"
- #endif
-
- #ifndef SOMCorba_h
- #include "somcorba.h"
- #endif
-
-
- //------------------------------------------------------------------------------
- // ODDescToAEDesc
- //------------------------------------------------------------------------------
-
- ODError ODDescToAEDesc(ODDesc* odDesc, AEDesc* aeDesc)
- {
- ODError error = noErr;
- Environment* ev = somGetGlobalEnvironment();
- ODDescType descType = odDesc->GetDescType(ev);
- const DescType randomDescType = 'nick';
-
- TRY
- ODByteArray data;
-
- if (descType == typeNull)
- {
- aeDesc->dataHandle = kODNULL;
- aeDesc->descriptorType = typeNull;
- }
- else
- {
- data = odDesc->GetRawData(ev);
- // CAREFUL HERE! IF YOU CALL AECreateDesc USING typeAEList OR
- // typeAERecord, IT WILL STICK A HEADER ON THE DESCRIPTOR FOR YOU.
- // THAT'S NOT WHAT YOU WANT IN THIS CASE BECAUSE THE ODDESC ALREADY
- // CONTAINS ALL THE RAW DATA INCLUDING THE HEADER. WORK AROUND
- // BY CREATING DESCRIPTOR WITH RANDOM TYPE AND SETTING THE DescType
- // AFTERWORDS.
- THROW_IF_ERROR(AECreateDesc(randomDescType,
- data._buffer, data._length, aeDesc));
- aeDesc->descriptorType = odDesc->GetDescType(ev);
- DisposeByteArrayStruct(data);
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // AEDescToODDesc
- //------------------------------------------------------------------------------
-
- ODError AEDescToODDesc(AEDesc* aeDesc, ODDesc* odDesc)
- {
- ODError error = noErr;
- Environment* ev = somGetGlobalEnvironment();
- Handle dataHandle = aeDesc->dataHandle;
- ODDescType descType = aeDesc->descriptorType;
-
- #define DEBUGGING_ODDESC_LEAKS 0
- #if DEBUGGING_ODDESC_LEAKS
- if (odDesc->GetDescType(ev) == typeUserToken)
- WARN("You are writing into a token, possibly overwriting an ODDesc*.");
- #endif
-
- TRY
- ODByteArray data;
- unsigned long dataSize;
-
- if (dataHandle != kODNULL)
- {
- dataSize = ODGetHandleSize(dataHandle);
- data._buffer = (octet*)ODNewPtr(dataSize);
- ODBlockMove(*(dataHandle), data._buffer, dataSize);
- data._length = dataSize;
- data._maximum = dataSize;
-
- odDesc->SetRawData(ev, &data);
-
- DisposeByteArrayStruct(data);
- }
- odDesc->SetDescType(ev, descType);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #if 0
- ODError AEDescChanged(AEDesc* aeDesc, ODDesc* odDesc)
- {
- // AEDesc* desc = odDesc->GetAEDesc(somGetGlobalEnvironment());
- // WASSERT( desc );
- // *desc = *aeDesc;
- return noErr;
- }
- #endif /* 0 */
-