Integrating Kanzi Monitor as a prebuilt library

You can integrate Kanzi Monitor as a prebuilt library into your Kanzi application project. The prebuilt libraries are located in the <KanziWorkspace>/Engine/plugins/monitor/lib directory.

Integrating to Windows projects with CMake and Visual Studio

To integrate Kanzi Monitor as a library to a Windows application project:

  1. In the top-level CMakeLists.txt, add the Kanzi Monitor library root directory location to the CMake configuration.

    set(PLUGIN_COMMON_SETUP cmake/common-setup.cmake)
    
    # KANZI_MONITOR_ROOT can be set explicitly: cmake -DKANZI_MONITOR_ROOT=<path>
    # If not set, auto-detection from known locations is attempted.
    if(NOT KANZI_MONITOR_ROOT)
        if(EXISTS ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor/${PLUGIN_COMMON_SETUP})
            set(KANZI_MONITOR_ROOT ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor)
        elseif(DEFINED ENV{KANZI_HOME} AND
               EXISTS "$ENV{KANZI_HOME}/Engine/plugins/monitor/${PLUGIN_COMMON_SETUP}")
            set(KANZI_MONITOR_ROOT "$ENV{KANZI_HOME}/Engine/plugins/monitor")
        endif()
        if(NOT KANZI_MONITOR_ROOT)
            message(FATAL_ERROR
                "Cannot find Monitor plugin root directory. "
                "Pass -DKANZI_MONITOR_ROOT=<path> to CMake, set the KANZI_HOME "
                "environment variable to your Kanzi workspace root, or install "
                "the plugin under 'WORKSPACE/Engine/plugins'.")
        endif()
    endif()
    
    include(${KANZI_MONITOR_ROOT}/${PLUGIN_COMMON_SETUP})
    include(${KANZI_MONITOR_ROOT}/cmake/monitor-config.cmake)
    
  2. Append the Kanzi Monitor plugin DLL path to the debugger environment variable of Visual Studio.

    This enables the Visual Studio debugger to locate the plugin DLL path automatically when launching the debugger.

    # Add the Kanzi Monitor library location to the VS debugger environment.
    set_target_properties(<ProjectName> PROPERTIES
        VS_DEBUGGER_ENVIRONMENT
        "${KANZI_VS_DEBUGGER_ENVIRONMENT};${KANZI_MONITOR_ROOT}/${PLATFORM_LIBRARY_DIR}")
    
  3. (Optional) If the Kanzi Monitor plugin is not added to the Kanzi Studio project, enable the plugin by adding it to the ModuleNames configuration option in application.cfg:

    ModuleNames = "kzmonitor"
    
  4. (Optional) Link the application executable with the Kanzi Monitor library.

    This is needed only if the application code uses the Kanzi Monitor API directly, for example to register custom commands or access the module instance. Linking resolves compile-time symbols but does not register the plugin at runtime. You still need to register the plugin through one of these methods:

    • Add kzmonitor to the Kanzi Studio project.

    • Set ModuleNames = "kzmonitor" in application.cfg.

    • Call configuration.moduleNames = { "kzmonitor" }; in onConfigure().

    Locate the CMakeLists.txt for the application executable:

    • If the project uses the Basic Application template, it is in the <KanziWorkspace>\Projects\<ProjectName>\Application directory.

    • If the project uses the Engine Plugin or Datasource plugin template, it is in the <KanziWorkspace>\Projects\<ProjectName>\Application\src\executable directory.

    Link with the Kanzi Monitor library:

    target_link_libraries(${PROJECT_NAME} ${KANZI_MONITOR_NAMESPACE}kzmonitor)
    
  5. (Optional) Enable the application executable to use the Kanzi Monitor C++ API.

    In the CMakeLists.txt for the application executable, add the Kanzi Monitor headers to the include directories:

    # Add the Kanzi Monitor include path.
    target_include_directories(${PROJECT_NAME}
        PRIVATE ${KANZI_MONITOR_ROOT}/include)
    
  6. Regenerate the project from the updated CMake files.

    For example, run the generate_cmake_vs2019_solution.bat script.

  7. Make sure that the application has the necessary privileges to write files and open TCP sockets.

Integrating to Android projects with Gradle, CMake, and Android Studio

Note

On Android, you must link Kanzi Monitor with target_link_libraries at build time. Dynamic plugin loading via ModuleNames alone does not work on Android because RTTI type information is not shared across .so library boundaries, which prevents the Kanzi Engine from recognizing the plugin module.

