home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.8 KB | 315 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLResour.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWRESFI_K
- #include "FWResFil.k"
- #endif
-
- #ifndef FWRESFI_H
- #include "FWResFil.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- #ifndef FWFILESP_H
- #include "FWFileSp.h"
- #endif
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwresour
- #endif
-
- /*
- * This file was generated by the SOM Compiler.
- * Generated using:
- * SOM Emitter emitxtm.dll: 2.33
- */
-
- #define FW_OResource_Class_Source
- #include "SLResour.xih"
-
- //========================================================================================
- // struct FW_CPrivResourceRep
- // This struct contains the body of the
- //========================================================================================
-
- class FW_CPrivResourceRep
- {
- public:
- FW_DECLARE_AUTO(FW_CPrivResourceRep)
-
- FW_CPrivResourceRep(Environment* ev,
- FW_OResourceFile* file,
- FW_ResourceID resourceID,
- FW_ResourceType resourceType);
-
- ~FW_CPrivResourceRep();
-
- FW_PResourceFile fResourceFile; // The resources file this resource originated from.
- FW_ResourceID fResourceID; // The resource ID of the resource.
- FW_ResourceType fResourceType; // The type of the resource.
- FW_ResourceHandle fResourceHandle; // The native resource handle.
- unsigned long fResourceSize; // The size of the resource, in bytes.
-
- #ifdef FW_BUILD_MAC
- unsigned short fLockCount; // Incremented by GetData, decremented by ReleaseData
- FW_PlatformHandle fResourceData; // Resource data is stored here.
- #endif
-
- #ifdef FW_BUILD_WIN
- HGLOBAL fLoadedHandle;
- #endif
- };
-
-
- FW_DEFINE_AUTO(FW_CPrivResourceRep)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivResourceRep::FW_CPrivResourceRep
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivResourceRep::FW_CPrivResourceRep(Environment* ev,
- FW_OResourceFile* file,
- FW_ResourceID resourceID,
- FW_ResourceType resourceType) :
- fResourceFile(ev, file),
- fResourceID(resourceID),
- fResourceType(resourceType),
- fResourceHandle(0)
- {
- #ifdef FW_BUILD_MAC
- fLockCount = 0;
- fResourceData = 0;
- {
- FW_CMacResLoadFalse dontLoadResource;
- fResourceHandle = fResourceFile->GetResourceHandle(ev, fResourceID, fResourceType);
- }
- #elif defined FW_BUILD_WIN
- fResourceHandle = fResourceFile->GetResourceHandle(ev, fResourceID, fResourceType);
- #endif
-
- #if defined FW_BUILD_MAC
- fResourceSize = ::GetResourceSizeOnDisk(fResourceHandle);
- #elif defined FW_BUILD_WIN
- fResourceSize = ::SizeofResource(fResourceFile->PrivGetResourceFileID(ev), fResourceHandle);
- #endif
-
- FW_END_CONSTRUCTOR
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivResourceRep::~FW_CPrivResourceRep
- //----------------------------------------------------------------------------------------
-
- inline FW_CPrivResourceRep::~FW_CPrivResourceRep()
- {
- FW_START_DESTRUCTOR
-
- #ifdef FW_BUILD_MAC
- FW_ASSERT(fLockCount == 0);
- if (fResourceData != 0)
- FW_CMemoryManager::FreeSystemHandle(fResourceData);
- #endif
- FW_SOMEnvironment ev;
- fResourceFile->ReleaseResourceHandle(ev, fResourceHandle);
- }
-
-
- //========================================================================================
- // CLASS FW_OResource
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_OResource__InitFromFile
- // Acquires the resource handle
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OResource__InitFromFile(FW_OResource *somSelf, Environment *ev,
- FW_OResourceFile* file,
- FW_ResourceID resourceID,
- FW_ResourceType resourceType)
- {
- FW_OResourceData *somThis = FW_OResourceGetData(somSelf);
-
- FW_SOM_TRY
- {
- somThis->fRep = FW_NEW(FW_CPrivResourceRep, (ev, file, resourceID, resourceType));
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OResource__AcquireData
- // Lock the resource and return a pointer to the data.
- // Client assumes responsiblity to call ReleaseData.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void* SOMLINK FW_OResource__AcquireData(FW_OResource *somSelf, Environment *ev)
- {
- FW_OResourceData *somThis = FW_OResourceGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_CPrivResourceRep& rep = *somThis->fRep;
- void *result;
-
- FW_ASSERT(rep.fResourceHandle != 0);
- #if defined FW_BUILD_MAC
- FW_ASSERT(rep.fLockCount >= 0);
- if (rep.fLockCount == 0)
- {
- if (rep.fResourceData == 0)
- {
- // ODNewHandle throws kODErrOutOfMemory if it fails
- rep.fResourceData = FW_CMemoryManager::AllocateSystemHandle(rep.fResourceSize);
-
- // Lock the handle, read the resource data
- FW_CMemoryManager::LockSystemHandle(rep.fResourceData);
- ::ReadPartialResource(rep.fResourceHandle, 0, *rep.fResourceData, rep.fResourceSize);
-
- // Throw an exception if the read failed.
- FW_FailOnError(::ResError());
- }
- else
- {
- FW_CMemoryManager::LockSystemHandle(rep.fResourceData);
- }
- }
- ++rep.fLockCount;
- FW_ASSERT(*rep.fResourceData != 0);
- result = *rep.fResourceData;
- #elif defined FW_BUILD_WIN
- rep.fLoadedHandle = ::LoadResource(rep.fResourceFile->PrivGetResourceFileID(ev), rep.fResourceHandle);
- result = ::LockResource(rep.fLoadedHandle);
- #endif
-
- return result;
- }
- FW_SOM_CATCH
-
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OResource__ReleaseData
- // Unlock the resource.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OResource__ReleaseData(FW_OResource *somSelf, Environment *ev)
- {
- FW_OResourceData *somThis = FW_OResourceGetData(somSelf);
-
- FW_SOM_TRY
- {
- FW_CPrivResourceRep& rep = *somThis->fRep;
-
- #if defined FW_BUILD_MAC
- FW_ASSERT(rep.fLockCount > 0);
- if (--rep.fLockCount == 0)
- {
- FW_CMemoryManager::UnlockSystemHandle(rep.fResourceData);
- // (JEL) ??? Should we HPurge too? My feeling is, tell developers they should
- // generally set all resources to purgeable, but allow them to set a resource
- // nonpurgeable for performance reasons. If we always did an HPurge, we take
- // control from the developer, for no good reason.
- }
- #elif defined FW_BUILD_WIN16
- ::UnlockResource(rep.fLoadedHandle);
- #endif
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OResource__GetSize
- // Return the size of this resource in bytes.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope unsigned long SOMLINK FW_OResource__GetSize(FW_OResource *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OResourceData *somThis = FW_OResourceGetData(somSelf);
-
- return somThis->fRep->fResourceSize;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OResource__GetResourceHandle
- // Return the platform (native) handle.
- // This method should be used with caution, since it reveals platform specifics,
- // and allows violation of internal lock counts, etc.
- //----------------------------------------------------------------------------------------
-
- SOM_Scope FW_ResourceHandle SOMLINK FW_OResource__GetResourceHandle(FW_OResource *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OResourceData *somThis = FW_OResourceGetData(somSelf);
-
- return somThis->fRep->fResourceHandle;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OResource__somInit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OResource__somInit(FW_OResource *somSelf)
- {
- FW_OResourceData *somThis = FW_OResourceGetData(somSelf);
-
- // FW_OResource_parent_FW_ORefCount_somInit(somSelf);
-
- somThis->fRep = 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OResource__somUninit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OResource__somUninit(FW_OResource *somSelf)
- {
- FW_OResourceData *somThis = FW_OResourceGetData(somSelf);
-
- FW_SOM_UNINIT_TRY
- {
- delete somThis->fRep;
- // FW_OResource_parent_FW_ORefCount_somUninit(somSelf);
- }
- FW_SOM_UNINIT_CATCH
- }
-
-
-