From ba2cea6270dc014bf2751f373404fa915d2c38b6 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 1 Aug 2015 17:40:24 +0100 Subject: Add DOM event handler. Currently just prints the events it gets. --- src/util/Makefile | 11 +++++++++++ src/util/dom-str.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util/dom-str.h | 33 +++++++++++++++++++++++++++++++++ src/util/util.h | 22 ++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 src/util/Makefile create mode 100644 src/util/dom-str.c create mode 100644 src/util/dom-str.h create mode 100644 src/util/util.h (limited to 'src/util') diff --git a/src/util/Makefile b/src/util/Makefile new file mode 100644 index 0000000..4f95e74 --- /dev/null +++ b/src/util/Makefile @@ -0,0 +1,11 @@ +# +# Makefile for libnslayout +# +# Copyright 2015 Michael Drake +# +# Released under the ISC License (see COPYING file) + +# Sources +DIR_SOURCES := dom-str.c + +include $(NSBUILD)/Makefile.subdir diff --git a/src/util/dom-str.c b/src/util/dom-str.c new file mode 100644 index 0000000..b959afe --- /dev/null +++ b/src/util/dom-str.c @@ -0,0 +1,54 @@ +/* + * This file is part of LibNSLayout + * Licensed under the ISC License, http://opensource.org/licenses/ISC + * Copyright 2015 Michael Drake + */ + +/** \file src/util/dom-str.c + * Layout object handling + */ + +#include +#include + +#include "util/dom-str.h" +#include "util/util.h" + +dom_string *nsl_dom_str_node_inserted; +dom_string *nsl_dom_str_subtree_modified; + + +/* Exported function, documented in src/util/dom-str.h */ +nslayout_error nsl_dom_str_init(void) +{ + dom_exception exc; + + exc = dom_string_create((const uint8_t *)"DOMNodeInserted", + SLEN("DOMNodeInserted"), + &nsl_dom_str_node_inserted); + if (exc != DOM_NO_ERR) { + /* TODO: free stuff, return value */ + printf("Failed to create string!\n"); + return NSLAYOUT_NO_MEM; + } + exc = dom_string_create((const uint8_t *)"DOMSubtreeModified", + SLEN("DOMSubtreeModified"), + &nsl_dom_str_subtree_modified); + if (exc != DOM_NO_ERR) { + /* TODO: free stuff, return value */ + printf("Failed to create string!\n"); + return NSLAYOUT_NO_MEM; + } + + return NSLAYOUT_OK; +} + + +/* Exported function, documented in src/util/dom-str.h */ +nslayout_error nsl_dom_str_fini(void) +{ + dom_string_unref(nsl_dom_str_node_inserted); + dom_string_unref(nsl_dom_str_subtree_modified); + + return NSLAYOUT_OK; +} diff --git a/src/util/dom-str.h b/src/util/dom-str.h new file mode 100644 index 0000000..9a51ad5 --- /dev/null +++ b/src/util/dom-str.h @@ -0,0 +1,33 @@ +/* + * This file is part of LibNSLayout + * Licensed under the ISC License, http://opensource.org/licenses/ISC + * Copyright 2015 Michael Drake + */ + +/** \file src/util/dom-str.h + * Layout object handling + */ + +#ifndef nslayout_util_dom_str_h_ +#define nslayout_util_dom_str_h_ + +#include + +extern dom_string *nsl_dom_str_node_inserted; +extern dom_string *nsl_dom_str_subtree_modified; + +/** + * Create the internal DOM strings + * + * \return NSLAYOUT_OK on success, appropriate error otherwise. + */ +nslayout_error nsl_dom_str_init(void); + +/** + * Unref the internal DOM strings + * + * \return NSLAYOUT_OK on success, appropriate error otherwise. + */ +nslayout_error nsl_dom_str_fini(void); + +#endif diff --git a/src/util/util.h b/src/util/util.h new file mode 100644 index 0000000..c03691b --- /dev/null +++ b/src/util/util.h @@ -0,0 +1,22 @@ +/* + * This file is part of LibNSLayout + * Licensed under the ISC License, http://opensource.org/licenses/ISC + * Copyright 2015 Michael Drake + */ + +/** \file src/util/util.h + * Layout object handling + */ + +#ifndef nslayout_util_util_h_ +#define nslayout_util_util_h_ + +#ifndef UNUSED +#define UNUSED(x) (void)(x) +#endif + +#ifndef SLEN +#define SLEN(x) (sizeof((x)) - 1) +#endif + +#endif -- cgit v1.2.3