Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Loader Class Reference

Handles database loading through asynchronous threading. More...

#include <loader.h>

Inheritance diagram for Loader:

AsyncUtility List of all members.

Public Member Functions

 Loader ()
 ~Loader ()
int find_all_files (const Filename &filename, const DSearchPath &search_path, Results &results) const
 Searches along the given search path for the given file name, and fills up the results list with all possible matches and their associated types, in order.

PointerTo< PandaNodeload_sync (const Filename &filename, bool search=true) const
uint request_load (const string &event_name, const Filename &filename, bool search=true)
 Requests an asynchronous load of a file.

bool check_load (uint id)
 Returns true if the indicated load-request has completed and not yet been fetched, false otherwise.

PointerTo< PandaNodefetch_load (uint id)
 Returns the Node associated with the indicated id number (returned by a previous call to request_load), or NULL if the request has not yet completed.

void set_frequency (float frequency)
 Fraction of a second.

float get_frequency (void) const
void create_thread (void)

Protected Member Functions

void destroy_thread (void)
void callback (void)
 This is the main body of the sub-thread.

void nap (void) const

Static Protected Member Functions

void * st_callback (void *arg)
 This is a static wrapper around the callback() method, below.


Protected Attributes

int _next_token
bool _shutdown
bool _threaded
float _frequency
bool _threads_enabled

Private Types

typedef TokenBoard< LoaderTokenLoaderTokenBoard

Private Member Functions

virtual bool process_request (void)
 Serves any requests on the token board, moving them to the done queue.

PointerTo< PandaNodeload_file (const Filename &filename, bool search) const
 Loads a single scene graph file, if possible.


Static Private Member Functions

void load_file_types ()
 Loads up all of the dynamic libraries named in a load-file-type Configure variable.


Private Attributes

LoaderTokenBoard_token_board

Static Private Attributes

bool _file_types_loaded = false

Detailed Description

Handles database loading through asynchronous threading.

Definition at line 46 of file loader.h.


Member Typedef Documentation

typedef TokenBoard<LoaderToken> Loader::LoaderTokenBoard [private]
 

Definition at line 94 of file loader.h.


Constructor & Destructor Documentation

Loader::Loader  ) 
 

Definition at line 81 of file loader.cxx.

References _token_board, and AsyncUtility::destroy_thread().

Loader::~Loader  ) 
 

Definition at line 93 of file loader.cxx.

References _file_types_loaded, Filename::get_extension(), LoaderFileTypeRegistry::get_ptr(), LoaderFileTypeRegistry::get_type_from_extension(), Filename::is_local(), load_file_types(), and NULL.


Member Function Documentation

void AsyncUtility::callback void   )  [protected, inherited]
 

This is the main body of the sub-thread.

It waits forever for a request to show up, and then serves it.

Definition at line 160 of file asyncUtility.cxx.

bool Loader::check_load uint  id  ) 
 

Returns true if the indicated load-request has completed and not yet been fetched, false otherwise.

Definition at line 314 of file loader.cxx.

References load_file_type, and NULL.

void AsyncUtility::create_thread void   )  [inherited]
 

Definition at line 80 of file asyncUtility.cxx.

References AsyncUtility::_shutdown, and AsyncUtility::_threaded.

void AsyncUtility::destroy_thread void   )  [protected, inherited]
 

Definition at line 99 of file asyncUtility.cxx.

Referenced by Loader().

PointerTo< PandaNode > Loader::fetch_load uint  id  ) 
 

Returns the Node associated with the indicated id number (returned by a previous call to request_load), or NULL if the request has not yet completed.

Definition at line 331 of file loader.cxx.

References TokenBoard< LoaderToken >::_done, _token_board, TokenBoard< LoaderToken >::_waiting, CircBuffer< PointerTo< LoaderToken >, MAX_TOKENBOARD_REQUESTS >::empty(), CircBuffer< PointerTo< LoaderToken >, MAX_TOKENBOARD_REQUESTS >::front(), load_file(), NULL, CircBuffer< PointerTo< LoaderToken >, MAX_TOKENBOARD_REQUESTS >::pop_front(), PT, and CircBuffer< PointerTo< LoaderToken >, MAX_TOKENBOARD_REQUESTS >::push_back().

