Kanzi 3.9.10
kanzi::ResourceManager::LoadTask Struct Referenceabstract

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

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

Inheritance diagram for kanzi::ResourceManager::LoadTask:
[legend]

Public Types

enum class  Type { LoadAndFinish , FinishOnly }
 The type of the load task. More...
 

Public Member Functions

virtual void finishFunction (const ResourceLoaderThreadContext *resourceLoaderThreadContext)=0
 The part of the loading that the main thread executes.
 
ResourceManagergetResourceManager () const
 Get the resource manager of a load task.
 
virtual ResourceSharedPtr getResult ()=0
 Returns the created resource.
 
Type getType () const
 Get the type of a load task.
 
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.
 
 LoadTask ()
 Constructor.
 
 LoadTask (const Type type)
 Constructor.
 
virtual ~LoadTask ()
 Destructor.
 

Protected Member Functions

void enqueueDependencies (UrlContainer urls)
 Add resource dependencies for the load task.
 

Friends

class FinishingQueue
 
class ResourceManager
 Friend classes.
 

Detailed Description

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

A load task is split into an optional loadFunction and mandatory finishFunction. The loadFunction may be called in a background worker thread, instead of the main thread. And so only thread independent work should be done here. While the finishFunction is guaranteed to be called in the main thread. The load task execution happens in this order:

  1. The loading thread or main thread execute the loadFunction.
  2. The main thread executes the finishFunction.
  3. The load task returns the created resource with getResult. Inside the loadFunction, a call to enqueueDependencies can be made to trigger background loading of dependencies.

Member Enumeration Documentation

◆ Type

The type of the load task.

Enumerator
LoadAndFinish 

Load task type with both loadFunction and finishFunction parts.

FinishOnly 

Load task type which does everything in the finishFunction only.

The loadFunction is guaranteed to be not called for such tasks.

Constructor & Destructor Documentation

◆ LoadTask() [1/2]

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

Constructor.

Type is set to LoadAndFinish.

◆ LoadTask() [2/2]

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

Constructor.

Parameters
typeLoad task type.

◆ ~LoadTask()

virtual kanzi::ResourceManager::LoadTask::~LoadTask ( )
virtual

Destructor.

Member Function Documentation

◆ loadFunction()

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.

◆ finishFunction()

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.

◆ getResult()

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

Returns the created resource.

Returns
The created resource.

Implemented in kanzi::ResourceProfilingLoadTask.

◆ getType()

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

Get the type of a load task.

Returns
The type of the load task.

◆ getResourceManager()

ResourceManager * kanzi::ResourceManager::LoadTask::getResourceManager ( ) const

Get the resource manager of a load task.

Returns
Pointer to resource manager.

◆ enqueueDependencies()

void kanzi::ResourceManager::LoadTask::enqueueDependencies ( UrlContainer urls)
protected

Add resource dependencies for the load task.

Can be called any number of times inside a loadFunction implementation. Informs the main thread of the dependencies, which can then trigger their async loading.

Parameters
urlsContainer of dependency urls.

Friends And Related Symbol Documentation

◆ ResourceManager

Friend classes.

◆ FinishingQueue


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