convert line ends
[canaan.git] / prj / tech / h / resapi.h
blobe0e08d83c64c3c21974958089e6d3fa891882671
1 /////////////////////////////////////////////////////////////////////////////
2 // $Header: x:/prj/tech/libsrc/res2/RCS/resapi.h 1.6 1998/06/29 12:07:52 JUSTIN Exp $
3 //
4 // -------------------
5 // Resource System API
6 // -------------------
7 //
8 // Description of interfaces:
9 //
10 // IResMan
12 // Name-based resource management. Convenience interfaces for
13 // StructuredStorage creation, and LRU maintanance. Allows for
14 // "Type Sets" to be installed, defined by the client, that know
15 // how to create specific IRes implementations based on stream
16 // name (extension), and can implement optional memory and file
17 // loading abilities.
19 // IRes
21 // Typed name-based resources. Maintains lock count, provides
22 // accessors for synchronous/asynchronous loading, extraction.
23 // Talks to resource manager for named resource-raw data LRU
24 // association. A StorageFactory may create client-specific
25 // implementations to do special loading/memory management.
26 // Mutiple instances may exist for a given resource - mixed or
27 // same resource interpretation, but the Resource Manager will
28 // only keep one instance of the raw data.
30 // IResType
32 // Defines a specific "type" of data. You create an IRes from an
33 // IResType, and the type remains associated with the IRes.
35 // IResMemOverride
37 // An optional interface that can be attached to an IRes aggregate
38 // when IResFactory creates it. Provides special memory handling
39 // abilities.
43 #ifndef __RESAPI_H
44 #define __RESAPI_H
46 #include <lg.h>
47 #include <comtools.h>
50 // We include the old resource system mainly due to a naming conflict;
51 // if res.h is to be included, it has to come before resapi.h.
53 // @TBD: we should fix this, by removing the naming conflict. Both res and
54 // resapi define "sResMemStats". We should probably change the name here...
56 #include <res.h>
58 #pragma once
59 #pragma pack(4)
61 F_DECLARE_INTERFACE(IResMan);
62 F_DECLARE_INTERFACE(IRes);
63 F_DECLARE_INTERFACE(IResStore);
64 F_DECLARE_INTERFACE(IResType);
65 F_DECLARE_INTERFACE(IResMemOverride);
66 F_DECLARE_INTERFACE(IStore);
67 F_DECLARE_INTERFACE(IStoreHierarchy);
68 F_DECLARE_INTERFACE(IStoreFactory);
69 F_DECLARE_INTERFACE(IStoreManager);
70 F_DECLARE_INTERFACE(IStoreStream);
71 F_DECLARE_INTERFACE(ISearchPath);
73 // Sorry, can't mix old 16-bit Windows API and this API
74 #undef UnlockResource
76 ///////////////////////////////////////////////////////////////////////////////
78 // Create the resource system and add it to the global app-object
81 #define Res2Create() \
82 { \
83 IUnknown * pAppUnknown = AppGetObj(IUnknown); \
84 _Res2Create(IID_TO_REFIID(IID_IResMan), NULL, pAppUnknown); \
85 COMRelease(pAppUnknown); \
89 // Creates a Resource Manager, aggregating it with specfied pOuter,
91 EXTERN tResult LGAPI
92 _Res2Create(REFIID, IResMan ** ppResMan, IUnknown * pOuter);
95 ///////////////////////////////////////////////////////////////////////////////
97 // Callback types
100 ///////////////////////////////////////
102 // Async lock callback
104 // When callback is called, pResource is *not* locked for client,
105 // so client should not release. pResource will be AddRef'd by
106 // Async system, then released after this callback is made. If an
107 // Extract was requested, the buffer originally given will be
108 // passed back, and size will be that passed in.
110 // @TBD (justin, 5-18-98): It would be nice to return the actual size
111 // of the data here, but that will take some mucking deep in
112 // cResARQFulfiller. At least DoFulfill needs to be changed, and it
113 // needs some way to find out what the actual loaded size was. For now,
114 // the caller should be able to find out the answer from IRes::GetSize.
116 typedef void (*tResAsyncCallback)(IRes * pResource,
117 void * pData,
118 ulong nBufSize,
119 void * pClientData);
121 ///////////////////////////////////////
123 // Block extraction callback
125 // pResource is NOT AddRef'd. Like IStream, returns buffer, bytes, and block index
128 typedef long (*tResBlockCallback)(IRes * pResource,
129 void * pBuf,
130 long nNumBytes,
131 long nIx,
132 void * pClientData);
134 ///////////////////////////////////////
136 // Resource from a storage callback.
138 // This is called by IResMan::PrepAllResources; it is called once for
139 // each resource found in the given storage. It is up to this callback
140 // to decide whether it is interested in the resource, and to Lock it
141 // if so.
143 typedef void (*tStoredResCallback)(IRes *pRes,
144 IStore *pStore,
145 void *pClientData);
147 ///////////////////////////////////////
149 // The callback from IResType::EnumerateExts().
151 typedef void (*tResEnumExtsCallback)(const char *pExt,
152 IResType *,
153 void *pClientData);
155 ///////////////////////////////////////////////////////////////////////////////
157 // Statistics
160 enum eResStatMode
162 kResStats_Off,
163 kResStats_On,
164 kResStats_Verbose,
166 kResStats_IntMax = 0xffffffff // ensure 32 bits
170 typedef enum eResStatMode eResStatMode;
172 ///////////////////////////////////////
174 // This structure is also defined in "res.h", so we only bother to define
175 // it if it isn't already defined. Implication: res.h should be #included
176 // before resapi.h.
178 #ifndef __RES_H
179 typedef struct sResMemStats
181 ulong reserved;
183 // From Windows:
184 ulong memoryLoad; // percent of memory in use
185 ulong totalPhys; // bytes of physical memory
186 ulong availPhys; // free physical memory bytes
187 ulong totalPageFile; // bytes of paging file
188 ulong availPageFile; // free bytes of paging file
189 ulong totalVirtual; // user bytes of address space
190 ulong availVirtual; // free user bytes
192 // From Resource system
193 ulong allocCap;
194 ulong totalMalloc;
195 ulong lockedMalloc;
196 ulong cachedMalloc;
198 } sResMemStats;
199 #endif
201 ///////////////////////////////////////
204 // Flags for MakeResource
206 #define RES_IS_STATIC 0x01
208 ///////////////////////////////////////////////////////////////////////////////
210 // INTERFACE: IResMan
212 // Weakness: Association between IRes implemenations and installed types.
214 // Multiple calls to "Open" with the same file will create new
215 // instances of an IStore - its up to the IStoreFactory
216 // implementation to ensure this. There is transient data
217 // associated with a StructuredStorage in the form of the storage
218 // name and location.
221 #undef INTERFACE
222 #define INTERFACE IResMan
224 DECLARE_INTERFACE_(IResMan, IUnknown)
227 // IUnknown methods
229 DECLARE_UNKNOWN_PURE();
232 // Get a new, empty ISearchPath, which can be set up to look for
233 // resources along.
235 STDMETHOD_(ISearchPath *, NewSearchPath)(THIS) PURE;
238 // Set the default search path to be used for opening storages.
239 // This can be ignored if you always pass in explicit paths to
240 // the appropriate methods. This will make a *reference* to the
241 // given path; changes to the path will be immediately reflected.
242 // Clear the default path by calling this with NULL.
244 STDMETHOD_(void, SetDefaultPath)(THIS_ ISearchPath *pPath) PURE;
247 // Given the name of a resource file, this loads that file in, and
248 // returns the resulting resource. If a search path is specified, that
249 // will be searched for the resource; otherwise, the default will be
250 // used. The given name may have a directory path relative to the given
251 // search path. If you know that a resource has already been found and
252 // loaded (or want to test that), call PrepResource with neither a path
253 // nor a default path. It will return the already-loaded resource if it
254 // is found, or NULL if it hasn't been loaded.
256 // Prepping a resource involves two steps: getting the storage that it
257 // is contained within, and binding the resource within that storage.
258 // If you need finer-grained control over the process, use the GetStore
259 // and MakeResource methods below. After the resource is bound, you may
260 // Lock it when you actually want to get at its data.
262 // Note that only one resource with any given name will be found by
263 // the resource system; it assumes a flat namespace.
265 // Returns the IRes if it could be found and loaded, or NULL if not.
267 STDMETHOD_(IRes *, PrepResource) (THIS_
268 const char *resName,
269 ISearchPath *pPath) PURE;
272 // Similar to PrepResource, but allows you to specify the type desired,
273 // and does not require that the resource's extension be specified. This
274 // is mostly a sop to Dark, which internally mostly doesn't have the
275 // file extensions. This will try finding the named resource, using all
276 // of the valid extensions for the given type. However, PrepResource is
277 // probably a little faster.
279 STDMETHOD_(IRes *, PrepTypedResource) (THIS_
280 const char *resName,
281 const char *typeName,
282 ISearchPath *pPath) PURE;
285 // Prepare all of the resources whose names match the given pattern,
286 // found along the given path. If the pattern is NULL, then prep all
287 // resources.
289 // For each resource found, the given callback will be called. It is
290 // up to that callback to Lock the resource if it is interested in it;
291 // no guarantees are made that the storage or resource will be kept
292 // around afterward otherwise. Note that the resource will not necessarily
293 // be loaded into memory at this point; it will be just as if PrepResource
294 // had been called on it.
296 // pClientData is a pointer to arbitrary memory, and can be used by
297 // the caller to pass information through to the callback.
299 STDMETHOD_(void, PrepAllResources) (THIS_
300 const char *pPattern,
301 ISearchPath *pPath,
302 tStoredResCallback,
303 void *pClientData) PURE;
306 // Same as PrepAllResource, but it will only find resources of the
307 // specified type.
309 STDMETHOD_(void, PrepAllTypedResources) (THIS_
310 const char *pPattern,
311 ISearchPath *pPath,
312 const char *pTypeName,
313 tStoredResCallback,
314 void *pClientData) PURE;
317 // Given a storage to look into, and the name of a stream, this will
318 // get a resource corresponding to that stream. It will make a
319 // best-guess of what IResType is appropriate for that resource
320 // (based on its name), and create an IRes for it. Note that this
321 // does not necessarily actually load the resource into memory; you
322 // cannot count on having it in memory until after you Lock it.
324 // MakeResource can take flags controlling its behaviour. Currently,
325 // the only flag allowed is RES_IS_STATIC. If this is set, then this
326 // resource will be fixed to the given storage; if not, the resource
327 // could be rebound to a different storage later.
329 // This will return an IRes, even if the named resource doesn't actually
330 // exist in storage. However, in such a case, IRes->Lock will return null.
332 STDMETHOD_(IRes *, MakeResource) (THIS_
333 IStore *pStore,
334 const char *pName,
335 const uint fBindFlags) PURE;
338 // This is the same as MakeResource, except that instead of simply
339 // binding to the default resource type for the named stream, it will
340 // bind it to the named type, assuming that that type is registered.
341 // This allows a single stream to serve many different resource types.
343 STDMETHOD_(IRes *, MakeTypedResource) (THIS_
344 IStore *pStore,
345 const char *pName,
346 const char *pTypeName,
347 const uint fBindFlags) PURE;
350 // This takes an existing IRes, and creates a new one with the same
351 // underlying stream, but the specified type.
353 STDMETHOD_(IRes *, MakeRetypedResource) (THIS_
354 IRes *pOldRes,
355 const char *pTypeName,
356 const uint fBindFlags) PURE;
359 // Tries to get the named storage. To get a storage along a search path,
360 // use ISearchPath::Find instead. Returns NULL if this storage can't be
361 // found.
363 // Note that this is mainly a convenience method; any IStore may be
364 // used to make resources with.
366 STDMETHOD_(IStore *, GetStore) (THIS_
367 const char *pPathName) PURE;
369 ////////////////////////////////////
371 // IStores are created through an IStoreFactory which is registered
372 // here; it decides which Factory to use based on the extension of the
373 // file. Similarly, IRes are created through an IResType, which is
374 // registered based on the extensions it understands.
376 // If multiple factories understand the same extension, the last one
377 // registered will be used to create the IStore/IRes.
379 // There is a default "type", called "RawBinary"; if we try to open a
380 // resource that has no registered type, we will use that default
381 // for it. This provides only very simplistic capabilities. Similarly,
382 // there is a default storage factory that deals with ordinary
383 // filesystem directories.
385 // Returns FAILED iff the given factory is invalid or unuseable; otherwise
386 // returns SUCCEEDED.
388 STDMETHOD_(BOOL, RegisterResType) (THIS_ IResType *) PURE;
389 STDMETHOD_(BOOL, RegisterStoreFactory) (THIS_ IStoreFactory *) PURE;
392 // Unregister a factory. Note that storage factories cannot currently
393 // be unregistered.
395 STDMETHOD_(void, UnregisterResType) (THIS_ IResType *) PURE;
397 //////////
399 // Refetch methods
401 // These methods are intended only in cases where we believe that a
402 // particular resource in memory is somehow "dirty" -- that it is no
403 // longer an accurate reflection of the state of the stream on disk.
404 // "Rebind" means that we should attempt to look this resource up
405 // again (usually in cases where a new copy has been added earlier on
406 // the path, or the one that was previously found has been deleted).
407 // "Reload" means that we should use the same stream, but we should
408 // load it into memory again (either because it has changed on disk,
409 // or the in-memory version has been corrupted).
413 // Notes that any version of this resource currently found in the LRU
414 // is now dirty; if we need this resource again, fetch it once more
415 // from storage. Useful if you have reason to believe that the resource
416 // has changed in storage, or if the in-memory version has become
417 // corrupt. This will mark all resources based on the named stream,
418 // if there are more than one.
420 STDMETHOD_(void, MarkForReload) (THIS_
421 const char *pName,
422 ISearchPath *pPath) PURE;
425 // Same as MarkForReload, except that it takes the
426 // actual resource itself. Will generally be faster, since less lookup
427 // is needed. Only marks the given resource, though, not any others
428 // from the same stream.
430 STDMETHOD_(void, MarkForReloadRes) (THIS_ IRes * pRes) PURE;
433 // Notes that any previously-found stream by this name along the path
434 // should be ignored, and that we should look it up again. This will
435 // not take effect until all locks are cleared; after that, the next
436 // lock will cause the rebind to occur. This will rebind all
437 // resources based on the named stream, if there are more than one.
439 STDMETHOD_(void, MarkForRebind) (THIS_
440 const char *pName,
441 ISearchPath *pPath) PURE;
444 // Same as MarkForRebind, but takes a single specific resource to
445 // rebind. Will generally be faster, since less lookup is needed.
446 // Takes the path, so we know where to rebind from. This will only
447 // rebind the given resource (and other resources of the same type,
448 // using the same data), not other resources of other types from
449 // the same stream.
451 STDMETHOD_(void, MarkForRebindRes) (THIS_
452 IRes * pRes,
453 ISearchPath *pPath) PURE;
456 //////////////////////////////////////////////////////////////////////
458 // INTERFACE: IResStats
460 // This interface is optionally available from IResMan; if available, it
461 // provides various statistics about the Resource Manager.
464 #undef INTERFACE
465 #define INTERFACE IResStats
467 DECLARE_INTERFACE_(IResStats, IUnknown)
470 // IUnknown methods
472 DECLARE_UNKNOWN_PURE();
475 // Enable stat tracking.
477 STDMETHOD_(void, EnableStats) (THIS_ const eResStatMode) PURE;
480 // Dump stats into given file, or monolog if none.
482 STDMETHOD_(void, DumpStats) (THIS_ const char *pFile) PURE;
485 //////////////////////////////////////////////////////////////////////
487 // INTERFACE: IResMem
489 // This interface controls the memory-management policies of the
490 // Resource Manager.
493 #undef INTERFACE
494 #define INTERFACE IResMem
496 DECLARE_INTERFACE_(IResMem, IUnknown)
499 // IUnknown methods
501 DECLARE_UNKNOWN_PURE();
504 // Enable paging.
506 STDMETHOD_(void, EnablePaging) (THIS_ BOOL) PURE;
509 // Flush the cache, cleanup the heap.
511 STDMETHOD_(void, Compact) (THIS) PURE;
514 // Get Resource Mem stats
516 STDMETHOD_(void, GetMemStats) (THIS_ sResMemStats *) PURE;
519 ///////////////////////////////////////////////////////////////////////////////
521 // INTERFACE: IRes
524 #undef INTERFACE
525 #define INTERFACE IRes
527 #define NO_RES_APP_DATA -1
529 DECLARE_INTERFACE_(IRes, IUnknown)
532 // IUnknown methods
534 DECLARE_UNKNOWN_PURE();
537 // Returns the type for this resource; use this to get the type name,
538 // and translators.
540 STDMETHOD_(IResType *, GetType) (THIS) PURE;
543 // Returns resource file name only.
545 STDMETHOD_(const char *, GetName)(THIS) PURE;
547 ////////////////////////////////////
549 // Raw data operations
553 // Will look in LRU or will load. Allocates buff.
554 // Returns NULL if for some reason it can't lock this resource. (Eg, it
555 // doesn't exist in storage.)
557 STDMETHOD_(void *, Lock)(THIS) PURE;
560 // Decrement lock count
562 STDMETHOD_(void, Unlock)(THIS) PURE;
565 // Remove from memory. Blow LRU for this. TRUE if success.
566 // FALSE if resource is locked.
568 STDMETHOD_(BOOL, Drop)(THIS) PURE;
571 // Query the size
573 STDMETHOD_(long, GetSize)(THIS) PURE;
576 // Extract into memory.
578 STDMETHOD_(void *, Extract)(THIS_ void * pBuf) PURE;
581 // Grab data, allocate, rework as needed. Will get used by resource
582 // manager to load raw data.
584 STDMETHOD_(void *, LoadData)(THIS_ ulong * pSize,
585 IResMemOverride * pResMem) PURE;
588 // Get data into memory (LRU). If already there, makes data
589 // most-recently-used.
591 STDMETHOD_(void *, PreLoad)(THIS) PURE;
594 // Grab data from file. If data already loaded for this resource,
595 // no file ops are done. Else, if associated stream is not already
596 // opened, then the stream is opened, data read, then stream
597 // closed. If stream is already open via 'OpenStream', then that
598 // stream is used, and not closed until explicitly closed via
599 // 'CloseStream'. Returns number of bytes extracted
601 STDMETHOD_(int, ExtractPartial)(THIS_
602 const long nStart,
603 const long nEnd,
604 void *pBuf)
605 PURE;
608 // Extract this resource, one block at a time, passing each block to
609 // the specified callback method. The blocks are placed in the given
610 // buffer; it is the caller's responsibility to manage that buffer.
612 // @param pBuf A buffer in which to place each block, which will be
613 // passed to the callback.
614 // @param nSize The size of that buffer, in bytes.
615 // @param callback A routine to call each time a block is loaded into
616 // the buffer.
617 // @param pCallbackData Some arbitrary data which will be passed to the
618 // callback, for the caller to use as it sees fit.
620 STDMETHOD_(void, ExtractBlocks)(THIS_
621 void *pBuf,
622 const long nSize,
623 tResBlockCallback,
624 void *pCallbackData)
625 PURE;
628 // Opens a stream using the IStore and resource name that were
629 // established already.
631 STDMETHOD_(IStoreStream *, OpenStream)(THIS) PURE;
633 ////////////////////////////////////
635 // Translation methods
637 // A resource may be able to obtain its data from other, already-loaded
638 // resources based on the same underlying stream. The issue is whether
639 // this type knows how to translate the data from another existing look
640 // at this data, in some other type.
643 // Returns an array of strings, with the names of types that this one
644 // knows how to translate from. Places the size of the array in
645 // pnTypes.
647 // @NOTE: This used to be GetProxiedTypes, with a different signature.
649 STDMETHOD_(char **, GetTranslatableTypes)(THIS_
650 /* OUT */ int *pnTypes) PURE;
653 // Load this resource from the given data block, which is from another
654 // resource. Analogous to LoadData in many ways. The parameters are:
656 // pOldData -- An existing block of data
657 // nOldSize -- The size of that old data block
658 // pOldTypeName -- The name of the type of that old data
659 // pAllocated -- Will return TRUE iff we allocated fresh memory for
660 // this resource, FALSE iff we are simply pointing to the old,
661 // given data block
662 // pSize -- Will return the size of the new data for this resource
663 // pResMem -- Will be used to allocate the new memory space, if
664 // any allocation is needed
666 // The method returns a pointer to the new data block for this resource.
667 // It will return NULL if something goes wrong. (For instance, if we don't
668 // know how to translate from the given data type.)
670 // @NOTE: This used to be LoadProxiedData, with a different signature.
672 STDMETHOD_(void *, LoadTranslation)(THIS_
673 void *pOldData,
674 long nOldSize,
675 const char *pOldTypeName,
676 /* OUT */ BOOL *pAllocated,
677 /* OUT */ ulong *pSize,
678 IResMemOverride *pResMem) PURE;
680 ////////////////////////////////////
682 // Async operations
686 // Lock (that is, read in and get the data for) the given resource
687 // asynchronously, calling the given callback when it is ready.
689 // Priority is a 'prikind.h' priority.
691 // pClientData is a pointer to arbitrary memory, which will be passed
692 // on to the callback. It may be used as desired by the caller, and may
693 // be null.
695 STDMETHOD_(BOOL, AsyncLock)(THIS_
696 const int nPriority,
697 tResAsyncCallback Callback,
698 void *pData) PURE;
700 // Similar to AsyncLock, but place the data into the given buffer.
701 // Memory management on this buffer is up to the caller.
703 STDMETHOD_(BOOL, AsyncExtract)(THIS_
704 const int nPriority,
705 void *pBuf,
706 const long bufSize,
707 tResAsyncCallback Callback,
708 void *pData) PURE;
710 // Similar to AsyncLock, but doesn't actually lock the Resource, just
711 // loads it in on the assumption that it'll get locked Real Soon Now.
712 // Assumed to be low-priority.
714 STDMETHOD_(BOOL, AsyncPreload)(THIS_
715 tResAsyncCallback Callback,
716 void *pData) PURE;
718 // Returns TRUE if async request has been fulfilled.
720 STDMETHOD_(BOOL, IsAsyncFulfilled)(THIS) PURE;
722 // Kills async request associated with this resource.
724 STDMETHOD(AsyncKill)(THIS) PURE;
726 // Forces synchronous completion of async request. ppResult is as
727 // passed back from the ARQ fulfiller.
729 STDMETHOD(GetAsyncResult)(THIS_ void **ppResult) PURE;
732 // Application Data methods
734 // Sometimes, the application wants to attach a bit of data to its
735 // resources; usually, but not always, this is a pointer of some sort.
736 // These methods allow you to do this, giving a DWORD that will be
737 // associated with this resource until further notice. (To unset this
738 // data, just call SetAppData again with NO_RES_APP_DATA.)
740 // Note that the resource system absolutely ignores this data. This
741 // is significant, because if the IRes is completely Released, it will
742 // delete itself without performing any cleanup on this data. If the
743 // the data is a pointer to a structure, it is the responsibility of
744 // the application to clean it up *before* completely releasing the
745 // resource. (This *may* get enhanced in the future, but no promises.)
747 // The "empty" AppData has the value NO_RES_APP_DATA -- that is, this is
748 // what GetAppData will return if SetAppData has not been called on
749 // this resource.
751 STDMETHOD_(void, SetAppData)(THIS_ DWORD AppData) PURE;
752 STDMETHOD_(DWORD, GetAppData)(THIS) PURE;
755 // @HACKS:
757 // These are methods in the interface to get Dark out the door quickly.
758 // They SHOULD NOT be used by later systems. They will hopefully be removed
759 // from the interface and from stdres as soon as feasible.
763 // Get the data for this resource, without loading or locking.
765 // You are STRONGLY DISCOURAGED from using this method. It exists solely
766 // for the use of older systems, whose designs didn't take into account the
767 // Lock/Unlock model of operation. New code should always use Lock to
768 // obtain the data, and should Unlock when it is done with that data.
769 // This method will be removed from the API when all projects have moved
770 // over to this new way of doing business.
772 // *If* this resource is currently loaded into memory, this returns a
773 // pointer to that resource's data. This pointer can only be considered
774 // valid as long as the resource is Locked; it will cease to be valid at
775 // an unpredictable time after that. Do not use unless you really know
776 // what you are doing.
778 STDMETHOD_(void *, DataPeek)(THIS) PURE;
781 // Assign the given data as the "real" data for this resource.
783 // This takes a pointer to some arbitrary memory, managed by an outside
784 // module. It will use that pointer, from now on, when returning
785 // information about this resource. The resource must be Unlocked when
786 // this is called. Memory management on the given data is entirely the
787 // responsibility of the caller. No reference counting is maintained in
788 // this case.
790 // This particular bit of hackery is principally here to support the
791 // Dark engine, which gets an image resource, then mipmaps it, and
792 // "assigns" the mipmap as the new version of the resource. It is
793 // intended solely for the short term; this model should NOT be emulated.
794 // Instead, later systems should create custom resource types for cases
795 // like this. When practicable, this method will be removed.
797 STDMETHOD_(void, SetData)(THIS_ void * pNewData) PURE;
798 STDMETHOD_(BOOL, HasSetData)(THIS) PURE;
801 //////////////////////////////////////////////////////////////////////
803 // INTERFACE: IResStore
805 // This is a side-interface from IRes, which allows the caller to get
806 // and set information about the way the resource appears in storage.
807 // (Mainly where it is to be found.)
810 #undef INTERFACE
811 #define INTERFACE IResStore
813 DECLARE_INTERFACE_(IResStore, IUnknown)
816 // IUnknown methods
818 DECLARE_UNKNOWN_PURE();
821 // Get/Set the structured storage
823 STDMETHOD_(BOOL, SetStore)(THIS_ IStore *) PURE;
824 STDMETHOD_(IStore *, GetStore)(THIS) PURE;
827 // Set the name of the resource under its storage
829 // @TBD (justin 5-15-98): Should we take this out? I think one can argue
830 // that the name of a resource is pretty intrinsic, and shouldn't be
831 // changed. As it is, this method is never called externally -- the name
832 // is set at creation time. The only argument I can see for keeping it
833 // external is for possible later tools...
835 STDMETHOD_(void, SetName)(THIS_ const char *pName) PURE;
838 // If FALSE, only the first call to SetStore will stick. May be useful
839 // if you don't want this resource getting looked up again if the state
840 // of the disk changes.
842 STDMETHOD_(void, AllowStorageReset)(THIS_ BOOL) PURE;
845 // Returns the full pathname for this resource.
847 STDMETHOD_(const char *, GetFullPathName)(THIS) PURE;
850 // Returns the *relative* pathname for this resource. This pathname is
851 // relative to the storage under which the resource was created; that is,
852 // it is generally equal to the name that was passed in to the Prep or
853 // Make command that generated it. In general, though, you should usually
854 // use GetName instead.
856 STDMETHOD_(void, SetRelativePathName)(THIS_ const char *pPathname) PURE;
857 STDMETHOD_(const char *, GetRelativePathName)(THIS) PURE;
860 // @TBD (justin 5-7-98): We don't currently have a mechanism for
861 // returning the pathname of this resource with the path it was
862 // found along. Do we need this? If so, it'll have to be added
863 // to IStoreStream. Personally, I'd rather not; it's kinda weird...
867 // @TBD (justin 5-7-98): We will probably eventually need a bit
868 // more interface here for the output side of the equation, so a
869 // tool can create a resource and add it to a storage...
873 //////////////////////////////////////////////////////////////////////
875 // INTERFACE: IResType
877 // A "type" encapsulates a particular family of resources. It serves as
878 // a factory for that kind of resource -- you call CreateRes () to get
879 // a new resource of this type, or CreateResFromRes () to create a new
880 // one based on the data of an existing one.
883 #undef INTERFACE
884 #define INTERFACE IResType
886 DECLARE_INTERFACE_(IResType, IUnknown)
889 // IUnknown methods
891 DECLARE_UNKNOWN_PURE();
894 // Get the name of this type. This is an arbitrary static string,
895 // which should ideally be unique.
897 STDMETHOD_(const char *, GetName) (THIS) PURE;
900 // Get the extensions that this type supports. This will call the callback
901 // once for each supported extension.
903 STDMETHOD_(void, EnumerateExts) (THIS_
904 tResEnumExtsCallback callback,
905 void *pClientData) PURE;
908 // Return TRUE iff the given extension is legal for this type. Arguably
909 // redundant with EnumerateExts, but it is useful for efficiency reasons
910 // to have both.
912 STDMETHOD_(BOOL, IsLegalExt) (THIS_ const char *pExt) PURE;
915 // Create a new resource of this type from the specified IStore, with
916 // the given name. If ppResMem is non-null, it gives the memory
917 // manager for this data. Returns NULL iff it can't create the IRes
918 // for some reason. It should make sure that the resource knows its
919 // name and storage, from the params.
921 // Note that this does not actually read any data in, or even open
922 // up the stream in the IStore; it just sets things up so that later
923 // operations can do so.
925 STDMETHOD_(IRes *, CreateRes) (THIS_
926 IStore *pStore,
927 const char *pName,
928 const char *pExt,
929 IResMemOverride **ppResMem) PURE;
932 ///////////////////////////////////////////////////////////////////////////////
934 // INTERFACE: IResMemOverride
937 #undef INTERFACE
938 #define INTERFACE IResMemOverride
940 DECLARE_INTERFACE_(IResMemOverride, IUnknown)
943 // IUnknown methods
945 DECLARE_UNKNOWN_PURE();
947 // @TBD (justin, 5-1-98): Is there any good reason to use special names
948 // for these methods? It seems more sensible to me to just call them
949 // Malloc and Free...
954 STDMETHOD_(void *, ResMalloc) (THIS_ ulong nNumBytes) PURE;
959 STDMETHOD_(void, ResFree) (THIS_ void *) PURE;
964 STDMETHOD_(ulong, GetSize) (THIS_ void *) PURE;
967 //////////////////////////////////////////////////////////////////////////
969 // C Accessor macros
972 #define IResMan_Init(p, a) COMCall1(p, Init, a)
973 #define IResMan_Cleanup(p) COMCall0(p, Cleanup)
974 #define IResMan_NewSearchPath(p) COMCall0(p, NewSearchPath)
975 #define IResMan_SetDefaultPath(p, a) COMCall1(p, SetDefaultPath, a)
976 #define IResMan_PrepResource(p, a, b) COMCall2(p, PrepResource, a, b)
977 #define IResMan_PrepTypedResource(p, a, b, c) COMCall3(p, PrepTypedResource, a, b, c)
978 #define IResMan_PrepAllResources(p, a, b, c, d) COMCall4(p, PrepAllResources, a, b, c, d)
979 #define IResMan_PrepAllTypedResources(p, a, b, c, d, e) COMCall5(p, PrepAllTypedResources, a, b, c, d, e)
980 #define IResMan_MakeResource(p, a, b, c) COMCall3(p, MakeResource, a, b, c)
981 #define IResMan_MakeTypedResource(p, a, b, c, d) COMCall4(p, MakeTypedResource, a, b, c, d)
982 #define IResMan_MakeRetypedResource(p, a, b, c) COMCall3(p, MakeRetypedResource, a, b, c)
983 #define IResMan_GetStore(p, a) COMCall1(p, GetStore, a)
984 #define IResMan_RegisterResType(p, a) COMCall1(p, RegisterResType, a)
985 #define IResMan_RegisterStoreFactory(p, a) COMCall1(p, RegisterStoreFactory, a)
986 #define IResMan_UnregisterResType(p, a) COMCall1(p, UnregisterResType, a)
987 #define IResMan_MarkForReload(p, a, b) COMCall2(p, MarkForReload, a, b)
988 #define IResMan_MarkForReloadRes(p, a) COMCall1(p, MarkForReloadRes, a)
989 #define IResMan_MarkForRebind(p, a, b) COMCall2(p, MarkForRebind, a, b)
990 #define IResMan_MarkForRebindRes(p, a, b) COMCall2(p, MarkForRebindRes, a, b)
992 //////////
994 #define IResStats_EnableStats(p, a) COMCall1(p, EnableStats, a)
995 #define IResStats_DumpStats(p, a) COMCall1(p, DumpStats, a)
997 //////////
999 #define IResMem_EnablePaging(p, a) COMCall1(p, EnablePaging, a)
1000 #define IResMem_Compact(p) COMCall0(p, Compact)
1001 #define IResMem_GetMemStats(p, a) COMCall1(p, GetMemStats, a)
1003 ///////////////////////////////////////
1005 #define IRes_GetType(p) COMCall0(p, GetType)
1006 #define IRes_GetName(p) COMCall0(p, GetName)
1007 #define IRes_Lock(p) COMCall0(p, Lock)
1008 #define IRes_Unlock(p) COMCall0(p, Unlock)
1009 #define IRes_Drop(p) COMCall0(p, Drop)
1010 #define IRes_GetSize(p) COMCall0(p, GetSize)
1011 #define IRes_Extract(p, a) COMCall1(p, Extract, a)
1012 #define IRes_LoadData(p, a, b) COMCall2(p, LoadData, a, b)
1013 #define IRes_PreLoad(p) COMCall0(p, PreLoad)
1014 #define IRes_ExtractPartial(p, a, b, c) COMCall3(p, ExtractPartial a, b, c)
1015 #define IRes_ExtractBlocks(p, a, b, c, d) COMCall4(p, ExtractBlocks, a, b, c, d)
1016 #define IRes_OpenStream(p) COMCall0(p, OpenStream)
1017 #define IRes_GetTranslatableTypes(p, a) COMCall1(p, GetTranslatableTypes, a)
1018 #define IRes_LoadTranslation(p, a, b, c, d, e, f) COMCall6(p, LoadTranslation, a, b, c, d, e, f)
1019 #define IRes_AsyncLock(p, a, b, c) COMCall3(p, AsyncLock, a, b, c)
1020 #define IRes_AsyncExtract(p, a, b, c, d, e) COMCall5(p, AsyncExtract, a, b, c, d, e)
1021 #define IRes_AsyncPreload(p, a, b) COMCall2(p, AsyncPreload, a, b)
1022 #define IRes_IsAsyncFulfilled(p) COMCall0(p, IsAsyncFulfilled)
1023 #define IRes_AsyncKill(p) COMCall0(p, AsyncKill)
1024 #define IRes_GetAsyncResult(p, a) COMCall1(p, GetAsyncResult, a)
1025 #define IRes_SetAppData(p, a) COMCall1(p, SetAppData, a)
1026 #define IRes_GetAppData(p) COMCall0(p, GetAppData)
1027 #define IRes_DataPeek(p) COMCall0(p, DataPeek)
1028 #define IRes_SetData(p, a) COMCall1(p, SetData, a)
1029 #define IRes_HasSetData(p) COMCall0(p, HasSetData)
1031 //////////
1033 #define IResStore_SetStore(p, a) COMCall1(p, SetStore, a)
1034 #define IResStore_GetStore(p) COMCall0(p, GetStore)
1035 #define IResStore_SetName(p, a) COMCall1(p, SetName, a)
1036 #define IResStore_AllowStorageReset(p, a) COMCall1(p, AllowStorageReset, a)
1037 #define IResStore_GetFullPathName(p) COMCall0(p, GetFullPathName)
1038 #define IResStore_SetRelativePathName(p, a) COMCall1(p, SetRelativePathName, a)
1039 #define IResStore_GetRelativePathName(p) COMCall0(p, GetRelativePathName)
1041 ///////////////////////////////////////
1043 #define IResType_GetName(p) COMCall0(p, GetName)
1044 #define IResType_EnumerateExts(p, a, b) COMCall2(p, EnumerateExts, a, b)
1045 #define IResType_IsLegalExt(p, a) COMCall1(p, IsLegalExt, a)
1046 #define IResType_CreateRes(p, a, b, c, d) COMCall4(p, CreateRes, a, b, c, d)
1048 ///////////////////////////////////////
1050 #define IResMemOverride_ResMalloc(p, a) COMCall1(p, ResMalloc, a)
1051 #define IResMemOverride_ResFree(p, a) COMCall1(p, ResFree, a)
1052 #define IResMemOverride_ResGetSize(p, a) COMCall1(p, ResGetSize, a)
1054 ///////////////////////////////////////////////////////////////////////////////
1056 #pragma pack()
1058 #endif /* !__RESAPI_H */