MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Types | Protected Attributes | List of all members
Mezzanine::Threading::AsynchronousFileLoadWorkUnit Class Reference

This is intended to load files asynchronously and continue doing so whether or not other the FrameScheduler is running or paused. More...

#include <asynchronousfileloadingworkunit.h>

+ Inheritance diagram for Mezzanine::Threading::AsynchronousFileLoadWorkUnit:
+ Collaboration diagram for Mezzanine::Threading::AsynchronousFileLoadWorkUnit:

Public Member Functions

 AsynchronousFileLoadWorkUnit ()
 Default constructor.
 
virtual ~AsynchronousFileLoadWorkUnit ()
 Destructor, deletes all loaded files.
 
RunningState BeginLoading (const std::vector< String > &Filenames_)
 Begin loading a list of files based on their names. More...
 
void DeleteLoadedFiles ()
 This deletes all the loaded files from the last call of BeginLoading .
 
virtual void DoWork (DefaultThreadSpecificStorage::Type &)
 This checks if Asynchronous loading thread has completed and if so it cleans up that threads' resources.
 
RawFileGetFile (const String &FileName) const
 Get a loaded RawFile in linear time. More...
 
RawFileGetFile (const Whole &Index) const
 Retrieve a pointer to file contents in constant time. More...
 
virtual RunningState IsWorkDone ()
 Get the RunningState of the file loading. More...
 

Protected Types

typedef std::vector< RawFile * > RawFileContainer
 Used to make referencing the the type of FilesRaw easier.
 

Protected Attributes

std::vector< StringFilenames
 The names of the files this batch of loading will retrieve.
 
RawFileContainer FilesRaw
 The contents of the files once they have been loaded. No partial files will exists here, either the whole file is added or nothing is added.
 
ThreadLoadingThread
 This is either 0 or the other thread that is loading.
 
Int32 Status
 This stores the current RunningState.
 

Detailed Description

This is intended to load files asynchronously and continue doing so whether or not other the FrameScheduler is running or paused.

The goal is to trigger lower level mechanisms to use DMA to load directly without CPU intervention. In some operating systems this is handled in the standard library, and in others special mechanisms must be used to make this happen. The current state of this allows testing to determine how good automatic mechanisms work.

Definition at line 100 of file asynchronousfileloadingworkunit.h.

Member Function Documentation

RunningState Mezzanine::Threading::AsynchronousFileLoadWorkUnit::BeginLoading ( const std::vector< String > &  Filenames_)

Begin loading a list of files based on their names.

Parameters
Filenames_A vector of Strings that correspond to either relative or absolute filenames that will be loaded.

When the file is loaded its contents are placed in a RawFile and can be retrieved with GetFile or GetFile member functions.

This starts by clearing the previous list of loaded files. If that list has not been deleted then this will cause a memory leak. Use DeleteLoadedFiles to clear this list or copy all the pointers elsewhere before calling this and delete them manually at your convience. When this work unit is destroyed it deletes any loaded files from the last call of this method.

If this is called while it is loading files the behavior is undefined, most likely it will crash or fail silently, either way no good can come from it. Use IsWorkDone to see if the work is Complete. If the work is complete then this can be called after any call to this class's DoWork member function.

Warning
This can leak memory if not used in conjuction with memory management or DeleteLoadedFiles and read the details.
This can fail in horrible ways if called twice without waiting for the first call to finish, use IsWorkDone and read the details.
Returns
This returns Starting when loading is successful started and who knows what it returns if it fails, likely a segfault or GPF.

Definition at line 100 of file asynchronousfileloadingworkunit.cpp.

RawFile * Mezzanine::Threading::AsynchronousFileLoadWorkUnit::GetFile ( const String FileName) const

Get a loaded RawFile in linear time.

This searches the list of files names to determine the index of the filename then calls GetFile.

Parameters
FileNameThe file to retrieve.
Returns
A pointer to a RawFile or 0 if it cannot be retrieved for any reason.

Definition at line 128 of file asynchronousfileloadingworkunit.cpp.

RawFile * Mezzanine::Threading::AsynchronousFileLoadWorkUnit::GetFile ( const Whole Index) const

Retrieve a pointer to file contents in constant time.

Parameters
IndexThe index of the File Name when it was passed into BeginLoading.
Returns
This returns a null pointer if the correct RawFile cannot be retrieved, otherwise a pointer to the RawFile with index corresponing to the index of a passed in filename is returned.
Warning
Do no call this before IsWorkDone() indicates that the work is Complete. These memory addresses are subject to change until all loading is complete.

Definition at line 141 of file asynchronousfileloadingworkunit.cpp.

RunningState Mezzanine::Threading::AsynchronousFileLoadWorkUnit::IsWorkDone ( )
virtual

Get the RunningState of the file loading.

This can return any RunningState and the meaning applies to the current state of the files being loaded.

  • NotStarted - Either BeginLoading has not been called or it has been called and has not progressed to the point where it sets this. Not useful for making logical decisions without knowledge of how many times BeginLoading has been called.
  • Starting - This is returned from BeginLoading is success conditions, and is never returned from this.
  • Running - This means that the loading thread has started but not yet completed.
  • Complete - The loading thread has completed its work, and new loading can definitely begin after the next call to DoWork method.
  • Failed - If somekind of recoverable error occured, this will be returned, there are no guarantees about the state of the loaded files.
    Returns
    The running state as of the time of this call, though it is subject to immediate thread unsafe change.

Implements Mezzanine::Threading::iAsynchronousWorkUnit.

Definition at line 125 of file asynchronousfileloadingworkunit.cpp.


The documentation for this class was generated from the following files: