Accessing services that run locally¶
Discovering local services¶
When you need to get access to a service running on the same Kanzi Connect Server, use the ConnectDomain
object. The ConnectDomain
object is available for all Kanzi Connect services. The ConnectDomain
object is aware of all locally registered services and can provide direct access to them.
When you want to gain access to other services, override the onStartServiceRequest
method which is called when a service needs to start its operation. At that point all the preconfigured services are loaded.
Using local content client¶
You need the local content client when you want a service that runs locally to subscribe to or provide content. To use the local content client, you must access the Content Service. This example shows how you can construct a local content client
...
#include <connect/connectdomain.hpp>
#include <content_service/content_manager.hpp>
#include <content_service/content_client_local.hpp>
...
AbstractServiceSharedPtr ContentService =
getDomain()->getServiceLookup()->lookupLocalService("Connect.CoreService.Content");
ContentManagerSharedPtr ContentManager =
dynamic_pointer_cast<ContentManager>(ContentService);
LocalContentClientSharedPtr contentClient = LocalContentClient::create(ContentManager);
Using the Virtual file local client¶
When a service that runs locally wants to publish content to the server, you must use the local virtual file client. This example shows how you can construct a local virtual file client.
...
#include <connect/connectdomain.hpp>
#include <virtualfile_service/virtualfile_service.hpp>
#include <virtualfile_service/virtualfilelocalclient.hpp>
...
AbstractServiceSharedPtr abstractService =
getDomain()->getServiceLookup()->lookupLocalService("Connect.CoreService.Virtualfile");
auto virtualFileService =
dynamic_pointer_cast<VirtualFileService>(abstractService);
VirtualFileLocalClientSharedPtr Client =
VirtualFileLocalClient::create(virtualFileService);
auto Token = Client->registerPath("http", "/serve/", this);