diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/ClientBroadcaster.cpp | 138 | ||||
-rw-r--r-- | src/engine/ClientBroadcaster.hpp | 52 | ||||
-rw-r--r-- | src/engine/HTTPEngineReceiver.cpp | 6 |
3 files changed, 47 insertions, 149 deletions
diff --git a/src/engine/ClientBroadcaster.cpp b/src/engine/ClientBroadcaster.cpp index 1da56af6..482d25e6 100644 --- a/src/engine/ClientBroadcaster.cpp +++ b/src/engine/ClientBroadcaster.cpp @@ -89,42 +89,10 @@ ClientBroadcaster::client(const URI& uri) void -ClientBroadcaster::bundle_begin() -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->bundle_begin(); -} - - -void -ClientBroadcaster::bundle_end() -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->bundle_end(); -} - - -void -ClientBroadcaster::transfer_begin() -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->transfer_begin(); -} - - -void -ClientBroadcaster::transfer_end() -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->transfer_end(); -} - - -void -ClientBroadcaster::error(const string& msg) +ClientBroadcaster::send_plugins(const NodeFactory::Plugins& plugins) { - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->error(msg); + for (Clients::const_iterator c = _clients.begin(); c != _clients.end(); ++c) + send_plugins_to((*c).second, plugins); } @@ -142,108 +110,16 @@ ClientBroadcaster::send_plugins_to(ClientInterface* client, const NodeFactory::P } -void -ClientBroadcaster::send_plugins(const NodeFactory::Plugins& plugins) -{ - for (Clients::const_iterator c = _clients.begin(); c != _clients.end(); ++c) - send_plugins_to((*c).second, plugins); -} - - -void -ClientBroadcaster::del(const Path& path) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->del(path); -} - - -void -ClientBroadcaster::connect(const Path& src_port_path, const Path& dst_port_path) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->connect(src_port_path, dst_port_path); -} - - -void -ClientBroadcaster::disconnect(const Path& src_port_path, const Path& dst_port_path) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->disconnect(src_port_path, dst_port_path); -} - - -void -ClientBroadcaster::put(const Raul::URI& subject, const Shared::Resource::Properties& properties) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->put(subject, properties); -} - - -/** Send notification of a property update. +/** Send an object to all clients. * - * Like control changes, does not send update to client that set the property, if applicable. - */ -void -ClientBroadcaster::set_property(const URI& subject, const URI& key, const Atom& value) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->set_property(subject, key, value); -} - - -/** Send notification of a control change. - * - * If responder is specified, the notification will not be send to the address of - * that responder (to avoid sending redundant information back to clients and - * forcing clients to ignore things to avoid feedback loops etc). - */ -void -ClientBroadcaster::set_port_value(const Path& port_path, const Raul::Atom& value) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->set_port_value(port_path, value); -} - - -void -ClientBroadcaster::set_voice_value(const Path& port_path, uint32_t voice, const Raul::Atom& value) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->set_voice_value(port_path, voice, value); -} - - -void -ClientBroadcaster::activity(const Path& path) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->activity(path); -} - - -/** Send an object. - * - * @param p Object to send + * @param o Object to send * @param recursive If true send all children of object */ void -ClientBroadcaster::send_object(const GraphObjectImpl* p, bool recursive) -{ - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - ObjectSender::send_object((*i).second, p, recursive); -} - - -/** Sends notification of an GraphObject's renaming - */ -void -ClientBroadcaster::move(const Path& old_path, const Path& new_path) +ClientBroadcaster::send_object(const GraphObjectImpl* o, bool recursive) { for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) - (*i).second->move(old_path, new_path); + ObjectSender::send_object((*i).second, o, recursive); } diff --git a/src/engine/ClientBroadcaster.hpp b/src/engine/ClientBroadcaster.hpp index 85524416..cfe0a14f 100644 --- a/src/engine/ClientBroadcaster.hpp +++ b/src/engine/ClientBroadcaster.hpp @@ -56,35 +56,57 @@ public: void send_object(const GraphObjectImpl* p, bool recursive); +#define BROADCAST(msg, ...) \ + for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) \ + (*i).second->msg(__VA_ARGS__) + + // CommonInterface - void bundle_begin(); - void bundle_end(); + void bundle_begin() { BROADCAST(bundle_begin); } + void bundle_end() { BROADCAST(bundle_end); } void put(const Raul::URI& uri, - const Shared::Resource::Properties& properties); + const Shared::Resource::Properties& properties) { + BROADCAST(put, uri, properties); + } void move(const Raul::Path& old_path, - const Raul::Path& new_path); + const Raul::Path& new_path) { + BROADCAST(move, old_path, new_path); + } - void del(const Raul::Path& path); + void del(const Raul::Path& path) { + BROADCAST(del, path); + } void connect(const Raul::Path& src_port_path, - const Raul::Path& dst_port_path); + const Raul::Path& dst_port_path) { + BROADCAST(connect, src_port_path, dst_port_path); + } void disconnect(const Raul::Path& src_port_path, - const Raul::Path& dst_port_path); + const Raul::Path& dst_port_path) { + BROADCAST(disconnect, src_port_path, dst_port_path); + } void set_property(const Raul::URI& subject, const Raul::URI& predicate, - const Raul::Atom& value); + const Raul::Atom& value) { + BROADCAST(set_property, subject, predicate, value); + } void set_port_value(const Raul::Path& port_path, - const Raul::Atom& value); + const Raul::Atom& value) { + BROADCAST(set_port_value, port_path, value); + } void set_voice_value(const Raul::Path& port_path, uint32_t voice, - const Raul::Atom& value); + const Raul::Atom& value) { + BROADCAST(set_voice_value, port_path, voice, value); + } + // ClientInterface @@ -93,12 +115,10 @@ public: void response_ok(int32_t id) {} ///< N/A void response_error(int32_t id, const std::string& msg) {} ///< N/A - void transfer_begin(); - void transfer_end(); - - void error(const std::string& msg); - - void activity(const Raul::Path& path); + void transfer_begin() { BROADCAST(transfer_begin); } + void transfer_end() { BROADCAST(transfer_end); } + void error(const std::string& msg) { BROADCAST(error, msg); } + void activity(const Raul::Path& path) { BROADCAST(activity, path); } private: typedef std::map<Raul::URI, Shared::ClientInterface*> Clients; diff --git a/src/engine/HTTPEngineReceiver.cpp b/src/engine/HTTPEngineReceiver.cpp index d28e1a24..16369bde 100644 --- a/src/engine/HTTPEngineReceiver.cpp +++ b/src/engine/HTTPEngineReceiver.cpp @@ -34,6 +34,8 @@ #include "EventSource.hpp" #include "ThreadManager.hpp" +#define LOG(s) s << "[HTTPEngineReceiver] " + using namespace std; using namespace Raul; @@ -51,7 +53,7 @@ HTTPEngineReceiver::HTTPEngineReceiver(Engine& engine, uint16_t port) soup_server_add_handler(_server, NULL, message_callback, this, NULL); - info << "Started HTTP server on port " << soup_server_get_port(_server) << endl; + LOG(info) << "Started HTTP server on port " << soup_server_get_port(_server) << endl; Thread::set_name("HTTP Receiver"); if (!engine.world()->parser || !engine.world()->serialiser) @@ -157,7 +159,7 @@ HTTPEngineReceiver::message_callback(SoupServer* server, SoupMessage* msg, const } if (!Path::is_valid(path)) { - error << "Bad HTTP path: " << path << endl; + LOG(error) << "Bad HTTP path: " << path << endl; soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); const string& err = (boost::format("Bad path: %1%") % path).str(); soup_message_set_response(msg, "text/plain", SOUP_MEMORY_COPY, |