Kanzi Connect service template¶
Use the Kanzi Connect service template as a basis for creating custom service plugins for embedded targets.
The code generation can provide the build files for Windows, Android, and most embedded platforms. You can use the build files to generate and compile the included service definitions, but this topic does not cover the compilation on Visual Studio.
Requirements¶
To generate code you must have Kanzi Connect and its dependencies installed.
To compile the service on Linux, you must have Kanzi Connect for Linux extracted on a Linux host and the environment variables set.
You can use the helper script
<KanziConnectInstallation>/SDK/setup_env.shto set the environment variables.In most cases to compile the service it is enough to set:
KANZI_HOMEto point to the Kanzi workspace that contains theEngine/libfolder for the given platform.KANZI_CONNECT_SDKto point to the Kanzi Connect installationSDKfolder.
The structure of the Kanzi Connect service template¶
The Kanzi Connect service template includes the example service you can create by completing the Create a custom service tutorial. See Tutorial: Create a custom Kanzi Connect service.
The only difference is the directory structure, which allows for more convenient cross-compilation using SCons:
configsdirectory contains the SCons and android_gradle build files.interfacesdirectory contains the XML service descriptions and thegenerate_interfaces.pythat you can use to generate C++ code from XML descriptions.sourcesdirectory contains the generated and modified source code and CMake build files.
You can find the Kanzi Connect service template in the <KanziConnectInstallation>/templates/nativeservices directory.
Using the Kanzi Connect service template¶
To use the Kanzi Connect service template:
To generate to directory structure required by the code generation, either:
Copy the Kanzi Connect service template directory
<KanziConnectInstallation>/templates/nativeservicesto a directory where you want to create a Kanzi Connect service.For example, copy and rename the template directory to
<KanziWorkspace>/services.Place the XML files that describe the service interfaces to the
<KanziWorkspace>/services/interfaces/definitionsdirectory.Export the Kanzi Connect simulator project with the services that you want to build. See Exporting a Simulator project.
For example, create the
<KanziWorkspace>/servicesdirectory and extract the contents of the simulator project into the directory.
To generate the C++ code from the custom interface XML, execute the
<KanziWorkspace>/services/interfaces/generate_interfaces.pyscript:cd interfaces py -3 generate_interfaces.py
This way you generate the sources and build files for all service descriptions in the
interfaces/definitions/directory and store the generated code of the services in thesources/services/<service_identifier>_servicedirectories.Compile the service for Windows.
For example, to build the service for the
Win64GL_vs2019_Release_DLLtarget, in the<KanziWorkspace>/servicesrunpy -3 %KANZI_CONNECT_SDK%\build_app.py --config GL_vs2019_Release_DLL --gfx_api GL --dynamic . win64
Compile the service for Linux.
To build the service for the
linux_x11_glxtarget, in the<KanziWorkspace>/servicesrunpython3 $KANZI_CONNECT_SDK/build_app.py --config Release --gfx_api GL --dynamic . linux_x11_glx
When you want to create static libraries, omit
--dynamic.When successfully compiled, you can find the service binary in the directory
<KanziWorkspace>services/lib/service_myservice/linux_x11_glx/GL_Releaseand the binary name contains the name of your service. For example,libservice_test.so.To build the service library for other platforms, replace the platform name
linux_x11_glxwith the platform name for which you want to build the service. For example, to build a service for QNX 7 aarch64, useqnx700_screen_aarch64and run the service on the target hardware.In the
<KanziConnectInstallation>/configs/connect_server_config.xml, add your service to the services section<services> ... <service library="service_test" name="test" optional="true" /> </services
Add the directories where the Kanzi Connect Server and libraries are stored, to the Linux library search path, and run the Kanzi Connect Server:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$KANZI_CONNECT_SDK/lib/linux_x11_glx/GL_Release:$KANZI_HOME/services/lib/linux_x11_glx/GL_Release $KANZI_CONNECT_SDK/lib/linux_x11_glx/GL_Release/connect_server
When the Kanzi Connect Server starts successfully, it prints the information to the console log:
2021-08-05T11:01:09+0300 140121170081600 INF [connectdomain] Registered metaclass Connect.Service.Test from module: service_test 2021-08-05T11:01:09+0300 140121170081600 INF [connectdomain] Registered module with name service_test
You must run the first command only once. It enables the Kanzi Connect Server to find your library. Alternatively, copy the service library to the directory where the connect_server application is.