summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-05-02 06:24:22 +0000
committerDavid Robillard <d@drobilla.net>2012-05-02 06:24:22 +0000
commitfe353cce9665b33a7372ed2d1683b3c2748625f7 (patch)
tree81287558b014309820e9df64033edc0b29d23b4f
parent1c736a348c59d98e4022fb02b49a8b4c93baa3d2 (diff)
downloadingen-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
-rw-r--r--bundles/ingen.lv2/ingen.ttl4
-rw-r--r--ingen/shared/AtomReader.hpp2
-rw-r--r--ingen/shared/URIs.hpp2
-rwxr-xr-xscripts/ingen_cmd148
-rw-r--r--src/client/ClientStore.cpp2
-rw-r--r--src/gui/LoadPluginWindow.cpp2
-rw-r--r--src/gui/PatchCanvas.cpp2
-rw-r--r--src/ingen/main.cpp4
-rw-r--r--src/serialisation/Parser.cpp6
-rw-r--r--src/serialisation/Serialiser.cpp2
-rw-r--r--src/server/events/SetMetadata.cpp21
-rw-r--r--src/shared/AtomReader.cpp19
-rw-r--r--src/shared/Builder.cpp2
-rw-r--r--src/shared/Configuration.cpp1
-rw-r--r--src/shared/Forge.cpp1
-rw-r--r--src/shared/URIs.cpp2
-rw-r--r--src/shared/World.cpp1
-rw-r--r--src/socket/SocketReceiver.cpp149
-rw-r--r--src/socket/SocketReceiver.hpp48
-rw-r--r--src/socket/ingen_socket_server.cpp51
-rw-r--r--src/socket/wscript14
-rw-r--r--wscript11
22 files changed, 465 insertions, 29 deletions
diff --git a/bundles/ingen.lv2/ingen.ttl b/bundles/ingen.lv2/ingen.ttl
index d581e458..95c26836 100644
--- a/bundles/ingen.lv2/ingen.ttl
+++ b/bundles/ingen.lv2/ingen.ttl
@@ -99,7 +99,7 @@ the node take precedence over properties of the node's plugin. This way a
node can be expressed as a lightweight set of changes (e.g. input values)
from its plugin or patch which may be defined elsewhere.
-A node MUST have at least one rdf:instanceOf property which is a subclass
+A node MUST have at least one ingen:prototype property which is a subclass
of :Plugin. When there are many such properties, an applications SHOULD
use the most specific class it understands.
""" .
@@ -117,7 +117,7 @@ ingen:Port
rdfs:label "Port" ;
rdfs:comment """
A Port is an input or output on a Node. It is implicitly an instance of the
-corresponding port on that Node's plugin (specified with rdf:instanceOf).
+corresponding port on that Node's plugin (specified with ingen:prototype).
A Port MUST have a legal lv2:symbol in the exact way a Node must, see :Node
documentation for details. Ports inherit properties from the Port on their
parent's Plugin in the exact way Nodes inherit properties from their Plugin.
diff --git a/ingen/shared/AtomReader.hpp b/ingen/shared/AtomReader.hpp
index f57dffa7..ef80a4b1 100644
--- a/ingen/shared/AtomReader.hpp
+++ b/ingen/shared/AtomReader.hpp
@@ -41,7 +41,7 @@ public:
void write(const LV2_Atom* msg);
private:
- void get_uri(const LV2_Atom* in, Raul::Atom& out);
+ void get_atom(const LV2_Atom* in, Raul::Atom& out);
void get_props(const LV2_Atom_Object* obj,
Ingen::Resource::Properties& props);
diff --git a/ingen/shared/URIs.hpp b/ingen/shared/URIs.hpp
index f59f5c38..9ebdbf27 100644
--- a/ingen/shared/URIs.hpp
+++ b/ingen/shared/URIs.hpp
@@ -78,6 +78,7 @@ public:
const Quark ingen_node;
const Quark ingen_polyphonic;
const Quark ingen_polyphony;
+ const Quark ingen_prototype;
const Quark ingen_sampleRate;
const Quark ingen_selected;
const Quark ingen_tail;
@@ -121,7 +122,6 @@ public:
const Quark patch_remove;
const Quark patch_request;
const Quark patch_subject;
- const Quark rdf_instanceOf;
const Quark rdf_type;
const Quark rdfs_seeAlso;
const Quark wildcard;
diff --git a/scripts/ingen_cmd b/scripts/ingen_cmd
new file mode 100755
index 00000000..aac616b6
--- /dev/null
+++ b/scripts/ingen_cmd
@@ -0,0 +1,148 @@
+#!/usr/bin/env python
+# Ingen Command-Line Interface
+# Copyright 2011-2012 David Robillard <http://drobilla.net>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+import os.path
+import socket
+import sys
+import time
+
+class Client:
+ def __init__(self, path='/tmp/ingen.sock'):
+ self.path = path
+
+ def send(self, msg):
+ self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ self.sock.connect(self.path)
+ print "SENDING:\n%s\n" % msg
+ self.sock.send(msg)
+ response = self.sock.recv(1024)
+ self.sock.close()
+ if response != 'OK':
+ print 'Error: %s' % response
+ return False
+ else:
+ return True
+
+ def put(self, path, body):
+ return self.send('''
+[]
+ a patch:Put ;
+ patch:subject <%s> ;
+ patch:body [
+%s
+] .
+''' % (path, body))
+
+ def set(self, path, body):
+ return self.send('''
+[]
+ a patch:Set ;
+ patch:subject <%s> ;
+ patch:body [
+%s
+ ] .
+''' % (path, body))
+
+ def connect(self, tail, head):
+ return self.send('''
+[]
+ a patch:Put ;
+ patch:subject <%s> ;
+ patch:body [
+ a ingen:Edge ;
+ ingen:tail <%s> ;
+ ingen:head <%s> ;
+ ] .
+''' % (os.path.commonprefix([tail, head]), tail, head))
+
+ def disconnect(self, tail, head):
+ return self.send('''
+[]
+ a patch:Delete ;
+ patch:body [
+ a ingen:Edge ;
+ ingen:tail <%s> ;
+ ingen:head <%s> ;
+ ] .
+''' % (tail, head))
+
+ def delete(self, path):
+ return self.send('''
+[]
+ a patch:Delete ;
+ patch:subject <%s> .
+''' % (path))
+
+def print_usage():
+ print '''Usage: %s COMMAND [ARGUMENT]...
+A command line interface to an Ingen server.
+
+Commands:
+ put PATH TURTLE_FRAGMENT
+ set PATH TURTLE_FRAGMENT
+ connect TAIL_PATH HEAD_PATH
+ disconnect TAIL_PATH HEAD_PATH
+ delete PATH
+
+Paths are UNIX-style paths with strict LV2 symbol components, e.g. /foo/bar_2.
+Turtle fragments are used verbatim as the body of blank nodes, the syntax is
+identical to the descriptions in Ingen patch files.
+
+Example:
+ ingen_cmd put /left_in 'a lv2:InputPort ; a lv2:AudioPort'
+ ingen_cmd put /left_out 'a lv2:OutputPort ; a lv2:AudioPort'
+
+ ingen_cmd put /tone 'a ingen:Node ; ingen:prototype <http://drobilla.net/plugins/mda/Shepard>'
+ ingen_cmd put /combo 'a ingen:Node ; ingen:prototype <http://drobilla.net/plugins/mda/Combo>'
+ ingen_cmd connect /left_in /tone/left_in
+ ingen_cmd connect /tone/left_out /combo/left_in
+ ingen_cmd connect /combo/left_out /left_out
+ ingen_cmd set /tone/output 'ingen:value 0.7'
+'''
+
+def abort_if_num_args_less_than(num):
+ if len(sys.argv) < num:
+ print_usage()
+ sys.exit(1)
+
+abort_if_num_args_less_than(3)
+ingen = Client()
+
+cmd = sys.argv[1]
+success = 0
+if cmd == 'put':
+ abort_if_num_args_less_than(3)
+ success = ingen.put(sys.argv[2], sys.argv[3])
+elif cmd == 'set':
+ abort_if_num_args_less_than(3)
+ success = ingen.set(sys.argv[2], sys.argv[3])
+elif cmd == 'connect':
+ abort_if_num_args_less_than(4)
+ success = ingen.connect(sys.argv[2], sys.argv[3])
+elif cmd == 'disconnect':
+ abort_if_num_args_less_than(4)
+ success = ingen.disconnect(sys.argv[2], sys.argv[3])
+elif cmd == 'delete':
+ success = ingen.delete(sys.argv[2])
+else:
+ print "error: Unknown command `%s'" % cmd
+ print_usage()
+ sys.exit(1)
+
+if success:
+ sys.exit(0)
+else:
+ sys.exit(1)
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')
diff --git a/wscript b/wscript
index 0cf9ab8f..5db31035 100644
--- a/wscript
+++ b/wscript
@@ -3,6 +3,7 @@ import os
import subprocess
import waflib.Options as Options
+import waflib.Utils as Utils
from waflib.extras import autowaf as autowaf
# Version of this package (even if built as a child)
@@ -32,6 +33,8 @@ def options(opt):
help="Do not build OSC via liblo support, even if liblo exists")
opt.add_option('--no-http', action='store_true', default=False, dest='no_http',
help="Do not build HTTP via libsoup support, even if libsoup exists")
+ opt.add_option('--no-socket', action='store_true', default=False, dest='no_socket',
+ help="Do not build Socket interface")
opt.add_option('--log-debug', action='store_true', default=False, dest='log_debug',
help="Print debugging output")
opt.add_option('--liblo-bundles', action='store_true', default=False, dest='liblo_bundles',
@@ -79,6 +82,11 @@ def configure(conf):
if not Options.options.no_osc:
autowaf.check_pkg(conf, 'liblo', uselib_store='LIBLO',
atleast_version='0.25', mandatory=False)
+ if not Options.options.no_socket:
+ conf.check_cc(function_name='socket',
+ header_name='sys/socket.h',
+ define_name='HAVE_SOCKET',
+ mandatory=False)
if not Options.options.no_jack_session:
if conf.is_defined('HAVE_NEW_JACK'):
autowaf.define(conf, 'INGEN_JACK_SESSION', 1)
@@ -120,6 +128,7 @@ def configure(conf):
conf.is_defined('INGEN_JACK_SESSION'))
autowaf.display_msg(conf, "OSC", conf.is_defined('HAVE_LIBLO'))
autowaf.display_msg(conf, "HTTP", conf.is_defined('HAVE_SOUP'))
+ autowaf.display_msg(conf, "SOCKET", conf.is_defined('HAVE_SOCKET'))
autowaf.display_msg(conf, "LV2", conf.is_defined('HAVE_LILV'))
autowaf.display_msg(conf, "GUI", str(conf.env['INGEN_BUILD_GUI'] == 1))
autowaf.display_msg(conf, "LV2 Bundle", conf.env['INGEN_BUNDLE_DIR'])
@@ -144,6 +153,7 @@ def build(bld):
bld.recurse('src/client')
bld.recurse('src/http')
bld.recurse('src/osc')
+ bld.recurse('src/socket')
if bld.is_defined('INGEN_BUILD_GUI'):
bld.recurse('src/gui')
@@ -159,6 +169,7 @@ def build(bld):
autowaf.use_lib(bld, obj, 'GTHREAD GLIBMM SORD RAUL LILV INGEN LV2')
bld.install_files('${DATADIR}/applications', 'src/ingen/ingen.desktop')
+ bld.install_files('${BINDIR}', 'scripts/ingen_cmd', chmod=Utils.O755)
# Documentation
autowaf.build_dox(bld, 'INGEN', INGEN_VERSION, top, out)