|
Assuming that the agent is already properly set up, the publisher side in Ada can be implemented as follows:
declare My_Value : Value_Publisher; begin My_Value.Register_At (My_Agent'Unchecked_Access, "some_value"); -- ... end;
Above, My_Agent
is an aliased 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
operation with new value:
declare Content : Parameter_Collection := Make_Parameters; begin -- fill the content object appropriately -- ... My_Value.Publish (Content); end;
When the Publish
operation 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 Register_User_Handler
operation can be used to extend the functionality of the value publisher with user-provided implementations of additional messages. Any regular message handler can be registered (at most once) and all messages that are received by the value publisher will be delegated to that additional handler.