Contents
MessageBus component
The MessageBus
component implements the message bus that ensures receipt, distribution and delivery of messages between programs running KasperskyOS. This bus is based on the publisher-subscriber model. Use of a message bus lets you avoid having to create a large number of IPC channels to connect each subscriber program to each publisher program.
Messages transmitted through the MessageBus
cannot contain data. These messages can be used only to notify subscribers about events.
The MessageBus
component provides an additional level of abstraction over KasperskyOS IPC that helps simplify the development and expansion of your programs. MessageBus
is a separate program that is accessed through IPC. However, developers are provided with a MessageBus
access library that lets you avoid direct use of IPC calls.
The API of the access library provides the following interfaces:
IProviderFactory
- Provides factory methods for obtaining access to instances of all other interfaces.
IProviderControl
- Interface for registering and deregistering a publisher and subscriber in the bus.
IProvider (MessageBus component)
- Interface for transferring a message to the bus.
ISubscriber
- Callback interface for sending a message to a subscriber.
IWaiter
- Interface for waiting for a callback when the corresponding message appears.
Message structure
Each message contains two parameters:
topic
- Identifier of the message subject.
id
- Additional parameter that identifies a particular message.
The topic
and id
parameters are unique for each message. The interpretation of topic
+id
is determined by the contract between the publisher and subscriber. For example, if there are changes to the configuration data used by the publisher and subscriber, the publisher forwards a message regarding the modified data and the id
of the specific entry containing the new data. The subscriber uses mechanisms outside of the MessageBus
to receive the new data based on the id
key.
IProviderFactory interface
The IProviderFactory
interface provides factory methods for receiving the interfaces necessary for working with the MessageBus
component.
A description of the IProviderFactory
interface is provided in the file named messagebus/i_messagebus_control.h
.
An instance of the IProviderFactory
interface is obtained by using the free InitConnection()
function, which receives the name of the IPC channel between your application and the MessageBus
program. The connection name is defined in the init.yaml.in
file when describing the solution configuration. If the connection is successful, the output parameter contains a pointer to the IProviderFactory
interface.
- The interface for registering and deregistering (see "IProviderControl interface") publishers and subscribers in the message bus is obtained by using the
IProviderFactory::CreateBusControl()
method. - The interface containing the methods enabling the publisher to send messages to the bus (see "IProvider interface (MessageBus component)") is obtained by using the
IProviderFactory::CreateBus()
method. - The interfaces containing the methods enabling the subscriber to receive messages from the bus (see "ISubscriber, IWaiter and ISubscriberRunner interfaces") are obtained by using the
IProviderFactory::CreateCallbackWaiter
andIProviderFactory::CreateSubscriberRunner()
methods.It is not recommended to use the
IWaiter
interface, because calling a method of this interface is a locking call.
i_messagebus_control.h (fragment)
IProviderControl interface
The IProviderControl
interface provides the methods for registering and deregistering publishers and subscribers in the message bus.
A description of the IProviderControl
interface is provided in the file named messagebus/i_messagebus_control.h
.
The IProviderFactory
interface is used to obtain an interface instance.
Registering and deregistering a publisher
The IProviderControl::RegisterPublisher()
method is used to register the publisher in the message bus. This method receives the message subject and puts the unique ID of the bus client into the output parameter. If the message subject is already registered in the bus, the call will be declined and the client ID will not be filled.
The IProviderControl::UnregisterPublisher()
method is used to deregister a publisher in the message bus. This method accepts the bus client ID received during registration. If the indicated ID is not registered as a publisher ID, the call will be declined.
i_messagebus_control.h (fragment)
Registering and deregistering a subscriber
The IProviderControl::RegisterSubscriber()
method is used to register the subscriber in the message bus. This method accepts the subscriber name and the list of subjects of messages for the necessary subscription, and puts the unique ID of the bus client into the output parameter.
The IProviderControl::UnregisterSubscriber()
method is used to deregister a subscriber in the message bus. This method accepts the bus client ID received during registration. If the indicated ID is not registered as a subscriber ID, the call will be declined.
i_messagebus_control.h (fragment)
IProvider interface (MessageBus component)
The IProvider
interface provides the methods enabling the publisher to send messages to the bus.
A description of the IProvider
interface is provided in the file named messagebus/i_messagebus.h
.
The IProviderFactory
interface is used to obtain an interface instance.
Sending a message to the bus
The IProvider::Push()
method is used to send a message. This method accepts the bus client ID received during registration and the message ID. If the message queue in the bus is full, the call will be declined.
i_messagebus.h (fragment)
ISubscriber, IWaiter and ISubscriberRunner interfaces
The ISubscriber
, IWaiter
, and ISubscriberRunner
interfaces provide the methods enabling the subscriber to receive messages from the bus and process them.
Descriptions of the ISubscriber
, IWaiter
and ISubscriberRunner
interfaces are provided in the file named messagebus/i_subscriber.h
.
The IProviderFactory
interface is used to obtain instances of the IWaiter
and ISubscriberRunner
interfaces. The implementation of the ISubscriber
callback interface is provided by the subscriber application.
Receiving a message from the bus
You can use the IWaiter::Wait()
or ISubscriberRunner::Run()
method to switch a subscriber to standby mode, waiting for a message from the bus. These methods accept the bus client ID and the pointer to the ISubscriber
callback interface. If the client ID is not registered, the call will be declined.
It is not recommended to use the IWaiter
interface, because calling the IWaiter::Wait()
method is a locking call.
The ISubscriber::OnMessage()
method will be called when a message is received from the bus. This method accepts the message subject and message ID.
i_subscriber.h (fragment)