int Loader::find_all_files const Filename filename,
const DSearchPath search_path,
Loader::Results results
const
 

Searches along the given search path for the given file name, and fills up the results list with all possible matches and their associated types, in order.

Definition at line 113 of file loader.cxx.

Referenced by process_request().

float AsyncUtility::get_frequency void   )  const [inline, inherited]
 

Definition at line 43 of file asyncUtility.I.

PointerTo< PandaNode > Loader::load_file const Filename filename,
bool  search
const [private]
 

Loads a single scene graph file, if possible.

Returns the Node that is the root of the file, or NULL if the file cannot be loaded.

If search is true, the file is searched for along the model path; otherwise, only the exact filename is loaded.

Definition at line 445 of file loader.cxx.

Referenced by fetch_load(), and Loader::Results::get_file_type().

void Loader::load_file_types  )  [static, private]
 

Loads up all of the dynamic libraries named in a load-file-type Configure variable.

Presumably this will make the various file types available for runtime loading.

Definition at line 357 of file loader.cxx.

Referenced by Loader::Results::get_file_type(), and ~Loader().

PointerTo< PandaNode > Loader::load_sync const Filename filename,
bool  search = true
const [inline]
 

Referenced by get_models().

void AsyncUtility::nap void   )  const [protected, inherited]
 

Definition at line 179 of file asyncUtility.cxx.

bool Loader::process_request void   )  [private, virtual]
 

Serves any requests on the token board, moving them to the done queue.

Implements AsyncUtility.

Definition at line 387 of file loader.cxx.

References find_all_files(), and get_model_path().

uint Loader::request_load const string &  event_name,
const Filename filename,
bool  search = true
 

Requests an asynchronous load of a file.

The request will be queued and served by the asynchronous thread. If event_name is nonempty, it is the name of the event that will be thrown (with the uint id as its single parameter) when the loading is completed later.

The return value is an integer which can be used to identify this particular request later to fetch_load(), or 0 if there has been an error.

If search is true, the file is searched for along the model path; otherwise, only the exact filename is loaded.

Definition at line 241 of file loader.cxx.

References _token_board.

void AsyncUtility::set_frequency float  frequency  )  [inline, inherited]
 

Fraction of a second.

Definition at line 31 of file asyncUtility.I.

References AsyncUtility::_frequency, and INLINE.

void * AsyncUtility::st_callback void *  arg  )  [static, protected, inherited]
 

This is a static wrapper around the callback() method, below.

It's static just so we can pass it to the thread-creation function. In addition, the function has a void* return type even though we don't actually return anything. This is necessary because ipc assumes a function that does not return anything indicates that the associated thread should be created as unjoinable (detached).

Definition at line 141 of file asyncUtility.cxx.

Referenced by AsyncUtility::~AsyncUtility().


Member Data Documentation

bool Loader::_file_types_loaded = false [static, private]
 

Definition at line 43 of file loader.cxx.

Referenced by ~Loader().

float AsyncUtility::_frequency [protected, inherited]
 

Definition at line 68 of file asyncUtility.h.

Referenced by AsyncUtility::set_frequency().

int AsyncUtility::_next_token [protected, inherited]
 

Definition at line 65 of file asyncUtility.h.

bool AsyncUtility::_shutdown [protected, inherited]
 

Definition at line 66 of file asyncUtility.h.

Referenced by AsyncUtility::create_thread().

bool AsyncUtility::_threaded [protected, inherited]
 

Definition at line 67 of file asyncUtility.h.

Referenced by AsyncUtility::create_thread(), and AsyncUtility::~AsyncUtility().

bool AsyncUtility::_threads_enabled [protected, inherited]
 

Definition at line 69 of file asyncUtility.h.

Referenced by AsyncUtility::~AsyncUtility().

LoaderTokenBoard* Loader::_token_board [private]
 

Definition at line 95 of file loader.h.

Referenced by fetch_load(), Loader(), and request_load().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:52:01 2003 for Panda by doxygen1.3