Kanzi Connect service template¶
Use the Kanzi Connect service template as a basis for creating custom service plugins for embedded targets.
The template includes a Windows solution which you can use to compile the included test service, but this topic does not cover the compilation on Windows.
You can use this template to compile the service library for QNX7. Follow the same instructions, but run the service on the target hardware.
Requirements¶
To generate code on Windows you must have the Kanzi Connect for Windows installed.
To compile the service on Linux, you must have the Kanzi Connect for Linux extracted on a Linux host and the environment variables set as described in
<KanziConnectInstallation>/SDK/EMBEDDED_TARGETS_README.txt
.
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:
Application
directory contains the SCons build files and the Visual Studio project.interfaces
directory contain the XML service descriptions and thegenerate_interfaces.py
that you can use to generate C++ code from an XML description.sources
directory contains the generated and modified source code.
You can find the Kanzi Connect service template in the <KanziConnectInstallation>/templates
/servicetemplate directory.
Using the Kanzi Connect service template¶
To use the Kanzi Connect service template:
Copy the Kanzi Connect service template directory from
<KanziConnectInstallation>/templates/servicetemplate
to the<KanziConnectWorkspace>/Projects
directory.Generate the C++ code from custom interface XML.
Place the XML file that describes the services interface to the
interfaces/definitions
directory. This procedure assumes that the name of the file which contains the description ismyservice_interface.xml
.Execute the
<KanziConnectInstallation>/SDK/interfaces/generate.py
$KANZI_CONNECT_SDK/interfaces/generate.py interfaces/definitions/myservice_interface.xml sources/services/myservice_service/interface user --pluginoutput sources/plugins/myservice_service
This command generates the sources for a non-core service from the service description in
interfaces/definitions/myservice_interface.xml
and stores the generated code of the service to these directories:sources/services/myservice_service
sources/plugins/myservice_service
Compile the service for Linux.
In the
configs/platforms/common/config.py
change the linedefineServiceLibraryTarget("test", "service_test", sdk_root, code_root, service_root)
to
defineServiceLibraryTarget("myservice", "service_myservice", sdk_root, code_root, service_root)
To build the service for the
linux_x11_glx_cpp11
target, in theconfigs/platforms/linux_x11_glx_cpp11
runscons project_name=service_myservice release --dynamic
When you want to create static libraries, omit
--dynamic
. When successfully compiled, you can find the service binary in the directoryoutput/linux_x11_glx_cpp11/GL_Release
and the binary name contains the name of your service. For example,libservice_myservice.so
.In the
<KanziConnectInstallation>/configs/connect_server_config.xml
, add your service to the services section<services> ... <service library="service_myservice" name="myservice" optional="true" /> </services
Add the directory where the binary is stored to the Linux library search path and run the Kanzi Connect Server:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd) output/linux_x11_glx_cpp11/GL_vs2015_Release_DLL/connect_server
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.