Inspirel banner

Programming Distributed Systems with YAMI4

6.4.2 C++

Assuming that the agent is already properly set up, the publisher side in C++ can be implemented as follows:

value_publisher my_value;

my_agent.register_value_publisher("some_value", my_value);

Above, my_agent is an agent object that will be used to manage all communication for this value publisher and "some_value" is an object name that will be visible to remote agents. This operation internally registers a regular object with the given name and provides the message handler that understands the ``subscribe'' and ``unsubscribe'' messages and implements proper management of subscribers.

The publisher can send new parameters value by calling the publish() function with new value:

parameters content;
// fill the content object appropriately
// ...

my_value.publish(content);

When the publish() function is invoked, all subscribers that are on the internally managed list are notified with a message named "subscription_update" that is sent to the object which name was given when the subscription was established.

The user-defined callable entity (function or functor) can be provided as a constructor parameter when the published value is created in order to extend the functionality of the value publisher with user-provided implementations of additional messages. Any regular handler can be registered (at most once) and all messages that are received by the value publisher will be delegated to that additional handler.