From acaab5ca7ce6869b8192de4f98c9f075fd17690e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 24 May 2011 23:29:42 +0000 Subject: Remove dependence on protocol-specific client headers in GUI code. In other words, remove need for protocol-specific (and library dependent) headers to be in public headers... git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3318 a436a847-0d15-0410-975c-d299462d15a1 --- src/client/HTTPEngineSender.cpp | 7 +++++-- src/client/HTTPEngineSender.hpp | 8 +++++++- src/client/OSCClientReceiver.cpp | 3 +++ src/client/OSCEngineSender.cpp | 6 ++++-- src/client/OSCEngineSender.hpp | 14 +++++++------- src/client/ingen_client.cpp | 21 +++++++++++++++----- src/gui/App.cpp | 5 +---- src/gui/App.hpp | 4 +--- src/gui/ConnectWindow.cpp | 41 ++++++++-------------------------------- src/ingen/main.cpp | 7 +++---- src/shared/World.cpp | 13 +++++++++---- src/shared/World.hpp | 11 ++++++++--- 12 files changed, 72 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/client/HTTPEngineSender.cpp b/src/client/HTTPEngineSender.cpp index ec5cc6a0..2c3dbe98 100644 --- a/src/client/HTTPEngineSender.cpp +++ b/src/client/HTTPEngineSender.cpp @@ -36,8 +36,11 @@ using namespace Shared; namespace Client { -HTTPEngineSender::HTTPEngineSender(World* world, const URI& engine_url) - : _world(*world->rdf_world()) +HTTPEngineSender::HTTPEngineSender(World* world, + const URI& engine_url, + SharedPtr receiver) + : _receiver(receiver) + , _world(*world->rdf_world()) , _engine_url(engine_url) , _id(0) , _enabled(true) diff --git a/src/client/HTTPEngineSender.hpp b/src/client/HTTPEngineSender.hpp index 27c34a51..3f932fb0 100644 --- a/src/client/HTTPEngineSender.hpp +++ b/src/client/HTTPEngineSender.hpp @@ -22,6 +22,7 @@ #include +#include "raul/Deletable.hpp" #include "raul/Path.hpp" #include "sord/sordmm.hpp" @@ -47,7 +48,10 @@ class HTTPClientReceiver; class HTTPEngineSender : public ServerInterface { public: - HTTPEngineSender(Shared::World* world, const Raul::URI& engine_url); + HTTPEngineSender(Shared::World* world, + const Raul::URI& engine_url, + SharedPtr receiver); + ~HTTPEngineSender(); Raul::URI uri() const { return _engine_url; } @@ -106,6 +110,8 @@ public: void request_property(const Raul::URI& path, const Raul::URI& key); protected: + SharedPtr _receiver; + SoupSession* _session; Sord::World& _world; const Raul::URI _engine_url; diff --git a/src/client/OSCClientReceiver.cpp b/src/client/OSCClientReceiver.cpp index 33e2d050..c163da60 100644 --- a/src/client/OSCClientReceiver.cpp +++ b/src/client/OSCClientReceiver.cpp @@ -137,6 +137,9 @@ OSCClientReceiver::unknown_cb(const char* path, const char* types, lo_arg** argv void OSCClientReceiver::setup_callbacks() { + if (!_target) + return; + lo_server_thread_add_method(_st, "/ok", "i", response_ok_cb, this); lo_server_thread_add_method(_st, "/error", "is", response_error_cb, this); lo_server_thread_add_method(_st, "/plugin", "sss", plugin_cb, this); diff --git a/src/client/OSCEngineSender.cpp b/src/client/OSCEngineSender.cpp index 4147c831..21c1ad6e 100644 --- a/src/client/OSCEngineSender.cpp +++ b/src/client/OSCEngineSender.cpp @@ -37,9 +37,11 @@ namespace Client { * from the most recently created server, so create the OSC listener before * this to have it all happen on the same port. Yeah, this is a big magic :/ */ -OSCEngineSender::OSCEngineSender(const URI& engine_url, - size_t max_packet_size) +OSCEngineSender::OSCEngineSender(const URI& engine_url, + size_t max_packet_size, + SharedPtr receiver) : Shared::OSCSender(max_packet_size) + , _receiver(receiver) , _engine_url(engine_url) , _id(0) { diff --git a/src/client/OSCEngineSender.hpp b/src/client/OSCEngineSender.hpp index a50de0f3..876d2ec2 100644 --- a/src/client/OSCEngineSender.hpp +++ b/src/client/OSCEngineSender.hpp @@ -24,6 +24,8 @@ #include +#include "raul/Deletable.hpp" + #include "ingen/ServerInterface.hpp" #include "shared/OSCSender.hpp" @@ -40,16 +42,12 @@ namespace Client { */ class OSCEngineSender : public ServerInterface, public Shared::OSCSender { public: - OSCEngineSender(const Raul::URI& engine_url, - size_t max_packet_size); + OSCEngineSender(const Raul::URI& engine_url, + size_t max_packet_size, + SharedPtr receiver); ~OSCEngineSender(); - static OSCEngineSender* create(const Raul::URI& engine_url, - size_t max_packet_size) { - return new OSCEngineSender(engine_url, max_packet_size); - } - Raul::URI uri() const { return _engine_url; } inline int32_t next_id() @@ -106,6 +104,8 @@ public: void request_property(const Raul::URI& path, const Raul::URI& key); protected: + SharedPtr _receiver; + const Raul::URI _engine_url; int _client_port; int32_t _id; diff --git a/src/client/ingen_client.cpp b/src/client/ingen_client.cpp index dc4d7f20..db32b117 100644 --- a/src/client/ingen_client.cpp +++ b/src/client/ingen_client.cpp @@ -20,9 +20,11 @@ #include "shared/Module.hpp" #include "shared/World.hpp" #ifdef HAVE_LIBLO +#include "OSCClientReceiver.hpp" #include "OSCEngineSender.hpp" #endif #ifdef HAVE_SOUP +#include "HTTPClientReceiver.hpp" #include "HTTPEngineSender.hpp" #endif @@ -30,10 +32,14 @@ using namespace Ingen; #ifdef HAVE_LIBLO SharedPtr -new_osc_interface(Ingen::Shared::World* world, const std::string& url) +new_osc_interface(Ingen::Shared::World* world, + const std::string& url, + SharedPtr respond_to) { - Client::OSCEngineSender* oes = Client::OSCEngineSender::create( - url, world->conf()->option("packet-size").get_int32()); + SharedPtr receiver( + new Client::OSCClientReceiver(16181, respond_to)); + Client::OSCEngineSender* oes = new Client::OSCEngineSender( + url, world->conf()->option("packet-size").get_int32(), receiver); oes->attach(rand(), true); return SharedPtr(oes); } @@ -41,9 +47,14 @@ new_osc_interface(Ingen::Shared::World* world, const std::string& url) #ifdef HAVE_SOUP SharedPtr -new_http_interface(Ingen::Shared::World* world, const std::string& url) +new_http_interface(Ingen::Shared::World* world, + const std::string& url, + SharedPtr respond_to) { - Client::HTTPEngineSender* hes = new Client::HTTPEngineSender(world, url); + SharedPtr receiver( + new Client::HTTPClientReceiver(world, url, respond_to)); + Client::HTTPEngineSender* hes = new Client::HTTPEngineSender( + world, url, receiver); hes->attach(rand(), true); return SharedPtr(hes); } diff --git a/src/gui/App.cpp b/src/gui/App.cpp index 9d7fffc1..f1e590cb 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -150,8 +150,7 @@ App::run() } void -App::attach(SharedPtr client, - SharedPtr handle) +App::attach(SharedPtr client) { assert(!_client); assert(!_store); @@ -160,7 +159,6 @@ App::attach(SharedPtr client, _world->engine()->register_client(client.get()); _client = client; - _handle = handle; _store = SharedPtr(new ClientStore(_world->uris(), _world->engine(), client)); _loader = SharedPtr(new ThreadedLoader(_world->uris(), _world->engine())); @@ -182,7 +180,6 @@ App::detach() _loader.reset(); _store.reset(); _client.reset(); - _handle.reset(); _world->set_engine(SharedPtr()); } } diff --git a/src/gui/App.hpp b/src/gui/App.hpp index ca5c590f..96cd0152 100644 --- a/src/gui/App.hpp +++ b/src/gui/App.hpp @@ -74,8 +74,7 @@ public: void error_message(const std::string& msg); - void attach(SharedPtr client, - SharedPtr handle=SharedPtr()); + void attach(SharedPtr client); void detach(); @@ -143,7 +142,6 @@ protected: static App* _instance; SharedPtr _client; - SharedPtr _handle; SharedPtr _store; SharedPtr _loader; diff --git a/src/gui/ConnectWindow.cpp b/src/gui/ConnectWindow.cpp index b266307a..56acc52b 100644 --- a/src/gui/ConnectWindow.cpp +++ b/src/gui/ConnectWindow.cpp @@ -29,12 +29,6 @@ #include "shared/Module.hpp" #include "shared/World.hpp" #include "server/Engine.hpp" -#ifdef HAVE_SOUP -#include "client/HTTPClientReceiver.hpp" -#endif -#ifdef HAVE_LIBLO -#include "client/OSCClientReceiver.hpp" -#endif #include "client/ClientStore.hpp" #include "client/PatchModel.hpp" #include "client/ThreadedSigClientInterface.hpp" @@ -78,7 +72,7 @@ ConnectWindow::start(Ingen::Shared::World* world) set_connected_to(world->engine()); - connect(true); + connect(world->engine()); } void @@ -175,27 +169,10 @@ ConnectWindow::connect(bool existing) // Create client-side listener SharedPtr tsci(new ThreadedSigClientInterface(1024)); - SharedPtr client; - string scheme = uri.substr(0, uri.find(":")); - -#ifdef HAVE_LIBLO - if (scheme == "osc.udp" || scheme == "osc.tcp") - client = SharedPtr(new OSCClientReceiver(16181, tsci)); -#endif -#ifdef HAVE_SOUP - if (scheme == "http") - client = SharedPtr(new HTTPClientReceiver(world, uri, tsci)); -#endif - - if (!existing) { - world->set_engine(world->interface(uri)); - } else { - uri = world->engine()->uri().str(); - scheme = uri.substr(0, uri.find(":")); - } + world->set_engine(world->interface(uri, tsci)); - App::instance().attach(tsci, client); + App::instance().attach(tsci); App::instance().register_callbacks(); Glib::signal_timeout().connect( @@ -204,19 +181,17 @@ ConnectWindow::connect(bool existing) } else if (_mode == LAUNCH_REMOTE) { #ifdef HAVE_LIBLO int port = _port_spinbutton->get_value_as_int(); - char port_str[6]; - snprintf(port_str, 6, "%u", port); - const string cmd = string("ingen -e --engine-port=").append(port_str); + char port_str[8]; + snprintf(port_str, sizeof(port_str), "%u", port); + const string cmd = string("ingen -e -E ").append(port_str); if (Raul::Process::launch(cmd)) { const std::string engine_uri = string("osc.udp://localhost:").append(port_str); - world->set_engine(world->interface(engine_uri)); - // FIXME: static args SharedPtr tsci(new ThreadedSigClientInterface(1024)); - SharedPtr client(new OSCClientReceiver(16181, tsci)); + world->set_engine(world->interface(engine_uri, tsci)); - App::instance().attach(tsci, client); + App::instance().attach(tsci); App::instance().register_callbacks(); Glib::signal_timeout().connect( diff --git a/src/ingen/main.cpp b/src/ingen/main.cpp index 997fb66e..8df67e92 100644 --- a/src/ingen/main.cpp +++ b/src/ingen/main.cpp @@ -45,6 +45,7 @@ #include "shared/Configuration.hpp" #include "shared/World.hpp" #include "shared/runtime_paths.hpp" +#include "client/ThreadedSigClientInterface.hpp" #ifdef WITH_BINDINGS #include "bindings/ingen_bindings.hpp" #endif @@ -105,17 +106,15 @@ main(int argc, char** argv) SharedPtr engine_interface; Glib::thread_init(); -#if HAVE_SOUP +#ifdef HAVE_SOUP g_type_init(); #endif Ingen::Shared::World* world = new Ingen::Shared::World(&conf, argc, argv); -#if INGEN_JACK_SESSION if (conf.option("uuid").get_string()) { world->set_jack_uuid(conf.option("uuid").get_string()); } -#endif // Run engine if (conf.option("engine").get_bool()) { @@ -145,7 +144,7 @@ main(int argc, char** argv) ingen_try(world->load_module("client"), "Unable to load client module"); const char* const uri = conf.option("connect").get_string(); - ingen_try((engine_interface = world->interface(uri)), + ingen_try((engine_interface = world->interface(uri, SharedPtr())), (string("Unable to create interface to `") + uri + "'").c_str()); } diff --git a/src/shared/World.cpp b/src/shared/World.cpp index f2af34a7..c583f2fa 100644 --- a/src/shared/World.cpp +++ b/src/shared/World.cpp @@ -169,6 +169,7 @@ public: SharedPtr serialiser; SharedPtr parser; SharedPtr store; + SharedPtr client; LilvWorld* lilv_world; std::string jack_uuid; }; @@ -189,6 +190,7 @@ void World::set_engine(SharedPtr e) { _impl->engi void World::set_serialiser(SharedPtr s) { _impl->serialiser = s; } void World::set_parser(SharedPtr p) { _impl->parser = p; } void World::set_store(SharedPtr s) { _impl->store = s; } +void World::set_client(SharedPtr c) { _impl->client = c; } void World::set_conf(Raul::Configuration* c) { _impl->conf = c; } int& World::argc() { return _impl->argc; } @@ -198,6 +200,7 @@ SharedPtr World::engine() { return _impl->engin SharedPtr World::serialiser() { return _impl->serialiser; } SharedPtr World::parser() { return _impl->parser; } SharedPtr World::store() { return _impl->store; } +SharedPtr World::client() { return _impl->client; } Raul::Configuration* World::conf() { return _impl->conf; } LV2Features* World::lv2_features() { return _impl->lv2_features; } @@ -207,7 +210,7 @@ SharedPtr World::uris() { return _impl->uris; } /** Load an Ingen module. * @return true on success, false on failure - */ +m */ bool World::load_module(const char* name) { @@ -236,16 +239,18 @@ World::unload_modules() /** Get an interface for a remote engine at @a url */ SharedPtr -World::interface(const std::string& url) +World::interface( + const std::string& engine_url, + SharedPtr respond_to) { - const string scheme = url.substr(0, url.find(":")); + const string scheme = engine_url.substr(0, engine_url.find(":")); const Pimpl::InterfaceFactories::const_iterator i = _impl->interface_factories.find(scheme); if (i == _impl->interface_factories.end()) { warn << "Unknown URI scheme `" << scheme << "'" << endl; return SharedPtr(); } - return i->second(this, url); + return i->second(this, engine_url, respond_to); } /** Run a script of type @a mime_type at filename @a filename */ diff --git a/src/shared/World.hpp b/src/shared/World.hpp index 3ce4d03e..6aacea36 100644 --- a/src/shared/World.hpp +++ b/src/shared/World.hpp @@ -34,6 +34,7 @@ namespace Sord { class World; } namespace Ingen { class EngineBase; +class ClientInterface; class ServerInterface; namespace Serialisation { class Serialiser; class Parser; } @@ -62,14 +63,16 @@ public: virtual void unload_modules(); typedef SharedPtr (*InterfaceFactory)( - World* world, - const std::string& engine_url); + World* world, + const std::string& engine_url, + SharedPtr respond_to); virtual void add_interface_factory(const std::string& scheme, InterfaceFactory factory); virtual SharedPtr interface( - const std::string& engine_url); + const std::string& engine_url, + SharedPtr respond_to); virtual bool run(const std::string& mime_type, const std::string& filename); @@ -79,12 +82,14 @@ public: virtual void set_serialiser(SharedPtr s); virtual void set_parser(SharedPtr p); virtual void set_store(SharedPtr s); + virtual void set_client(SharedPtr c); virtual SharedPtr local_engine(); virtual SharedPtr engine(); virtual SharedPtr serialiser(); virtual SharedPtr parser(); virtual SharedPtr store(); + virtual SharedPtr client(); virtual Sord::World* rdf_world(); virtual SharedPtr uris(); -- cgit v1.2.1