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.sh
to set the environment variables.In most cases to compile the service it is enough to set:
KANZI_HOME
to point to the Kanzi workspace that contains theEngine/lib
folder for the given platform.KANZI_CONNECT_SDK
to point to the Kanzi Connect installationSDK
folder.
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:
configs
directory contains the SCons and android_gradle build files.interfaces
directory contains the XML service descriptions and thegenerate_interfaces.py
that you can use to generate C++ code from XML descriptions.sources
directory 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/nativeservices
to 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/definitions
directory.Export the Kanzi Connect simulator project with the services that you want to build. See Exporting a Simulator project.
For example, create the
<KanziWorkspace>/services
directory 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.py
script: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>_service
directories.Compile the service for Windows.
For example, to build the service for the
Win64GL_vs2019_Release_DLL
target, in the<KanziWorkspace>/services
runCompile the service for Linux.
To build the service for the
linux_x11_glx
target, in the<KanziWorkspace>/services
runWhen 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_Release
and 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_glx
with the platform name for which you want to build the service. For example, to build a service for QNX 7 aarch64, useqnx700_screen_aarch64
and run the service on the target hardware.In the
<KanziConnectInstallation>/configs/connect_server_config.xml
, add your service to the services sectionAdd the directories where the Kanzi Connect Server and libraries are stored, to the Linux library search path, and run the Kanzi Connect Server:
When the Kanzi Connect Server starts successfully, it prints the information to the console log:
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.