printer REFACTOR write callback typedef
diff --git a/src/printer.c b/src/printer.c
index 1f74076..6272bb3 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -160,7 +160,7 @@
}
API LY_ERR
-ly_out_new_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, struct ly_out **out)
+ly_out_new_clb(ly_write_clb writeclb, void *user_data, struct ly_out **out)
{
LY_CHECK_ARG_RET(NULL, out, writeclb, LY_EINVAL);
@@ -169,12 +169,12 @@
(*out)->type = LY_OUT_CALLBACK;
(*out)->method.clb.func = writeclb;
- (*out)->method.clb.arg = arg;
+ (*out)->method.clb.arg = user_data;
return LY_SUCCESS;
}
-API ssize_t (*ly_out_clb(struct ly_out *out, ssize_t (*writeclb)(void *arg, const void *buf, size_t count)))(void *arg, const void *buf, size_t count)
+API ly_write_clb ly_out_clb(struct ly_out *out, ly_write_clb writeclb)
{
void *prev_clb;
diff --git a/src/printer.h b/src/printer.h
index 030dabc..5eb217d 100644
--- a/src/printer.h
+++ b/src/printer.h
@@ -66,15 +66,26 @@
LY_ERR ly_out_reset(struct ly_out *out);
/**
+ * @brief Generic write callback for data printed by libyang.
+ *
+ * @param[in] user_data Optional caller-specific argument.
+ * @param[in] buf Data to write.
+ * @param[in] count Number of bytes to write.
+ * @return Number of printed bytes.
+ * @return Negative value in case of error.
+ */
+typedef ssize_t (*ly_write_clb)(void *user_data, const void *buf, size_t count);
+
+/**
* @brief Create printer handler using callback printer function.
*
* @param[in] writeclb Pointer to the printer callback function writing the data (see write(2)).
- * @param[in] arg Optional caller-specific argument to be passed to the @p writeclb callback.
+ * @param[in] user_data Optional caller-specific argument to be passed to the @p writeclb callback.
* @param[out] out Created printer handler supposed to be passed to different ly*_print() functions.
* @return LY_SUCCESS in case of success
* @return LY_EMEM in case allocating the @p out handler fails.
*/
-LY_ERR ly_out_new_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, struct ly_out **out);
+LY_ERR ly_out_new_clb(ly_write_clb writeclb, void *user_data, struct ly_out **out);
/**
* @brief Get or reset callback function associated with a callback printer handler.
@@ -83,7 +94,7 @@
* @param[in] fd Optional value of a new file descriptor for the handler. If -1, only the current file descriptor value is returned.
* @return Previous value of the file descriptor.
*/
-ssize_t (*ly_out_clb(struct ly_out *out, ssize_t (*writeclb)(void *arg, const void *buf, size_t count)))(void *arg, const void *buf, size_t count);
+ly_write_clb ly_out_clb(struct ly_out *out, ly_write_clb writeclb);
/**
* @brief Get or reset callback function's argument aasociated with a callback printer handler.
diff --git a/src/printer_data.c b/src/printer_data.c
index 2fffc57..50ac2e1 100644
--- a/src/printer_data.c
+++ b/src/printer_data.c
@@ -144,15 +144,14 @@
}
API LY_ERR
-lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
- const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_clb(ly_write_clb writeclb, void *user_data, const struct lyd_node *root, LYD_FORMAT format, int options)
{
LY_ERR ret;
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, writeclb, LY_EINVAL);
- LY_CHECK_RET(ly_out_new_clb(writeclb, arg, &out));
+ LY_CHECK_RET(ly_out_new_clb(writeclb, user_data, &out));
ret = lyd_print_(out, root, format, options);
ly_out_free(out, NULL, 0);
return ret;
diff --git a/src/printer_data.h b/src/printer_data.h
index 3eb4fec..44e365f 100644
--- a/src/printer_data.h
+++ b/src/printer_data.h
@@ -19,6 +19,7 @@
#include <unistd.h>
#include "log.h"
+#include "printer.h"
#include "tree_data.h"
#ifdef __cplusplus
@@ -126,14 +127,13 @@
* @brief Print data tree in the specified format.
*
* @param[in] writeclb Callback function to write the data (see write(1)).
- * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
+ * @param[in] user_data Optional caller-specific argument to be passed to the \p writeclb callback.
* @param[in] root The root element of the (sub)tree to print.
* @param[in] format Output format.
* @param[in] options [Data printer flags](@ref dataprinterflags).
* @return LY_ERR value.
*/
-LY_ERR lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
- const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_clb(ly_write_clb writeclb, void *user_data, const struct lyd_node *root, LYD_FORMAT format, int options);
#ifdef __cplusplus
}
diff --git a/src/printer_schema.c b/src/printer_schema.c
index dd31369..f59676a 100644
--- a/src/printer_schema.c
+++ b/src/printer_schema.c
@@ -176,14 +176,13 @@
}
API LY_ERR
-lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
- const struct lys_module *module, LYS_OUTFORMAT format, int options)
+lys_print_clb(ly_write_clb writeclb, void *user_data, const struct lys_module *module, LYS_OUTFORMAT format, int options)
{
struct ly_out *out;
LY_CHECK_ARG_RET(NULL, writeclb, module, LY_EINVAL);
- LY_CHECK_RET(ly_out_new_clb(writeclb, arg, &out));
+ LY_CHECK_RET(ly_out_new_clb(writeclb, user_data, &out));
return lys_print_(out, module, format, options);
}
diff --git a/src/printer_schema.h b/src/printer_schema.h
index 0a5254d..1a7dfc3 100644
--- a/src/printer_schema.h
+++ b/src/printer_schema.h
@@ -19,6 +19,7 @@
#include <unistd.h>
#include "log.h"
+#include "printer.h"
#ifdef __cplusplus
extern "C" {
@@ -151,12 +152,12 @@
*
* @param[in] module Schema tree to print.
* @param[in] writeclb Callback function to write the data (see write(1)).
- * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
+ * @param[in] user_data Optional caller-specific argument to be passed to the \p writeclb callback.
* @param[in] format Schema output format.
* @param[in] options Schema output options (see @ref schemaprinterflags).
* @return LY_ERR value.
*/
-LY_ERR lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
+LY_ERR lys_print_clb(ly_write_clb writeclb, void *user_data,
const struct lys_module *module, LYS_OUTFORMAT format, int options);
/**