From 40268925466dba7a37b468be0bba951e7f6ca5d1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 29 Apr 2018 15:24:05 +0200 Subject: Add SerdWorld for shared library state --- serd/serd.h | 72 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'serd/serd.h') diff --git a/serd/serd.h b/serd/serd.h index 4e9b5d48..715ff22a 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -55,6 +55,13 @@ extern "C" { @{ */ +/** + World. + + The World represents all library state shared between various objects. +*/ +typedef struct SerdWorldImpl SerdWorld; + /** Environment. @@ -693,6 +700,41 @@ typedef struct SerdSinkInterface { SerdEndSink end; } SerdSinkInterface; +/** + @} + @name World + @{ +*/ + +/** + Create a new Serd World. + + It is safe to use multiple worlds in one process, though no objects can be + shared between worlds. +*/ +SERD_API +SerdWorld* +serd_world_new(void); + +/** + Free `world`. +*/ +SERD_API +void +serd_world_free(SerdWorld* world); + +/** + Set a function to be called when errors occur. + + The `error_sink` will be called with `handle` as its first argument. If + no error function is set, errors are printed to stderr. +*/ +SERD_API +void +serd_world_set_error_sink(SerdWorld* world, + SerdErrorSink error_sink, + void* handle); + /** @} @name Environment @@ -800,7 +842,8 @@ serd_env_foreach(const SerdEnv* env, */ SERD_API SerdReader* -serd_reader_new(SerdSyntax syntax, +serd_reader_new(SerdWorld* world, + SerdSyntax syntax, const SerdSinkInterface* sink); /** @@ -814,18 +857,6 @@ SERD_API void serd_reader_set_strict(SerdReader* reader, bool strict); -/** - Set a function to be called when errors occur during reading. - - The `error_sink` will be called with `handle` as its first argument. If - no error function is set, errors are printed to stderr in GCC style. -*/ -SERD_API -void -serd_reader_set_error_sink(SerdReader* reader, - SerdErrorSink error_sink, - void* error_handle); - /** Return the `handle` passed to serd_reader_new(). */ @@ -944,7 +975,8 @@ serd_reader_free(SerdReader* reader); */ SERD_API SerdWriter* -serd_writer_new(SerdSyntax syntax, +serd_writer_new(SerdWorld* world, + SerdSyntax syntax, SerdStyle style, SerdEnv* env, const SerdURI* base_uri, @@ -1004,18 +1036,6 @@ SERD_API char* serd_buffer_sink_finish(SerdBuffer* stream); -/** - Set a function to be called when errors occur during writing. - - The `error_sink` will be called with `handle` as its first argument. If - no error function is set, errors are printed to stderr. -*/ -SERD_API -void -serd_writer_set_error_sink(SerdWriter* writer, - SerdErrorSink error_sink, - void* error_handle); - /** Set a prefix to be removed from matching blank node identifiers. */ -- cgit v1.2.1