From 119468f621a59d86da10bedf75c4427b70f9d370 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 16 Mar 2012 03:15:41 +0000 Subject: Remove activity from interface and use set_property() instead. Move client registration stuff to Engine and remove corresponding events. Simply response ID interface. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4066 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/ClientBroadcaster.cpp | 18 ++++++--- src/server/ClientBroadcaster.hpp | 7 +++- src/server/Engine.cpp | 12 ++++++ src/server/Engine.hpp | 4 ++ src/server/ServerInterfaceImpl.cpp | 34 ++++------------- src/server/ServerInterfaceImpl.hpp | 7 +--- src/server/events.hpp | 2 - src/server/events/Get.cpp | 10 +++++ src/server/events/RegisterClient.cpp | 70 ---------------------------------- src/server/events/RegisterClient.hpp | 53 ------------------------- src/server/events/UnregisterClient.cpp | 52 ------------------------- src/server/events/UnregisterClient.hpp | 51 ------------------------- src/server/wscript | 2 - 13 files changed, 54 insertions(+), 268 deletions(-) delete mode 100644 src/server/events/RegisterClient.cpp delete mode 100644 src/server/events/RegisterClient.hpp delete mode 100644 src/server/events/UnregisterClient.cpp delete mode 100644 src/server/events/UnregisterClient.hpp (limited to 'src/server') diff --git a/src/server/ClientBroadcaster.cpp b/src/server/ClientBroadcaster.cpp index 2931497a..1a55d355 100644 --- a/src/server/ClientBroadcaster.cpp +++ b/src/server/ClientBroadcaster.cpp @@ -39,6 +39,7 @@ namespace Server { void ClientBroadcaster::register_client(const URI& uri, ClientInterface* client) { + Glib::Mutex::Lock lock(_clients_mutex); Clients::iterator i = _clients.find(uri); if (i == _clients.end()) { @@ -56,12 +57,14 @@ ClientBroadcaster::register_client(const URI& uri, ClientInterface* client) bool ClientBroadcaster::unregister_client(const URI& uri) { - size_t erased = _clients.erase(uri); + Glib::Mutex::Lock lock(_clients_mutex); + const size_t erased = _clients.erase(uri); - if (erased > 0) + if (erased > 0) { LOG(info) << "Unregistered client: " << uri << endl; - else + } else { LOG(warn) << "Failed to find client to unregister: " << uri << endl; + } return (erased > 0); } @@ -72,6 +75,7 @@ ClientBroadcaster::unregister_client(const URI& uri) ClientInterface* ClientBroadcaster::client(const URI& uri) { + Glib::Mutex::Lock lock(_clients_mutex); Clients::iterator i = _clients.find(uri); if (i != _clients.end()) { return (*i).second; @@ -83,8 +87,10 @@ ClientBroadcaster::client(const URI& uri) void ClientBroadcaster::send_plugins(const NodeFactory::Plugins& plugins) { - for (Clients::const_iterator c = _clients.begin(); c != _clients.end(); ++c) + Glib::Mutex::Lock lock(_clients_mutex); + for (Clients::const_iterator c = _clients.begin(); c != _clients.end(); ++c) { send_plugins_to((*c).second, plugins); + } } void @@ -108,8 +114,10 @@ ClientBroadcaster::send_plugins_to(ClientInterface* client, const NodeFactory::P void ClientBroadcaster::send_object(const GraphObjectImpl* o, bool recursive) { - for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) + Glib::Mutex::Lock lock(_clients_mutex); + for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) { ObjectSender::send_object((*i).second, o, recursive); + } } } // namespace Server diff --git a/src/server/ClientBroadcaster.hpp b/src/server/ClientBroadcaster.hpp index c9c56d56..b004433b 100644 --- a/src/server/ClientBroadcaster.hpp +++ b/src/server/ClientBroadcaster.hpp @@ -22,6 +22,8 @@ #include #include +#include + #include "raul/SharedPtr.hpp" #include "ingen/ClientInterface.hpp" @@ -61,6 +63,7 @@ public: void send_object(const GraphObjectImpl* p, bool recursive); #define BROADCAST(msg, ...) \ + Glib::Mutex::Lock lock(_clients_mutex); \ for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) \ (*i).second->msg(__VA_ARGS__) @@ -121,7 +124,9 @@ public: private: typedef std::map Clients; - Clients _clients; + + Glib::Mutex _clients_mutex; + Clients _clients; }; } // namespace Server diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index d9878bee..89062d4a 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -240,5 +240,17 @@ Engine::process_events(ProcessContext& context) (*i)->process(*_post_processor, context); } +void +Engine::register_client(const Raul::URI& uri, ClientInterface* client) +{ + _broadcaster->register_client(uri, client); +} + +bool +Engine::unregister_client(const Raul::URI& uri) +{ + return _broadcaster->unregister_client(uri); +} + } // namespace Server } // namespace Ingen diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index d4f39bd8..64f874c2 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -76,6 +76,10 @@ public: virtual void process_events(ProcessContext& context); + virtual void register_client(const Raul::URI& uri, ClientInterface* client); + + virtual bool unregister_client(const Raul::URI& uri); + Ingen::Shared::World* world() const { return _world; } ClientBroadcaster* broadcaster() const { return _broadcaster; } diff --git a/src/server/ServerInterfaceImpl.cpp b/src/server/ServerInterfaceImpl.cpp index eb615e9a..1bd388ec 100644 --- a/src/server/ServerInterfaceImpl.cpp +++ b/src/server/ServerInterfaceImpl.cpp @@ -21,6 +21,7 @@ #include "ingen/shared/URIs.hpp" +#include "ClientBroadcaster.hpp" #include "Driver.hpp" #include "Engine.hpp" #include "EventSource.hpp" @@ -63,37 +64,18 @@ ServerInterfaceImpl::now() const } void -ServerInterfaceImpl::respond_to(ClientInterface* client, int32_t id) +ServerInterfaceImpl::set_response_id(int32_t id) { - _request_client = client; - _request_id = id; -} - -void -ServerInterfaceImpl::disable_responses() -{ - _request_client = NULL; - _request_id = -1; + if (!_request_client) { // Kludge + _request_client = _engine.broadcaster()->client( + "http://drobilla.net/ns/ingen#internal"); + std::cerr << "SET REQUEST CLIENT " << (void*)_request_client << std::endl; + } + _request_id = id; } /* *** ServerInterface implementation below here *** */ -void -ServerInterfaceImpl::register_client(ClientInterface* client) -{ - push_queued(new Events::RegisterClient(_engine, client, _request_id, now(), client->uri())); - _request_client = client; - _request_id = 1; -} - -void -ServerInterfaceImpl::unregister_client(const URI& uri) -{ - push_queued(new Events::UnregisterClient(_engine, _request_client, _request_id, now(), uri)); - _request_client = NULL; - _request_id = -1; -} - // Bundle commands void diff --git a/src/server/ServerInterfaceImpl.hpp b/src/server/ServerInterfaceImpl.hpp index b43549ef..e3dcabad 100644 --- a/src/server/ServerInterfaceImpl.hpp +++ b/src/server/ServerInterfaceImpl.hpp @@ -52,12 +52,7 @@ public: Raul::URI uri() const { return "http://drobilla.net/ns/ingen#internal"; } - virtual void respond_to(ClientInterface* client, int32_t id); - virtual void disable_responses(); - - // Client registration - virtual void register_client(ClientInterface* client); - virtual void unregister_client(const Raul::URI& uri); + virtual void set_response_id(int32_t id); // Bundles virtual void bundle_begin(); diff --git a/src/server/events.hpp b/src/server/events.hpp index 776b6c52..40e4f3d2 100644 --- a/src/server/events.hpp +++ b/src/server/events.hpp @@ -29,10 +29,8 @@ #include "events/Get.hpp" #include "events/Move.hpp" #include "events/Ping.hpp" -#include "events/RegisterClient.hpp" #include "events/SetMetadata.hpp" #include "events/SetPortValue.hpp" -#include "events/UnregisterClient.hpp" #endif // INGEN_ENGINE_EVENTS_HPP diff --git a/src/server/events/Get.cpp b/src/server/events/Get.cpp index 08ac3e10..605e392a 100644 --- a/src/server/events/Get.cpp +++ b/src/server/events/Get.cpp @@ -18,6 +18,7 @@ #include "ingen/ClientInterface.hpp" #include "ClientBroadcaster.hpp" +#include "Driver.hpp" #include "Engine.hpp" #include "EngineStore.hpp" #include "Get.hpp" @@ -67,6 +68,15 @@ Get::post_process() if (_request_client) { _engine.broadcaster()->send_plugins_to(_request_client, _plugins); } + } else if (_uri == "ingen:engine") { + // TODO: Keep a proper RDF model of the engine + if (_request_client) { + Shared::URIs& uris = *_engine.world()->uris().get(); + _request_client->set_property( + uris.ingen_engine, + uris.ingen_sampleRate, + uris.forge.make(int32_t(_engine.driver()->sample_rate()))); + } } else if (!_object && !_plugin) { respond(NOT_FOUND); } else if (_request_client) { diff --git a/src/server/events/RegisterClient.cpp b/src/server/events/RegisterClient.cpp deleted file mode 100644 index 088cf296..00000000 --- a/src/server/events/RegisterClient.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2007-2011 David Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "ingen/shared/LV2URIMap.hpp" -#include "ingen/shared/URIs.hpp" - -#include "ClientBroadcaster.hpp" -#include "Driver.hpp" -#include "Engine.hpp" -#include "events/RegisterClient.hpp" - -using namespace Raul; - -namespace Ingen { -namespace Server { -namespace Events { - -RegisterClient::RegisterClient(Engine& engine, - ClientInterface* client, - int32_t id, - SampleCount timestamp, - const URI& uri) - : Event(engine, client, id, timestamp) - , _uri(uri) -{ -} - -void -RegisterClient::pre_process() -{ - _engine.broadcaster()->register_client(_uri, _request_client); - - Event::pre_process(); -} - -void -RegisterClient::post_process() -{ - respond(SUCCESS); - - /* Tell the client the engine's sample rate (which it needs to know to - interpret control bounds for lv2:sampleRate ports). This is a bit of a - kludge. TODO: keep a proper RDF model to describe the engine and send - that to clients. - */ - const Ingen::Shared::URIs& uris = *_engine.world()->uris().get(); - _request_client->set_property( - uris.ingen_engine, - uris.ingen_sampleRate, - _engine.world()->forge().make(int32_t(_engine.driver()->sample_rate()))); -} - -} // namespace Server -} // namespace Ingen -} // namespace Events - diff --git a/src/server/events/RegisterClient.hpp b/src/server/events/RegisterClient.hpp deleted file mode 100644 index 0f82a33d..00000000 --- a/src/server/events/RegisterClient.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2007-2011 David Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef INGEN_EVENTS_REGISTERCLIENT_HPP -#define INGEN_EVENTS_REGISTERCLIENT_HPP - -#include "raul/URI.hpp" -#include "ingen/ClientInterface.hpp" -#include "Event.hpp" - -namespace Ingen { -namespace Server { -namespace Events { - -/** Registers a new client with the OSC system, so it can receive updates. - * - * \ingroup engine - */ -class RegisterClient : public Event -{ -public: - RegisterClient(Engine& engine, - ClientInterface* client, - int32_t id, - SampleCount timestamp, - const Raul::URI& uri); - - void pre_process(); - void post_process(); - -private: - Raul::URI _uri; -}; - -} // namespace Server -} // namespace Ingen -} // namespace Events - -#endif // INGEN_EVENTS_REGISTERCLIENT_HPP diff --git a/src/server/events/UnregisterClient.cpp b/src/server/events/UnregisterClient.cpp deleted file mode 100644 index a673c25a..00000000 --- a/src/server/events/UnregisterClient.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2007-2011 David Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "ingen/ClientInterface.hpp" -#include "UnregisterClient.hpp" -#include "Engine.hpp" -#include "ClientBroadcaster.hpp" - -using namespace Raul; - -namespace Ingen { -namespace Server { -namespace Events { - -UnregisterClient::UnregisterClient(Engine& engine, - ClientInterface* client, - int32_t id, - SampleCount timestamp, - const URI& uri) - : Event(engine, client, id, timestamp) - , _uri(uri) -{ -} - -void -UnregisterClient::post_process() -{ - if (_engine.broadcaster()->unregister_client(_uri)) { - respond(SUCCESS); - } else { - respond(FAILURE); - } -} - -} // namespace Server -} // namespace Ingen -} // namespace Events - diff --git a/src/server/events/UnregisterClient.hpp b/src/server/events/UnregisterClient.hpp deleted file mode 100644 index 089b8d8e..00000000 --- a/src/server/events/UnregisterClient.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* This file is part of Ingen. - * Copyright 2007-2011 David Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef INGEN_EVENTS_UNREGISTERCLIENT_HPP -#define INGEN_EVENTS_UNREGISTERCLIENT_HPP - -#include "Event.hpp" -#include "raul/URI.hpp" - -namespace Ingen { -namespace Server { -namespace Events { - -/** Unregisters an OSC client so it no longer receives notifications. - * - * \ingroup engine - */ -class UnregisterClient : public Event -{ -public: - UnregisterClient(Engine& engine, - ClientInterface* client, - int32_t id, - SampleCount timestamp, - const Raul::URI& uri); - - void post_process(); - -private: - Raul::URI _uri; -}; - -} // namespace Server -} // namespace Ingen -} // namespace Events - -#endif // INGEN_EVENTS_UNREGISTERCLIENT_HPP diff --git a/src/server/wscript b/src/server/wscript index 593664be..33ffc58a 100644 --- a/src/server/wscript +++ b/src/server/wscript @@ -43,10 +43,8 @@ def build(bld): events/DisconnectAll.cpp events/Get.cpp events/Move.cpp - events/RegisterClient.cpp events/SetMetadata.cpp events/SetPortValue.cpp - events/UnregisterClient.cpp ingen_engine.cpp internals/Controller.cpp internals/Delay.cpp -- cgit v1.2.1