kanzi::ResourceManager::LoadTask Struct Referenceabstract

Use this base class to implement load tasks to load new resources. More...

#include <kanzi/core.ui/resource/resource_manager.hpp>

Inheritance diagram for kanzi::ResourceManager::LoadTask:
kanzi::ResourceProfilingLoadTask

Public Types

enum  Type { LoadAndFinish, FinishOnly }
 The type of the load task. More...
 
enum  State {
  Initialized, WaitingToLoad, Loading, WaitingForDependencies,
  WaitingToFinish, Finishing, Finished
}
 The state of the load task. More...
 

Public Member Functions

 LoadTask ()
 Constructor. More...
 
 LoadTask (const Type type)
 Constructor. More...
 
virtual ~LoadTask ()
 Destructor. More...
 
virtual void loadFunction (const ResourceLoaderThreadContext *resourceLoaderThreadContext)=0
 You can override this function to define the part of the resource loading task that a worker thread executes. More...
 
virtual void finishFunction (const ResourceLoaderThreadContext *resourceLoaderThreadContext)=0
 The part of the loading that the main thread executes. More...
 
virtual ResourceSharedPtr getResult ()=0
 Returns the created resource. More...
 
Type getType () const
 Gets the type of a load task. More...
 
ResourceManagergetResourceManager () const
 Gets the resource manager of a load task. More...
 

Protected Member Functions

void enqueueDependencies (UrlContainer urls)
 Adds resource dependencies for a load task. More...
 

Friends

class ResourceManager
 Friend classes. More...
 
class FinishingQueue
 

Detailed Description

Use this base class to implement load tasks to load new resources.

A load task is split into an optional loadFunction and a mandatory finishFunction. You can call the loadFunction in a background worker thread, instead of the main thread. In the loadFunction execute only thread-independent work. Kanzi always calls the finishFunction in the main thread. Kanzi executes the load task in this order:

  1. The loading thread or main thread executes the loadFunction.
  2. The main thread executes the finishFunction.
  3. The load task returns the created resource with getResult. To trigger background loading of dependencies, in the loadFunction call enqueueDependencies.

Member Enumeration Documentation

The type of the load task.

Enumerator
LoadAndFinish 

Load task type with both loadFunction and finishFunction parts.

FinishOnly 

Load task type that executes everything only in the finishFunction.

For such tasks, Kanzi never calls the loadFunction.

The state of the load task.

Enumerator
Initialized 

The initial state of the task when you create the task.

WaitingToLoad 

Waiting for the execution of the loadFunction that is usually in the loading queue.

Loading 

Kanzi is executing the loadFunction.

WaitingForDependencies 

Waiting for completion of dependencies.

WaitingToFinish 

Waiting for the execution of the finishFunction that is usually in the finishing queue.

Finishing 

Kanzi is executing the finishFunction.

Finished 

Kanzi completed the execution of both loadFunction and finishFunction.

Constructor & Destructor Documentation

kanzi::ResourceManager::LoadTask::LoadTask ( )
explicit

Constructor.

Type is set to LoadAndFinish.

kanzi::ResourceManager::LoadTask::LoadTask ( const Type  type)
explicit

Constructor.

Parameters
typeLoad task type.
virtual kanzi::ResourceManager::LoadTask::~LoadTask ( )
virtual

Destructor.

Member Function Documentation

virtual void kanzi::ResourceManager::LoadTask::loadFunction ( const ResourceLoaderThreadContext resourceLoaderThreadContext)
pure virtual

You can override this function to define the part of the resource loading task that a worker thread executes.

You cannot access any shared data inside the function.

Parameters
resourceLoaderThreadContextThe context of the loader thread.

Implemented in kanzi::ResourceProfilingLoadTask.

virtual void kanzi::ResourceManager::LoadTask::finishFunction ( const ResourceLoaderThreadContext resourceLoaderThreadContext)
pure virtual

The part of the loading that the main thread executes.

The function creates and stores a new resource that getResult returns.

Parameters
resourceLoaderThreadContextThe context of the loader thread that was used to call loadFunction.

Implemented in kanzi::ResourceProfilingLoadTask.

virtual ResourceSharedPtr kanzi::ResourceManager::LoadTask::getResult ( )
pure virtual

Returns the created resource.

Returns
The created resource.

Implemented in kanzi::ResourceProfilingLoadTask.

Type kanzi::ResourceManager::LoadTask::getType ( ) const

Gets the type of a load task.

Returns
The type of the load task.
ResourceManager* kanzi::ResourceManager::LoadTask::getResourceManager ( ) const

Gets the resource manager of a load task.

Returns
Pointer to the resource manager.
void kanzi::ResourceManager::LoadTask::enqueueDependencies ( UrlContainer  urls)
protected

Adds resource dependencies for a load task.

Inside a loadFunction implementation you can call this function any number of times. When you call this function it informs the main thread about the dependencies of a load task, which then triggers the asynchronous loading of these dependencies.

Parameters
urlsContainer of dependency URLs.

Friends And Related Function Documentation

friend class ResourceManager
friend

Friend classes.

friend class FinishingQueue
friend

The documentation for this struct was generated from the following file: