Use this base class to implement load tasks to load new resources. More...
#include <kanzi/core.ui/resource/resource_manager.hpp>
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... | |
| ResourceManager * | getResourceManager () 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 |
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:
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. |
|
explicit |
Constructor.
Type is set to LoadAndFinish.
|
explicit |
Constructor.
| type | Load task type. |
|
virtual |
Destructor.
|
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.
| resourceLoaderThreadContext | The context of the loader thread. |
Implemented in kanzi::ResourceProfilingLoadTask.
|
pure virtual |
The part of the loading that the main thread executes.
The function creates and stores a new resource that getResult returns.
| resourceLoaderThreadContext | The context of the loader thread that was used to call loadFunction. |
Implemented in kanzi::ResourceProfilingLoadTask.
|
pure virtual |
Returns the created resource.
Implemented in kanzi::ResourceProfilingLoadTask.
| Type kanzi::ResourceManager::LoadTask::getType | ( | ) | const |
Gets the type of a load task.
| ResourceManager* kanzi::ResourceManager::LoadTask::getResourceManager | ( | ) | const |
Gets the resource manager of a load task.
|
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.
| urls | Container of dependency URLs. |
|
friend |
Friend classes.
|
friend |