Exemplo n.º 1
0
SocketWriter::SocketWriter(URIMap&            map,
                           URIs&              uris,
                           const Raul::URI&   uri,
                           SPtr<Raul::Socket> sock)
	: AtomWriter(map, uris, *this)
	, _map(map)
	, _sratom(sratom_new(&map.urid_map_feature()->urid_map))
	, _uri(uri)
	, _socket(sock)
{
	// Use <ingen:/root/> as base URI so e.g. </foo/bar> will be a path
	_base = serd_node_from_string(SERD_URI, (const uint8_t*)"ingen:/root/");

	serd_uri_parse(_base.buf, &_base_uri);

	_env    = serd_env_new(&_base);
	_writer = serd_writer_new(
		SERD_TURTLE,
		(SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED),
		_env,
		&_base_uri,
		socket_sink,
		this);

	sratom_set_sink(_sratom,
	                (const char*)_base.buf,
	                (SerdStatementSink)serd_writer_write_statement,
	                (SerdEndSink)serd_writer_end_anon,
	                _writer);
}
Exemplo n.º 2
0
SocketWriter::SocketWriter(URIMap&            map,
                           URIs&              uris,
                           const Raul::URI&   uri,
                           SPtr<Raul::Socket> sock)
	: AtomWriter(map, uris, *this)
	, _map(map)
	, _sratom(sratom_new(&map.urid_map_feature()->urid_map))
	, _uri(uri)
	, _socket(sock)
{
	// Use <ingen:/> as base URI, so relative URIs are like bundle paths
	_base = serd_node_from_string(SERD_URI, (const uint8_t*)"ingen:/");

	serd_uri_parse(_base.buf, &_base_uri);

	// Set up serialisation environment
	_env = serd_env_new(&_base);
	serd_env_set_prefix_from_strings(_env, USTR("atom"),  USTR("http://lv2plug.in/ns/ext/atom#"));
	serd_env_set_prefix_from_strings(_env, USTR("patch"), USTR("http://lv2plug.in/ns/ext/patch#"));
	serd_env_set_prefix_from_strings(_env, USTR("doap"),  USTR("http://usefulinc.com/ns/doap#"));
	serd_env_set_prefix_from_strings(_env, USTR("ingen"), USTR(INGEN_NS));
	serd_env_set_prefix_from_strings(_env, USTR("lv2"),   USTR("http://lv2plug.in/ns/lv2core#"));
	serd_env_set_prefix_from_strings(_env, USTR("midi"),  USTR("http://lv2plug.in/ns/ext/midi#"));
	serd_env_set_prefix_from_strings(_env, USTR("owl"),   USTR("http://www.w3.org/2002/07/owl#"));
	serd_env_set_prefix_from_strings(_env, USTR("rdf"),   USTR("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
	serd_env_set_prefix_from_strings(_env, USTR("rdfs"),  USTR("http://www.w3.org/2000/01/rdf-schema#"));
	serd_env_set_prefix_from_strings(_env, USTR("xsd"),   USTR("http://www.w3.org/2001/XMLSchema#"));

	// Make a Turtle writer that writes directly to the socket
	_writer = serd_writer_new(
		SERD_TURTLE,
		(SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED),
		_env,
		&_base_uri,
		socket_sink,
		this);

	// Write namespace prefixes to reduce traffic
	serd_env_foreach(_env, write_prefix, this);

	// Configure sratom to write directly to the writer (and thus the socket)
	sratom_set_sink(_sratom,
	                (const char*)_base.buf,
	                (SerdStatementSink)serd_writer_write_statement,
	                (SerdEndSink)serd_writer_end_anon,
	                _writer);
}
Exemplo n.º 3
0
static int
lilv_state_write(LilvWorld*       world,
                 LV2_URID_Map*    map,
                 LV2_URID_Unmap*  unmap,
                 const LilvState* state,
                 SerdWriter*      writer,
                 const char*      uri,
                 const char*      dir)
{
	SerdNode lv2_appliesTo = serd_node_from_string(
		SERD_CURIE, USTR("lv2:appliesTo"));

	const SerdNode* plugin_uri = sord_node_to_serd_node(
		state->plugin_uri->node);

	SerdNode subject = serd_node_from_string(SERD_URI, USTR(uri ? uri : ""));

	// <subject> a pset:Preset
	SerdNode p = serd_node_from_string(SERD_URI, USTR(LILV_NS_RDF "type"));
	SerdNode o = serd_node_from_string(SERD_URI, USTR(LV2_PRESETS__Preset));
	serd_writer_write_statement(writer, 0, NULL,
	                            &subject, &p, &o, NULL, NULL);

	// <subject> lv2:appliesTo <http://example.org/plugin>
	serd_writer_write_statement(writer, 0, NULL,
	                            &subject,
	                            &lv2_appliesTo,
	                            plugin_uri, NULL, NULL);

	// <subject> rdfs:label label
	if (state->label) {
		p = serd_node_from_string(SERD_URI, USTR(LILV_NS_RDFS "label"));
		o = serd_node_from_string(SERD_LITERAL, USTR(state->label));
		serd_writer_write_statement(writer, 0,
		                            NULL, &subject, &p, &o, NULL, NULL);
	}

	SerdEnv*        env  = serd_writer_get_env(writer);
	const SerdNode* base = serd_env_get_base_uri(env, NULL);

	Sratom* sratom = sratom_new(map);
	sratom_set_sink(sratom, (const char*)base->buf,
	                (SerdStatementSink)serd_writer_write_statement,
	                (SerdEndSink)serd_writer_end_anon,
	                writer);

	// Write port values as pretty numbers
	sratom_set_pretty_numbers(sratom, true);

	// Write port values
	for (uint32_t i = 0; i < state->num_values; ++i) {
		PortValue* const value = &state->values[i];

		const SerdNode port = serd_node_from_string(
			SERD_BLANK, USTR(value->symbol));

		// <> lv2:port _:symbol
		p = serd_node_from_string(SERD_URI, USTR(LV2_CORE__port));
		serd_writer_write_statement(writer, SERD_ANON_O_BEGIN,
		                            NULL, &subject, &p, &port, NULL, NULL);

		// _:symbol lv2:symbol "symbol"
		p = serd_node_from_string(SERD_URI, USTR(LV2_CORE__symbol));
		o = serd_node_from_string(SERD_LITERAL, USTR(value->symbol));
		serd_writer_write_statement(writer, SERD_ANON_CONT,
		                            NULL, &port, &p, &o, NULL, NULL);

		// _:symbol pset:value value
		p = serd_node_from_string(SERD_URI, USTR(LV2_PRESETS__value));
		sratom_write(sratom, unmap, SERD_ANON_CONT, &port, &p,
		             value->type, value->size, value->value);

		serd_writer_end_anon(writer, &port);
	}

	// Write property values with precise types
	sratom_set_pretty_numbers(sratom, false);

	// Write properties
	const SerdNode state_node = serd_node_from_string(SERD_BLANK,
	                                                  USTR("2state"));
	if (state->num_props > 0) {
		p = serd_node_from_string(SERD_URI, USTR(LV2_STATE__state));
		serd_writer_write_statement(writer, SERD_ANON_O_BEGIN, NULL,
		                            &subject, &p, &state_node, NULL, NULL);
	}
	for (uint32_t i = 0; i < state->num_props; ++i) {
		Property*   prop = &state->props[i];
		const char* key  = unmap->unmap(unmap->handle, prop->key);

		p = serd_node_from_string(SERD_URI, USTR(key));
		if (prop->type == state->atom_Path && !dir) {
			const char* path     = (const char*)prop->value;
			const char* abs_path = lilv_state_rel2abs(state, path);
			sratom_write(sratom, unmap, SERD_ANON_CONT,
			             &state_node, &p, prop->type,
			             strlen(abs_path) + 1, abs_path);
		} else {
			sratom_write(sratom, unmap, SERD_ANON_CONT,
			             &state_node, &p, prop->type, prop->size, prop->value);
		}
	}
	if (state->num_props > 0) {
		serd_writer_end_anon(writer, &state_node);
	}

	sratom_free(sratom);
	return 0;
}