diff options
author | David Robillard <d@drobilla.net> | 2012-12-21 02:51:35 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-12-21 02:51:35 +0000 |
commit | 853dee67639d73178f036c192ea5d98d74fb39e3 (patch) | |
tree | 3da9bd4792431ae2c8c6153729059b1c23ebd696 /src/server/Broadcaster.hpp | |
parent | aac9cbc534ab57a5471b121523bd8308e857c228 (diff) | |
download | ingen-853dee67639d73178f036c192ea5d98d74fb39e3.tar.gz ingen-853dee67639d73178f036c192ea5d98d74fb39e3.tar.bz2 ingen-853dee67639d73178f036c192ea5d98d74fb39e3.zip |
Add Broadcaster::Transfer for scoped recursion-safe reply bundling.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4868 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server/Broadcaster.hpp')
-rw-r--r-- | src/server/Broadcaster.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/server/Broadcaster.hpp b/src/server/Broadcaster.hpp index 3af4e5b7..621b6b61 100644 --- a/src/server/Broadcaster.hpp +++ b/src/server/Broadcaster.hpp @@ -42,9 +42,31 @@ namespace Server { class Broadcaster : public Interface { public: + Broadcaster() : _bundle_depth(0) {} + void register_client(const Raul::URI& uri, SharedPtr<Interface> client); bool unregister_client(const Raul::URI& uri); + /** A handle that represents a transfer of possibly several changes. + * + * This object going out of scope signifies the transfer is completed. + * This makes doing the right thing in recursive functions that send + * updates simple (e.g. Event::post_process()). + */ + struct Transfer : public Raul::Noncopyable { + Transfer(Broadcaster& b) : broadcaster(b) { + if (++broadcaster._bundle_depth == 1) { + broadcaster.bundle_begin(); + } + } + ~Transfer() { + if (--broadcaster._bundle_depth == 0) { + broadcaster.bundle_end(); + } + } + Broadcaster& broadcaster; + }; + SharedPtr<Interface> client(const Raul::URI& uri); void send_plugins(const BlockFactory::Plugins& plugin_list); @@ -109,10 +131,13 @@ public: void error(const std::string& msg) { BROADCAST(error, msg); } private: + friend class Transfer; + typedef std::map< Raul::URI, SharedPtr<Interface> > Clients; Glib::Mutex _clients_mutex; Clients _clients; + unsigned _bundle_depth; }; } // namespace Server |