To integrate Kanzi Monitor as a library to an Android application project:

  1. In the CMakeLists.txt, add the Kanzi Monitor library root directory location to the CMake configuration.

    Add these configurations after find_kanzi() and find_package() calls.

    set(PLUGIN_COMMON_SETUP cmake/common-setup.cmake)
    
    # KANZI_MONITOR_ROOT can be set explicitly: cmake -DKANZI_MONITOR_ROOT=<path>
    # If not set, auto-detection from known locations is attempted.
    if(NOT KANZI_MONITOR_ROOT)
        if(EXISTS ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor/${PLUGIN_COMMON_SETUP})
            set(KANZI_MONITOR_ROOT ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor)
        elseif(DEFINED ENV{KANZI_HOME} AND
               EXISTS "$ENV{KANZI_HOME}/Engine/plugins/monitor/${PLUGIN_COMMON_SETUP}")
            set(KANZI_MONITOR_ROOT "$ENV{KANZI_HOME}/Engine/plugins/monitor")
        endif()
        if(NOT KANZI_MONITOR_ROOT)
            message(FATAL_ERROR
                "Cannot find Monitor plugin root directory. "
                "Pass -DKANZI_MONITOR_ROOT=<path> to CMake, set the KANZI_HOME "
                "environment variable to your Kanzi workspace root, or install "
                "the plugin under 'WORKSPACE/Engine/plugins'.")
        endif()
    endif()
    
    include(${KANZI_MONITOR_ROOT}/${PLUGIN_COMMON_SETUP})
    include(${KANZI_MONITOR_ROOT}/cmake/monitor-config.cmake)
    
  2. Link Kanzi Monitor plugin to your application:

    target_link_libraries(${PROJECT_NAME} ${KANZI_MONITOR_NAMESPACE}kzmonitor)
    
  3. If the Kanzi Monitor plugin is not added to the Kanzi Studio project, enable the plugin by adding it to the ModuleNames configuration option in application.cfg:

    ModuleNames = "kzmonitor"
    

    This is the recommended registration method for Android because it works with both Kanzi application frameworks:

    • appfw (Basic Application template) – The application has a C++ ExampleApplication subclass, so you can alternatively set configuration.moduleNames = { "kzmonitor" }; in onConfigure().

    • droidfw (Android Application template) – The application lifecycle is Java-driven and the C++ source is a stub, so application.cfg is the only viable registration path.

  4. Regenerate the project from the updated CMake files.

    For example, update your Android Studio and Gradle environment with the changes that you made to the CMake files.

  5. Make sure that the application has the necessary privileges to write files and open TCP sockets. See Setting permissions on Android.

  6. (Optional) If you need to use the Kanzi Monitor Java API, add AAR modules to the Android Studio project.

    In Android Studio, go to the build.gradle file of your application and add Kanzi Monitor modules as dependencies:

    def monitorLibDir = getKanzi().toString() + '/Engine/plugins/monitor/lib/android'
    
    dependencies {
        debugImplementation     files("$monitorLibDir/monitor-debug.aar")
        profilingImplementation  files("$monitorLibDir/monitor-profiling.aar")
        releaseImplementation    files("$monitorLibDir/monitor-release.aar")
    }
    

Integrating to QNX and Linux projects with SCons

To integrate Kanzi Monitor as a prebuilt library to a QNX or Linux application project:

  1. Locate the Kanzi Monitor prebuilt libraries.

    After installation, the prebuilt libraries are at <KanziWorkspace>/Engine/plugins/monitor/lib/<platform_name>/<profile_string>/.

  2. Edit the configs/platforms/common/config.py file of your project to define the kzmonitor prebuilt library.

    Add the following before the application module definition:

    # Path to Monitor plugin directory.
    monitor_dir = os.path.join(engine_root, "plugins", "monitor")
    
    # Define the kzmonitor prebuilt library.
    kzmonitor_lib = library("kzmonitor")
    kzmonitor_lib.include_paths += [os.path.join(monitor_dir, "include")]
    kzmonitor_lib.libpaths += [
        os.path.join(monitor_dir, "lib", platform_name, profile_string)]
    kzmonitor_lib.binaries += ["kzmonitor"]
    del kzmonitor_lib
    
  3. In the same file, add kzmonitor to the used libraries of the application module:

    m = module(project_name)
    m.used_libraries += ["kzmonitor"]
    del m
    
  4. For QNX targets, add the socket library in the platform-specific config.py.

    For example, in configs/platforms/qnx710_screen_aarch64/config.py:

    m = module(project_name)
    m.env["LIBS"] += ["socket"]
    del m
    
  5. If the Kanzi Monitor plugin is not added to the Kanzi Studio project, enable the plugin by adding it to the ModuleNames configuration option in application.cfg:

    ModuleNames = "kzmonitor"
    
  6. (Optional) If the application code uses the Kanzi Monitor C++ API, add the Kanzi Monitor include path to the application module:

    m.include_paths += [os.path.join(monitor_dir, "include")]
    
  7. Build the project from the platform-specific SConstruct directory.

    For example:

    scons release ES3
    
  8. Make sure that the application has the necessary privileges to write files and open TCP sockets.

See also

Integrating Kanzi Monitor from source code

Getting started with Kanzi Monitor