Kanzi  3.9.5
Kanzi Engine API
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  Type { Type::LoadAndFinish, Type::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. More...
 
ResourceManagergetResourceManager () const
 Get the resource manager of a load task. More...
 
virtual ResourceSharedPtr getResult ()=0
 Returns the created resource. More...
 
Type getType () const
 Get the type of a load task. 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...
 
 LoadTask ()
 Constructor. More...
 
 LoadTask (const Type type)
 Constructor. More...
 
virtual ~LoadTask ()
 Destructor. More...
 

Protected Member Functions

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

Friends

class FinishingQueue
 
class ResourceManager
 Friend classes. More...
 

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 Function Documentation

◆ ResourceManager

friend class ResourceManager
friend

Friend classes.

◆ FinishingQueue

friend class FinishingQueue
friend

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