diff options
author | David Robillard <d@drobilla.net> | 2012-05-02 06:24:22 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-05-02 06:24:22 +0000 |
commit | fe353cce9665b33a7372ed2d1683b3c2748625f7 (patch) | |
tree | 81287558b014309820e9df64033edc0b29d23b4f /src | |
parent | 1c736a348c59d98e4022fb02b49a8b4c93baa3d2 (diff) | |
download | ingen-fe353cce9665b33a7372ed2d1683b3c2748625f7.tar.gz ingen-fe353cce9665b33a7372ed2d1683b3c2748625f7.tar.bz2 ingen-fe353cce9665b33a7372ed2d1683b3c2748625f7.zip |
Preliminary socket control interface, and ingen_cmd command line interface which uses it.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4311 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/client/ClientStore.cpp | 2 | ||||
-rw-r--r-- | src/gui/LoadPluginWindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/PatchCanvas.cpp | 2 | ||||
-rw-r--r-- | src/ingen/main.cpp | 4 | ||||
-rw-r--r-- | src/serialisation/Parser.cpp | 6 | ||||
-rw-r--r-- | src/serialisation/Serialiser.cpp | 2 | ||||
-rw-r--r-- | src/server/events/SetMetadata.cpp | 21 | ||||
-rw-r--r-- | src/shared/AtomReader.cpp | 19 | ||||
-rw-r--r-- | src/shared/Builder.cpp | 2 | ||||
-rw-r--r-- | src/shared/Configuration.cpp | 1 | ||||
-rw-r--r-- | src/shared/Forge.cpp | 1 | ||||
-rw-r--r-- | src/shared/URIs.cpp | 2 | ||||
-rw-r--r-- | src/shared/World.cpp | 1 | ||||
-rw-r--r-- | src/socket/SocketReceiver.cpp | 149 | ||||
-rw-r--r-- | src/socket/SocketReceiver.hpp | 48 | ||||
-rw-r--r-- | src/socket/ingen_socket_server.cpp | 51 | ||||
-rw-r--r-- | src/socket/wscript | 14 |
17 files changed, 302 insertions, 25 deletions
diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index ab3847ee..445dc182 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -327,7 +327,7 @@ ClientStore::put(const URI& uri, model->set_properties(properties); add_object(model); } else if (is_node) { - const Iterator p = properties.find(_uris->rdf_instanceOf); + const Iterator p = properties.find(_uris->ingen_prototype); SharedPtr<PluginModel> plug; if (p->second.is_valid() && p->second.type() == _uris->forge.URI) { if (!(plug = _plugin(p->second.get_uri()))) { diff --git a/src/gui/LoadPluginWindow.cpp b/src/gui/LoadPluginWindow.cpp index ccad9a2c..2977ceca 100644 --- a/src/gui/LoadPluginWindow.cpp +++ b/src/gui/LoadPluginWindow.cpp @@ -348,7 +348,7 @@ LoadPluginWindow::load_plugin(const Gtk::TreeModel::iterator& iter) Resource::Properties props = _initial_data; props.insert(make_pair(uris.rdf_type, uris.ingen_Node)); - props.insert(make_pair(uris.rdf_instanceOf, + props.insert(make_pair(uris.ingen_prototype, _app->forge().alloc_uri(plugin->uri().str()))); Raul::warn << "FIXME: polyphonic" << std::endl; //props.insert(make_pair(uris.ingen_polyphonic, diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp index 783896fd..8cb9d384 100644 --- a/src/gui/PatchCanvas.cpp +++ b/src/gui/PatchCanvas.cpp @@ -817,7 +817,7 @@ PatchCanvas::load_plugin(WeakPtr<PluginModel> weak_plugin) // FIXME: polyphony? GraphObject::Properties props = get_initial_data(); props.insert(make_pair(uris.rdf_type, uris.ingen_Node)); - props.insert(make_pair(uris.rdf_instanceOf, + props.insert(make_pair(uris.ingen_prototype, uris.forge.alloc_uri(plugin->uri().str()))); _app.engine()->put(path, props); } diff --git a/src/ingen/main.cpp b/src/ingen/main.cpp index f0a43b12..c0ff6181 100644 --- a/src/ingen/main.cpp +++ b/src/ingen/main.cpp @@ -139,6 +139,10 @@ main(int argc, char** argv) "Unable to load HTTP server module"); #endif } + #ifdef HAVE_SOCKET + ingen_try(world->load_module("socket_server"), + "Unable to load socket server module"); + #endif } // If we don't have a local engine interface (for GUI), use network diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index 838a0200..24b96b8d 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -224,11 +224,11 @@ parse_node(Ingen::Shared::World* world, { const URIs& uris = *world->uris().get(); - Sord::URI rdf_instanceOf(*world->rdf_world(), NS_RDF "instanceOf"); + Sord::URI ingen_prototype(*world->rdf_world(), NS_INGEN "prototype"); - Sord::Iter i = model.find(subject, rdf_instanceOf, nil); + Sord::Iter i = model.find(subject, ingen_prototype, nil); if (i.end() || i.get_object().type() != Sord::Node::URI) { - LOG(error) << "Node missing mandatory rdf:instanceOf" << endl; + LOG(error) << "Node missing mandatory ingen:prototype" << endl; return boost::optional<Path>(); } diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index e6379e22..f16ed1d7 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -455,7 +455,7 @@ Serialiser::Impl::serialise_node(SharedPtr<const Node> node, Sord::Curie(_model->world(), "rdf:type"), Sord::Curie(_model->world(), "ingen:Node")); _model->add_statement(node_id, - Sord::Curie(_model->world(), "rdf:instanceOf"), + Sord::Curie(_model->world(), "ingen:prototype"), class_id); _model->add_statement(node_id, Sord::Curie(_model->world(), "lv2:symbol"), diff --git a/src/server/events/SetMetadata.cpp b/src/server/events/SetMetadata.cpp index ee741b9e..7d88c83c 100644 --- a/src/server/events/SetMetadata.cpp +++ b/src/server/events/SetMetadata.cpp @@ -77,16 +77,19 @@ SetMetadata::SetMetadata(Engine& engine, } /* - LOG(info) << "Set " << subject << " : " << context << " {" << endl; + LOG(info) << "Patch " << subject << " : " << context << " {" << endl; typedef Resource::Properties::const_iterator iterator; - for (iterator i = properties.begin(); i != properties.end(); ++i) - LOG(info) << " " << i->first << " = " << i->second << " :: " << i->second.type() << endl; - LOG(info) << "}" << endl; - - LOG(info) << "Unset " << subject << " {" << endl; + for (iterator i = properties.begin(); i != properties.end(); ++i) { + LOG(info) << " + " << i->first + << " = " << engine.world()->forge().str(i->second) + << " :: " << engine.world()->lv2_uri_map()->unmap_uri(i->second.type()) << endl; + } typedef Resource::Properties::const_iterator iterator; - for (iterator i = remove.begin(); i != remove.end(); ++i) - LOG(info) << " " << i->first << " = " << i->second << " :: " << i->second.type() << endl; + for (iterator i = remove.begin(); i != remove.end(); ++i) { + LOG(info) << " - " << i->first + << " = " << engine.world()->forge().str(i->second) + << " :: " << engine.world()->lv2_uri_map()->unmap_uri(i->second.type()) << endl; + } LOG(info) << "}" << endl; */ } @@ -133,7 +136,7 @@ SetMetadata::pre_process() _create_event = new CreatePatch(_engine, _request_client, _request_id, _time, path, poly, _properties); } else if (is_node) { - const iterator p = _properties.find(uris.rdf_instanceOf); + const iterator p = _properties.find(uris.ingen_prototype); _create_event = new CreateNode(_engine, _request_client, _request_id, _time, path, p->second.get_uri(), _properties); } else if (is_port) { diff --git a/src/shared/AtomReader.cpp b/src/shared/AtomReader.cpp index 6925d478..7cafd919 100644 --- a/src/shared/AtomReader.cpp +++ b/src/shared/AtomReader.cpp @@ -33,7 +33,7 @@ AtomReader::AtomReader(LV2URIMap& map, URIs& uris, Forge& forge, Interface& ifac } void -AtomReader::get_uri(const LV2_Atom* in, Raul::Atom& out) +AtomReader::get_atom(const LV2_Atom* in, Raul::Atom& out) { if (in) { if (in->type == _uris.atom_URID) { @@ -49,9 +49,14 @@ void AtomReader::get_props(const LV2_Atom_Object* obj, Ingen::Resource::Properties& props) { + if (obj->body.otype) { + props.insert( + std::make_pair(_uris.rdf_type, + _forge.alloc_uri(_map.unmap_uri(obj->body.otype)))); + } LV2_ATOM_OBJECT_FOREACH(obj, p) { Raul::Atom val; - get_uri(&p->value, val); + get_atom(&p->value, val); props.insert(std::make_pair(_map.unmap_uri(p->key), val)); } } @@ -96,8 +101,8 @@ AtomReader::write(const LV2_Atom* msg) Raul::Atom tail_atom; Raul::Atom head_atom; - get_uri(tail, tail_atom); - get_uri(head, head_atom); + get_atom(tail, tail_atom); + get_atom(head, head_atom); if (tail_atom.is_valid() && head_atom.is_valid()) { _iface.disconnect(Raul::Path(tail_atom.get_uri()), Raul::Path(head_atom.get_uri())); @@ -130,8 +135,8 @@ AtomReader::write(const LV2_Atom* msg) Raul::Atom tail_atom; Raul::Atom head_atom; - get_uri(tail, tail_atom); - get_uri(head, head_atom); + get_atom(tail, tail_atom); + get_atom(head, head_atom); _iface.connect(Raul::Path(tail_atom.get_uri()), Raul::Path(head_atom.get_uri())); } else { @@ -153,7 +158,7 @@ AtomReader::write(const LV2_Atom* msg) LV2_ATOM_OBJECT_FOREACH(body, p) { Raul::Atom val; - get_uri(&p->value, val); + get_atom(&p->value, val); _iface.set_property(subject_uri, _map.unmap_uri(p->key), val); } } else if (obj->body.otype == _uris.patch_Patch) { diff --git a/src/shared/Builder.cpp b/src/shared/Builder.cpp index e726d647..272a3394 100644 --- a/src/shared/Builder.cpp +++ b/src/shared/Builder.cpp @@ -66,7 +66,7 @@ Builder::build(SharedPtr<const GraphObject> object) if (node) { Resource::Properties props; props.insert(make_pair(uris.rdf_type, uris.ingen_Node)); - props.insert(make_pair(uris.rdf_instanceOf, + props.insert(make_pair(uris.ingen_prototype, _uris->forge.alloc_uri(node->plugin()->uri().str()))); _interface.put(node->path(), props); build_object(object); diff --git a/src/shared/Configuration.cpp b/src/shared/Configuration.cpp index d5aa6f9b..fafe7a49 100644 --- a/src/shared/Configuration.cpp +++ b/src/shared/Configuration.cpp @@ -40,6 +40,7 @@ Configuration::Configuration() add("connect", 'c', "Connect to engine URI", STRING, Value("osc.udp://localhost:16180")); add("engine", 'e', "Run (JACK) engine", BOOL, Value(false)); add("engine-port", 'E', "Engine listen port", INT, Value(16180)); + add("socket", 'S', "Engine socket path", STRING, Value("/tmp/ingen.sock")); add("gui", 'g', "Launch the GTK graphical interface", BOOL, Value(false)); add("help", 'h', "Print this help message", BOOL, Value(false)); add("jack-client", 'n', "JACK client name", STRING, Value("ingen")); diff --git a/src/shared/Forge.cpp b/src/shared/Forge.cpp index 9d33ada9..fc8116c6 100644 --- a/src/shared/Forge.cpp +++ b/src/shared/Forge.cpp @@ -27,6 +27,7 @@ Forge::Forge(Shared::LV2URIMap& map) Float = map.map_uri(LV2_ATOM__Float); Bool = map.map_uri(LV2_ATOM__Bool); URI = map.map_uri(LV2_ATOM__URI); + URID = map.map_uri(LV2_ATOM__URID); String = map.map_uri(LV2_ATOM__String); Dict = map.map_uri(LV2_ATOM__Object); } diff --git a/src/shared/URIs.cpp b/src/shared/URIs.cpp index db5c5bfd..058e4216 100644 --- a/src/shared/URIs.cpp +++ b/src/shared/URIs.cpp @@ -82,6 +82,7 @@ URIs::URIs(Ingen::Forge& f, LV2URIMap* map) , ingen_node (forge, map, NS_INGEN "node") , ingen_polyphonic (forge, map, NS_INGEN "polyphonic") , ingen_polyphony (forge, map, NS_INGEN "polyphony") + , ingen_prototype (forge, map, NS_INGEN "prototype") , ingen_sampleRate (forge, map, NS_INGEN "sampleRate") , ingen_selected (forge, map, NS_INGEN "selected") , ingen_tail (forge, map, NS_INGEN "tail") @@ -125,7 +126,6 @@ URIs::URIs(Ingen::Forge& f, LV2URIMap* map) , patch_remove (forge, map, LV2_PATCH__remove) , patch_request (forge, map, LV2_PATCH__request) , patch_subject (forge, map, LV2_PATCH__subject) - , rdf_instanceOf (forge, map, NS_RDF "instanceOf") , rdf_type (forge, map, NS_RDF "type") , rdfs_seeAlso (forge, map, NS_RDFS "seeAlso") , wildcard (forge, map, NS_INGEN "wildcard") diff --git a/src/shared/World.cpp b/src/shared/World.cpp index a5f86319..b99dfd1a 100644 --- a/src/shared/World.cpp +++ b/src/shared/World.cpp @@ -121,6 +121,7 @@ public: // Set up RDF namespaces rdf_world->add_prefix("atom", "http://lv2plug.in/ns/ext/atom#"); + rdf_world->add_prefix("patch", "http://lv2plug.in/ns/ext/patch#"); rdf_world->add_prefix("doap", "http://usefulinc.com/ns/doap#"); rdf_world->add_prefix("ingen", "http://drobilla.net/ns/ingen#"); rdf_world->add_prefix("lv2", "http://lv2plug.in/ns/lv2core#"); diff --git a/src/socket/SocketReceiver.cpp b/src/socket/SocketReceiver.cpp new file mode 100644 index 00000000..833c90ac --- /dev/null +++ b/src/socket/SocketReceiver.cpp @@ -0,0 +1,149 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard <http://drobilla.net/> + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <sys/fcntl.h> +#include <sys/socket.h> +#include <sys/un.h> + +#include "ingen/Interface.hpp" +#include "ingen/shared/World.hpp" +#include "ingen/shared/AtomReader.hpp" +#include "sord/sordmm.hpp" +#include "sratom/sratom.h" +#include "SocketReceiver.hpp" + +#define LOG(s) s << "[SocketReceiver] " + +namespace Ingen { +namespace Socket { + +SocketReceiver::SocketReceiver(Ingen::Shared::World& world, + SharedPtr<Interface> iface) + : _world(world) + , _iface(iface) +{ + // Create server socket + _sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (_sock == -1) { + LOG(Raul::error) << "Failed to create socket" << std::endl; + return; + } + + _sock_path = world.conf()->option("socket").get_string(); + + // Make server socket address + struct sockaddr_un addr; + memset(&addr, 0, sizeof(struct sockaddr_un)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, _sock_path.c_str(), sizeof(addr.sun_path) - 1); + + // Bind socket to address + if (bind(_sock, (struct sockaddr*)&addr, + sizeof(struct sockaddr_un)) == -1) { + LOG(Raul::error) << "Failed to bind socket" << std::endl; + return; + } + + // Mark socket as a passive socket for accepting incoming connections + if (listen(_sock, 64) == -1) { + LOG(Raul::error) << "Failed to listen on socket" << std::endl; + } + + LOG(Raul::info) << "Opened socket at " << _sock_path << std::endl; + start(); +} + +SocketReceiver::~SocketReceiver() +{ + stop(); + join(); + close(_sock); + unlink(_sock_path.c_str()); +} + +void +SocketReceiver::_run() +{ + while (!_exit_flag) { + // Accept connection from client + socklen_t client_addr_size = sizeof(struct sockaddr_un); + struct sockaddr_un client_addr; + int conn = accept(_sock, (struct sockaddr*)&client_addr, + &client_addr_size); + if (conn == -1) { + LOG(Raul::error) << "Error accepting connection" << std::endl; + continue; + } + + // Set connection to non-blocking so parser can read until EOF + // and not block indefinitely waiting for more input + fcntl(conn, F_SETFL, fcntl(conn, F_GETFL, 0) | O_NONBLOCK); + + // Set up a reader to parse the Turtle message into a model + Sord::World* world = _world.rdf_world(); + SerdEnv* env = world->prefixes().c_obj(); + SordModel* model = sord_new(world->c_obj(), SORD_SPO, false); + SerdReader* reader = sord_new_reader(model, env, SERD_TURTLE, NULL); + + // Set base URI to path: so e.g. </foo/bar> will be a path + SordNode* base_uri = sord_new_uri( + world->c_obj(), (const uint8_t*)"path:"); + serd_env_set_base_uri(env, sord_node_to_serd_node(base_uri)); + + LV2_URID_Map* map = &_world.lv2_uri_map()->urid_map_feature()->urid_map; + + // Set up sratom to build an LV2_Atom from the model + Sratom* sratom = sratom_new(map); + SerdChunk chunk = { NULL, 0 }; + LV2_Atom_Forge forge; + lv2_atom_forge_init(&forge, map); + lv2_atom_forge_set_sink( + &forge, sratom_forge_sink, sratom_forge_deref, &chunk); + + // Read directly from the connection with serd + FILE* f = fdopen(conn, "r"); + serd_reader_read_file_handle(reader, f, (const uint8_t*)"(socket)"); + + // FIXME: Sratom needs work to be able to read resources + SordNode* msg_node = sord_new_blank( + world->c_obj(), (const uint8_t*)"genid1"); + + // Build an LV2_Atom at chunk.buf from the message + sratom_read(sratom, &forge, world->c_obj(), model, msg_node); + + // Make an AtomReader to read that atom and do Ingen things + Shared::AtomReader ar(*_world.lv2_uri_map().get(), + *_world.uris().get(), + _world.forge(), + *_iface.get()); + + // Call _iface methods based on atom content + ar.write((LV2_Atom*)chunk.buf); + + // Respond and close connection + write(conn, "OK", 2); + fclose(f); + close(conn); + + sratom_free(sratom); + sord_node_free(world->c_obj(), msg_node); + serd_reader_free(reader); + sord_free(model); + } +} + +} // namespace Ingen +} // namespace Socket diff --git a/src/socket/SocketReceiver.hpp b/src/socket/SocketReceiver.hpp new file mode 100644 index 00000000..5c7ea316 --- /dev/null +++ b/src/socket/SocketReceiver.hpp @@ -0,0 +1,48 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard <http://drobilla.net/> + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <string> + +#include "raul/SharedPtr.hpp" +#include "raul/Thread.hpp" + +namespace Ingen { + +class Interface; + +namespace Shared { class World; } + +namespace Socket { + +class SocketReceiver : public Raul::Thread +{ +public: + SocketReceiver(Ingen::Shared::World& world, + SharedPtr<Interface> iface); + + ~SocketReceiver(); + +private: + virtual void _run(); + + Ingen::Shared::World& _world; + SharedPtr<Interface> _iface; + std::string _sock_path; + int _sock; +}; + +} // namespace Ingen +} // namespace Socket diff --git a/src/socket/ingen_socket_server.cpp b/src/socket/ingen_socket_server.cpp new file mode 100644 index 00000000..79e2e05e --- /dev/null +++ b/src/socket/ingen_socket_server.cpp @@ -0,0 +1,51 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard <http://drobilla.net/> + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "raul/log.hpp" + +#include "ingen/shared/Module.hpp" +#include "ingen/shared/World.hpp" + +#include "../server/Engine.hpp" +#include "../server/ServerInterfaceImpl.hpp" + +#include "SocketReceiver.hpp" + +using namespace Ingen; + +struct IngenSocketServerModule : public Ingen::Shared::Module { + void load(Ingen::Shared::World* world) { + Server::Engine* engine = (Server::Engine*)world->local_engine().get(); + SharedPtr<Server::ServerInterfaceImpl> interface( + new Server::ServerInterfaceImpl(*engine)); + receiver = SharedPtr<Ingen::Socket::SocketReceiver>( + new Ingen::Socket::SocketReceiver(*world, interface)); + + engine->add_event_source(interface); + } + + SharedPtr<Ingen::Socket::SocketReceiver> receiver; +}; + +extern "C" { + +Ingen::Shared::Module* +ingen_module_load() +{ + return new IngenSocketServerModule(); +} + +} // extern "C" diff --git a/src/socket/wscript b/src/socket/wscript new file mode 100644 index 00000000..e5de6cec --- /dev/null +++ b/src/socket/wscript @@ -0,0 +1,14 @@ +#!/usr/bin/env python +from waflib.extras import autowaf as autowaf + +def build(bld): + if bld.is_defined('HAVE_SOCKET'): + obj = bld(features = 'cxx cxxshlib', + source = ['SocketReceiver.cpp', + 'ingen_socket_server.cpp'], + includes = ['.', '../..'], + name = 'libingen_socket_server', + target = 'ingen_socket_server', + install_path = '${LIBDIR}', + use = 'libingen_server') + autowaf.use_lib(bld, obj, 'RAUL LIBLO') |