XmlListener/Broadcaster


#1

[size=75]It’s going to be part of Tampon, but as that’s still got a while to go before it’s ready for release, I’ll post it here separately…[/size]

You know the score already - it’s the same as Change/Action Broadcaster/Listener, but it uses XML.

Download XmlListener.zip

XmlBroadcasters can call ‘broadcastXml (XmlElement* xml)’ to send an xml structure to all registered listeners.

XmlListeners have ‘xmlCallback (const XmlElement& xml)’ to respond with.

I’m sure it’s quite obvious how it can be useful. It’s basically the same as ActionListener but allows more complex information to be passed around. Should be thread safe etc…, it follows exactly the same message delivery system as ActionBroadcaster.

The (perhaps) ‘interesting’ part is how the XML is passed around.

  • Because each listener has to respond to its own message, each message needs access to the Xml data.

  • If each message had its own copy, that would be unacceptable (copying XmlElements willy-nilly! who knows how big you might want them to be!),

-…but we can’t keep a local copy ‘til its done’ because we don’t know when that’ll be.

So, it uses some reference counting shenanigans, by way of a handy template ‘Evanescent’ [broaden your vocabulary with Tampon!]; it’s designed to wrap an object that you know should only exist for a short time, but you don’t really know how long. As long as there are tokens for it, it will stay alive. In this case, each message has a token to the Evanescent, and when the last one has been processed, the data will be destroyed.

Tidy!