tResourceManager Class Reference

resource manager: fetches and caches resources from repositories or arbitrary URIs More...

#include <tResourceManager.h>

List of all members.

Static Public Member Functions

static tResourceGetResource (const char *file, int typeID)
 When finished, this will be the preferred way to load a resource.
static int RegisterResourceType (tNewResourceFunc func)
 Register a resource type.
static tString locateResource (const char *file, const char *uri="")
 Return the position of the resource in the cache.
static FILE * openResource (const char *pathname, const char *uri="")
 opens a resource
static tStringAccessRepoServer ()
 server determined resource repository
static tStringAccessRepoClient ()
 client determined resource repository
static void RegisterLoader ()
 register a resource component loader


Detailed Description

resource manager: fetches and caches resources from repositories or arbitrary URIs

Definition at line 10 of file tResourceManager.h.


Member Function Documentation

tResource * tResourceManager::GetResource ( const char *  file,
int  typeID 
) [static]

When finished, this will be the preferred way to load a resource.

Parameters:
file the full path to the file
typeID the unique identifier for the resource type, which is in turn returned from RegisterResourceType
See also:
RegisterResourceType

Definition at line 21 of file tResourceManager.cpp.

References NULL.

00022 {
00023     // stub
00024     return NULL;
00025 }

int tResourceManager::RegisterResourceType ( tNewResourceFunc  func  )  [static]

Register a resource type.

Parameters:
func a function that returns a new instance of the resource
Returns:
the unique identifier for the function. Use this in subsequence calls to GetResource.
When you create a new resource type, you must register a function that will instantiate that new type. Later on you'll call tResourceManager to instantiate the type for a resource that's needed and you'll need to know the identifier returned from this method.

Definition at line 27 of file tResourceManager.cpp.

00027                                                                 {
00028     // stub
00029     return 0;
00030 }

tString tResourceManager::locateResource ( const char *  file,
const char *  uri = "" 
) [static]

Return the position of the resource in the cache.

Definition at line 140 of file tResourceManager.cpp.

References AccessRepoClient(), AccessRepoServer(), con, free, tPath::GetReadPath(), tPathResource::GetWritePath(), malloc, myFetch(), NULL, pos, tDirectories::Resource(), and rv.

Referenced by tXmlParserNamespace::tXmlResource::LoadFile(), tXmlParserNamespace::tXmlParser::LoadWithoutParsing(), tXmlParserNamespace::tXmlParser::LoadWithParsing(), openResource(), and RInclude().

00140                                                                           {
00141     tString filepath, a_uri = tString(), savepath;
00142     int rv;
00143 
00144     char * to_free = NULL; // string to delete later
00145 
00146     {
00147         char const *pos, *posb;
00148         char *nf;
00149         size_t l;
00150 
00151         // Step 1: If 'file' has an open paren, cut everything after it off
00152         if ( (pos = strchr(file, '(')) ) {
00153             l = (size_t)(pos - file);
00154             nf = (char*)malloc((l + 1) * sizeof(char));
00155             strncpy(nf, file, l);
00156             nf[l] = '\0';
00157             file = nf;
00158             to_free = nf;
00159 
00160             // Step 2: Extract URI, if any
00161             ++pos;
00162             if ( (posb = strchr(pos, ')')) ) {
00163                 l = (size_t)(posb - pos);
00164                 nf = (char*)malloc((l + 1) * sizeof(char));
00165                 strncpy(nf, pos, l);
00166                 nf[l] = '\0';
00167                 a_uri << nf << ';';
00168                 free( nf );
00169             }
00170         }
00171     }
00172     // Validate paths and determine detination savepath
00173     if (!file || file[0] == '\0') {
00174         con << tOutput( "$resource_no_filename" );
00175         return (tString) NULL;
00176     }
00177     if (file[0] == '/' || file[0] == '\\') {
00178         con << tOutput( "$resource_abs_path" );
00179         return (tString) NULL;
00180     }
00181     savepath = tDirectories::Resource().GetWritePath(file);
00182     if (savepath == "") {
00183         con << tOutput( "$resource_no_writepath" );
00184         return (tString) NULL;
00185     }
00186 
00187     // Do we have this file locally ?
00188     filepath = tDirectories::Resource().GetReadPath(file);
00189 
00190     if (filepath != "")
00191     {
00192         if ( NULL != to_free )
00193             free( to_free );
00194         return filepath;
00195     }
00196 
00197     // Some sort of File not found
00198     if (uri && strcmp("0", uri))
00199         a_uri << uri << ';';
00200 
00201     // add repositories to uri
00202     if ( AccessRepoServer().Len() > 2 )
00203         a_uri << AccessRepoServer() << file << ';';
00204 
00205     if ( AccessRepoClient().Len() > 2 && AccessRepoClient() != AccessRepoServer() )
00206         a_uri << AccessRepoClient() << file << ';';
00207 
00208     con << tOutput( "$resource_not_cached", file );
00209 
00210     rv = myFetch((const char *)a_uri, file, (const char *)savepath);
00211 
00212     if ( NULL != to_free )
00213         free( to_free );
00214 
00215     if (rv)
00216         return (tString) NULL;
00217     return savepath;
00218 }

Here is the call graph for this function:

Here is the caller graph for this function:

FILE * tResourceManager::openResource ( const char *  pathname,
const char *  uri = "" 
) [static]

opens a resource

Definition at line 220 of file tResourceManager.cpp.

References tString::Len(), locateResource(), and NULL.

Referenced by tXmlParserNamespace::tXmlParser::LoadWithoutParsing(), tXmlParserNamespace::tXmlParser::LoadWithParsing(), and tXmlParserNamespace::myxmlParserInputBufferCreateFilenameFunc().

00220                                                                       {
00221     tString filepath;
00222     filepath = locateResource(file, uri);
00223     if ( filepath.Len() <= 1 )
00224         return NULL;
00225     return fopen((const char *)filepath, "r");
00226 }

Here is the call graph for this function:

Here is the caller graph for this function:

tString & tResourceManager::AccessRepoServer (  )  [static]

server determined resource repository

Definition at line 37 of file tResourceManager.cpp.

Referenced by locateResource().

00038 {
00039     static tString resRepoServer("http://resource.armagetronad.net/resource/");
00040     return resRepoServer;
00041 }

Here is the caller graph for this function:

tString & tResourceManager::AccessRepoClient (  )  [static]

client determined resource repository

Definition at line 45 of file tResourceManager.cpp.

Referenced by locateResource().

00046 {
00047     static tString resRepoClient("http://resource.armagetronad.net/resource/");
00048     return resRepoClient;
00049 }

Here is the caller graph for this function:

void tResourceManager::RegisterLoader (  )  [static]

register a resource component loader

Definition at line 17 of file tResourceManager.cpp.

00018 {
00019 }


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:59:09 2008 for Armagetron Advanced by  doxygen 1.5.4