Using connection adapters

You can add transport layers as plugins. To enable support for a new connection type, implement these interfaces:

  • For the client implement ClientConnectionAdapter

  • For the server implement ConnectionAdapter

Before you can form a connection, you must register the plugins. See Configuring the server and Configuring the client.

Configuring the server

For Kanzi applications and Kanzi Connect Server the loading follows common Kanzi Engine plugin practices. Define a library with a createModule() entry point and provide a list of metaclasses in the getMetaclassesOverride() function.

These rules apply for the connection plugins:

  • Metaclasses must implement the ConnectBearerProvider interface.

  • Metaclass names must begin with connect.bearer.

    For example, connect.bearer.tcp.

  • You must register the library in a server configuration with the given name. You can also pass other configuration parameters for connection adapter plugins. For reference see the connection.xml files of the example projects.

    For example, <KanziConnectInstallation>\SDK\examples\IVI\Application\bin\connection.xml.

Configuring the client

Before forming a connection you must register the connection adapter on the client side.

Kanzi Engine Plugins

When registering the plugin metadata it is recommended to use the registerConnectionAdapter method from the kanzi::Context singleton. This is the first place where an instance of kanzi::Domain is available for a Kanzi Engine plugin. For example:

void MyPluginsModule::registerMetadataOverride(ObjectFactory& factory)
{
    if (m_domain)
    {
        ContextSharedPtr connectContext = Context::instance(*m_domain);
        connectContext->registerConnectionAdapter("connect.bearer.usb", ClientUsbConnectionAdapter::create);
    }
}

Console Applications

On console applications the kanzi::Client API is usually explicitly used and instantiated. You only need to add your connection provider before creating a connection. For example:

Client client;
client.registerConnectionAdapter("connect.bearer.usb", ClientUsbConnectionAdapter::create);

Java Applications

There are no Java bindings available for implementing new transport layers. The transport layer API is C++ only. - Java binding clients For the Kanzi Connect bindings library (AAR) you can add new C++ transports to the bearer registration in the <KanziConnectInstallation>\SDK\bindings\android\AndroidGradleAarCreator\kanziconnect\buildenv\bearer_cpp\AndroidBearerInstaller.cpp file. All transports registered in that file are automatically available for Android applications that use the Kanzi Connect bindings library. - Android server The Android example server registers TCP and SSL bearers by default. You can add new bearers by registering them in the <KanziConnectInstallation>\SDKexamples\AndroidServer\Application\configs\platforms\android\jni_src\runner.cpp file in the same way as the existing bearers.