home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * RES.C
- *
- * System Overview:
- * GetRes() -
- * DupRes() -
- * FreeRes() -
- * FreeAllRes() -
- * ChownRes() -
- * UnLinkAllRes() -
- * ReLinkAllRes() -
- * SetResFlags() -
- * AddRes() -
- * RemRes() -
- * GetResInfo() -
- * GetResList() -
- * GetFileList() -
- * AddPrivResFile() -
- * RemPrivResFiles() -
- * AddGlobResFile() -
- * RemGlobResFiles() -
- * AddResSwapDir() -
- * RemResSwapDirs() -
- *
- */
-
- #include <local/typedefs.h>
- #include <local/ipc.h>
- #include <local/res.h>
- #include "/src/ires.h"
-
- static long SysLock[2] = { 0, 0 };
-
- extern TML *GetTML();
-
- /*
- * Search order: Private-mem, Private-disk, System-mem, System-disk,
- * OtherTaskGlob-mem, OtherTaskGlob-disk
- */
-
- APTR
- GetRes(name)
- char *name;
- {
- TML *tml = GetTML();
-
-
-
-
- resptr= GetRes(resnametype) char *resnametype;
-
- This function retrieves the requested resource, doing any
- translations required to get the resource into the requested
- type. NULL is returned if the resource could not be found
- or could not be translated to the requested type.
-
- In-Memory private resources are searched first, then the private
- resource files for the task, then In-Memory system resources, then
- the global resource files for the system. Openning an already-open
- resource causes one of two actions depending on whether the resource
- is shared or not. If shared, the reference count is simply
- incremented, otherwise a private copy of the resource is made.
-
- Example: Win = GetRes("Charlie.Window");
-
- resptr2 = DupRes(resptr1) APTR resptr1, resptr2;
-
- This call duplicates a resource. If the resource is shared
- resptr2 will be the same as resptr1 and the reference count will
- be bumped. Otherwise, a new resource data area is allocated and
- the old copied to the new.
-
- Things like fixing pointers and such within a resource that is
- physically duplicated are handled by the interface code (since
- raw resources do not contain pointers, only VIRTUAL resources
- will contain pointers and all VIRTUAL resources have some
- interface code).
-
- error = FreeRes(resptr)
-
- Free a resource that you retrieved via GetRes(). Only the task
- that owns the resource may free it (though several tasks may own
- a resource through duplication and ownership changes). 1 is
- returned on success, 0 on error.
-
- That is, if task #1 GetRes()'s the resource and duplicates it once,
- then task #2 duplicates it once, task #1 must call FreeRes() twice
- and task #2 must call FreeRes() once. Ownership is strictly
- tracked.
-
- numres= FreeAllRes(task)
-
- Free all resources associated with the specified task (NULL for
- self).
-
- error = ChownRes(resptr, fromtask, totask)
-
- Change ownership of a resource from the source task to the
- destination task. The resource must be owned by the source
- task or an error will occur (0 return value). 1 is returned
- on success. NULL may be specified for either or both tasks
- and means the calling task.
-
- handle= UnLinkAllRes(task)
-
- Unlink all resources associated with the specified task (NULL
- for self) and return a handle representing those resources.
-
- This is useful for shells and such to keep their resources from
- getting removed by commands they run. Combined with the NUNLINK
- flag one can pass resources to a Command and keep the rest out of
- reach.
-
- (void) ReLinkAllRes(handle, task)
-
- Link all the resources represented by the handle to the specified
- task (NULL for self).
-
- oldfl = SetResFlags(resptr, newflags, flagsmask)
-
- Modify the flags associated with a resource. NOTE: If multiple
- references to a shared resource exist, all are modified. Some
- modifications may be disallowed by the system. This call is
- normally used to modify the LOCKED and SWAPABLE flags (note that
- the SWAPABLE flag can be changed back and forth only for resource
- which support it).
-
- error = AddRes(resnametype, flags, ptr, ctlcode);
- char *resnametype;
- long flags;
- APTR ptr;
- long (*ctlcode)();
-
- Add a resource to the system. The resource is placed either in
- the task's privately accessable in-memory resource list or
- in the system global accessable in-memory resource list depending
- on the specified flags. One may now GetRes() the resource.
-
- ONLY VIRTUAL RESOURCES MAY BE ADDED IN THIS WAY. The VIRTUAL
- and LOCKED flags are automatically set.
-
- If flags specifies a VIRTUAL resource
-
- error = RemRes(resname)
-
- Remove the specified resource. An error will occur and the resource
- will not be removed (1) if it does not exist in memory, or (2) it
- is currently being referenced. (Note: the resource is removed even
- if it is swapped or locked).
-
- error = GetResInfo(resname, &flags, &bytes)
-
- Get information on a resource. Information may not exist for a
- resource if it is not currently in memory and would have to be
- translated to get to the right type.
-
- error = GetResList(wildcard, from, &av, &ac);
-
- from: mask, bit 0 search private list
- 1 search system list
- 2 <not used>
- 3 search in-memory private list
- 4 search in-memory global list
-
- Return an ARGC/ARGV list of resource names. Note that some names
- might be duplicated if searching multiple lists. Restricting the
- search to in-memory lists give resources which are already in
- memory (but might be swapped out or removed at any time for those
- with no references)
-
- RESOURCE FILES
-
- error = GetFileList(wildcard, from, &av, &ac);
-
- from: mask, bit 0 search private list
- 1 search system list
- 2 search swap list
-
- Return an ARGC/ARGV list of the files which match the specified
- wildcard from the private list, system list, or system swap dir
- list (in which case you get directory names). This list has been
- allocated, and can be freed as follows:
-
- Loop through all entries for (i = 0; i < ac; ++i)
- FreeMem(av[i], strlen(av[i])+1);
- Free the array itself: FreeMem(av, sizeof(char *) * (ac+1));
-
- num = AddPrivResFile(filename, pri)
-
- Add a file name to the list of resource files for this task. These
- are scanned before global files when a resource is requested. All
- files in the list are write protected (i.e. a shared lock is kept
- for each file). Thus, such files cannot be updated until removed
- from the list.
-
- Can also be used to modify the priority of an existing file
-
- num = RemPrivResFiles(wildcard)
-
- Remove zero or more file names from the list of resource files for
- this task. A wildcard pattern (* and ?) is accepted.
-
- Note for command processors: commands you run might execute
- this command for *.
-
- num = AddGlobResFile(filename, pri)
-
- Same as AddPrivResFile() but applies to the system list, which is
- searched last and by any requesting task. Wildcard file names are
- NOT accepted. The file need not exist at this time, and references
- to unmounted volumes are allowed.
-
- Can also be used to modify the priority of an existing entry
-
- num = RemGlobResFiles(wildcard)
-
- Remove zero or more resource files from the global list. Again,
- a wildcard filename is accepted.
-
- num = AddResSwapDir(dirname, pri, maxkbytes) char *dirname;
- char pri;
- long maxkbytes
-
- Add a directory to the list of directories the resource system
- can swap to. The maximum number of KBytes of material allowed
- in the directory should be specified. You can also use this
- call to modify the priority and maxkbytes for an entry.
-
- The highest priority directories are used before lower priority
- directories. Not all directories need be mounted, but if a swapin
- occurs from an unmounted directory a requester will appear.
-
- A lock is kept on each specified directory.
-
- num = RemResSwapDirs(wildcard)
-
- Remove directories associated with the resource swap areas.
-
-
- RESOURCE FILE IFF FORMAT
-
-
-
-
- static
- TML *
- GetTML()
- {
- TML *tml = GetTaskData(RESMLNAME, sizeof(TML));
- if (tml && !tml->RFList.mlh_Head) {
- NewList(&tml->RENList);
- NewList(&tml->RFList);
- }
- return(tml);
- }
-
-