diff options
Diffstat (limited to 'src/sink.c')
-rw-r--r-- | src/sink.c | 55 |
1 files changed, 33 insertions, 22 deletions
@@ -46,37 +46,40 @@ serd_sink_free(SerdSink* sink) } SerdStatus -serd_sink_set_base_func(SerdSink* sink, SerdBaseFunc base_func) +serd_sink_set_event_func(SerdSink* sink, SerdEventFunc event_func) { - sink->base = base_func; + sink->on_event = event_func; return SERD_SUCCESS; } SerdStatus -serd_sink_set_prefix_func(SerdSink* sink, SerdPrefixFunc prefix_func) +serd_sink_write_event(const SerdSink* sink, const SerdEvent* event) { - sink->prefix = prefix_func; - return SERD_SUCCESS; -} - -SerdStatus -serd_sink_set_statement_func(SerdSink* sink, SerdStatementFunc statement_func) -{ - sink->statement = statement_func; - return SERD_SUCCESS; -} + switch (event->type) { + case SERD_BASE: + return serd_sink_write_base(sink, event->base.uri); + case SERD_PREFIX: + return serd_sink_write_prefix(sink, + event->prefix.name, + event->prefix.uri); + case SERD_STATEMENT: + return serd_sink_write_statement(sink, + event->statement.flags, + event->statement.statement); + case SERD_END: + return serd_sink_write_end(sink, event->end.node); + } -SerdStatus -serd_sink_set_end_func(SerdSink* sink, SerdEndFunc end_func) -{ - sink->end = end_func; return SERD_SUCCESS; } SerdStatus serd_sink_write_base(const SerdSink* sink, const SerdNode* uri) { - return sink->base ? sink->base(sink->handle, uri) : SERD_SUCCESS; + const SerdBaseEvent ev = { SERD_BASE, uri }; + + return sink->on_event ? sink->on_event(sink->handle, (const SerdEvent*)&ev) + : SERD_SUCCESS; } SerdStatus @@ -84,7 +87,10 @@ serd_sink_write_prefix(const SerdSink* sink, const SerdNode* name, const SerdNode* uri) { - return sink->prefix ? sink->prefix(sink->handle, name, uri) : SERD_SUCCESS; + const SerdPrefixEvent ev = { SERD_PREFIX, name, uri }; + + return sink->on_event ? sink->on_event(sink->handle, (const SerdEvent*)&ev) + : SERD_SUCCESS; } SerdStatus @@ -92,8 +98,10 @@ serd_sink_write_statement(const SerdSink* sink, const SerdStatementFlags flags, const SerdStatement* statement) { - return sink->statement ? sink->statement(sink->handle, flags, statement) - : SERD_SUCCESS; + const SerdStatementEvent ev = { SERD_STATEMENT, flags, statement }; + + return sink->on_event ? sink->on_event(sink->handle, (const SerdEvent*)&ev) + : SERD_SUCCESS; } SerdStatus @@ -112,5 +120,8 @@ serd_sink_write(const SerdSink* sink, SerdStatus serd_sink_write_end(const SerdSink* sink, const SerdNode* node) { - return sink->end ? sink->end(sink->handle, node) : SERD_SUCCESS; + const SerdEndEvent ev = {SERD_END, node}; + + return sink->on_event ? sink->on_event(sink->handle, (const SerdEvent*)&ev) + : SERD_SUCCESS; } |