KernelSystems
Kernel systems are components used to expand the functionality provided by the kernel. They are initialized by the kernel and remain alive during all the lifetime of the kernel. They are similar to singletons but with an explicit order for initialization and desinitialization. Examples of Kernel Systems are: ConfigSystem, RenderSystem, ResourceSystem.
NoesisEngine is designed to be extended primarily using Kernel Systems.
Implementation
Kernel systems must inherit from base class BaseKernelSystem and reimplement the following functions:
- Init()
This function is invoked whenever the system is being initialized
- Shutdown()
Called when shutting down the kernel for each initialized system
- GetDependencies()
Each system must report the list of systems that it needs before being initialized. Using this information the kernel guarantees that systems are initialized in the proper order.
- KernelActivate()
This function is invoked by the kernel whenever a kernel system is being installed as a global kernel system accessible from everywhere. Normally the work done here is adding a special metadata to the proper interface. For example:
////////////////////////////////////////////////////////////////////////////// void VGLSystem::KernelActivate() { KernelActivateHelper<IVGLSystem>(); }This permits after system initialization getting a reference to the system this way:
NsGetSystem<IVGLSystem>()->CreateContext();
- KernelDeactivate()
This is the symmetric function to KernelActivate()
Initialization
There are two possible ways to initialized systems.
- The manual initialization. A list of the systems to initialize is given to the kernel. The kernel will initialize them in the proper order:
NsSymbol systems[] = {NsSymbol("CommandSystem"), NsSymbol("ConfigSystem"), NsSymbol("UnitTestSystem"), Symbol::Null()}; NsGetKernel()->InitSystems(systems);
- The automatic initialization, where all the registered systems in the installed packages are initialized in the proper order:
NsGetKernel()->InitSystems();
Getting access to kernel systems
To get a pointer to a kernelsystem you must include the header <NsCore/NsSystem.h> and use the different functions available for that purpose. For example:
// Getting access by symbol
{
const Ptr<IConfigSystem>& configSystem = NsGetSystem(NSS(ConfigSystem));
}
// Getting access by type. Faster than the symbol version
{
const Ptr<IConfigSystem>& configSystem = NsGetSystem<IConfigSystem>();
}
// Using the system without storing it
{
NsGetSystem<IConfigSystem>()->AddDomain(NSS(Domain0));
NsGetSystem<IConfigSystem>()->AddDomain(NSS(Domain1));
NsGetSystem<IConfigSystem>()->AddDomain(NSS(Domain2));
}
Lifetime
Kernel Systems remain alive during the Kernel lifetime. When the Kernel is shutdown, Kernel Systems are freed in reverse order of creation.