CoreRef
Interface Overview
CoreRef is the root handle type for invoking framework functionality. It can be obtained in two ways:
When a developer inherits the
ModuleBasetype to implement their ownModule, the AimRT framework passes aCoreRefhandle in theInitializemethod;When using the Create Module approach, AimRT returns the corresponding module’s
CoreRefhandle after creating aModule;
The core interfaces provided in CoreRef are as follows:
Info()->ModuleInfo: Get module information;GetConfigurator()->ConfiguratorRef: Get configuration handle;GetLogger()->LoggerRef: Get logger handle;GetExecutorManager()->ExecutorManagerRef: Get executor handle;GetRpcHandle()->RpcHandleRef: Get RPC handle;GetChannelHandle()->ChannelHandleRef: Get Channel handle;
Key points regarding the use of CoreRef:
The AimRT framework generates a dedicated
CoreRefhandle for each module to enable features like resource isolation and monitoring. The module it belongs to can be identified via theCoreRef::Infointerface.Corresponding component handles can be obtained through the
GetXXXinterfaces inCoreRefto invoke related functionalities. Refer to the documentation for specific components:
Usage Examples
Below is a simple usage example demonstrating how to obtain and use the CoreRef handle when inheriting the ModuleBase type:
import aimrt_py
class HelloWorldModule(aimrt_py.ModuleBase):
def Initialize(self, core):
assert(isinstance(core, aimrt_py.CoreRef))
# Get log handle
logger = core.GetLogger()
# Use log handle
aimrt_py.info(logger, "This is a test log")
return True
Below is another simple usage example demonstrating how to obtain and use the CoreRef handle in App mode:
import aimrt_py
def main():
aimrt_core = aimrt_py.Core()
# Initialize
core_options = aimrt_py.CoreOptions()
core_options.cfg_file_path = "path/to/cfg/xxx_cfg.yaml"
aimrt_core.Initialize(core_options)
# Get module handle
module_handle = aimrt_core.CreateModule("HelloWorldPyModule")
assert(isinstance(module_handle, aimrt_py.CoreRef))
# Use log handle
aimrt_py.info(module_handle.GetLogger(), "This is an example log.")
# ...
if __name__ == '__main__':
main()