Next: Transform Plugin API, Previous: Reader Plugin API, Up: Writing Plugins [Contents]
Override on STCSWriterClass:
configureParse template and maps; stcs_writer_add_mapping(key, datapoint).
write_valueCalled when a mapped datapoint changes. Update the outbound buffer and
send it (typically stcs_writer_write_bytes()).
<write-attempts> is handled by the base writer (retry same bytes
on transport write-error). Connect acknowledgement via the writer ack
hook used by runlevel wiring.
G_DECLARE_FINAL_TYPE (MyWriter, my_writer,
MY, WRITER, STCSWriter)
static gboolean
my_writer_configure (STCSWriter *w,
xmlNodePtr node,
STCSDatapointLookupFunc lookup,
gpointer lookup_data,
GError **error)
{
STCSDatapoint *dp = lookup ("out", lookup_data);
if (dp == NULL)
return FALSE;
stcs_writer_add_mapping (w, "out", dp);
return TRUE;
}
static gboolean
my_writer_write_value (STCSWriter *w,
const gchar *key,
gdouble value,
GError **error)
{
gchar *text = g_strdup_printf ("%g\n", value);
GBytes *bytes = g_bytes_new_take (text, strlen (text));
gboolean ok = stcs_writer_write_bytes (w, bytes, error);
g_bytes_unref (bytes);
return ok;
}
static void
my_writer_class_init (MyWriterClass *klass)
{
STCSWriterClass *wc = STCS_WRITER_CLASS (klass);
wc->configure = my_writer_configure;
wc->write_value = my_writer_write_value;
}