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. See Deploying Kanzi Connect applications to embedded devices.

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 the generate_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:

  1. Copy the Kanzi Connect service template directory from <KanziConnectInstallation>/templates/servicetemplate to the <KanziConnectWorkspace>/Projects directory.

  2. Generate the C++ code from custom interface XML.

    1. 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 is myservice_interface.xml.

    2. 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

  3. Compile the service for Linux.

    1. In the configs/platforms/common/config.py change the line

      defineServiceLibraryTarget("test", "service_test", sdk_root, code_root, service_root)
      

      to

      defineServiceLibraryTarget("myservice", "service_myservice", sdk_root, code_root, service_root)
      
    2. To build the service for the linux_x11_glx_cpp11 target, in the configs/platforms/linux_x11_glx_cpp11 run

      scons 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 directory output/linux_x11_glx_cpp11/GL_Release and the binary name contains the name of your service. For example, libservice_myservice.so.

    3. 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
      
    4. 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.

../../_images/myserviceonserver.png