*/
void sp_free_error_message(char *message);
+/**
+ * Set the handler function for library debugging messages.
+ *
+ * Debugging messages are generated by the library during each operation,
+ * to help in diagnosing problems. The handler will be called for each
+ * message. The handler can be set to NULL to ignore all debug messages.
+ *
+ * The handler function should accept a format string and variable length
+ * argument list, in the same manner as e.g. printf().
+ *
+ * The default handler is sp_default_debug_handler().
+ */
+void sp_set_debug_handler(void (*handler)(const char *format, ...));
+
+/**
+ * Default handler function for library debugging messages.
+ *
+ * This function prints debug messages to the standard error stream if the
+ * environment variable LIBSERIALPORT_DEBUG is set. Otherwise, they are
+ * ignored.
+ */
+void sp_default_debug_handler(const char *format, ...);
+
/** @} */
#ifdef __cplusplus
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
+#include <stdio.h>
+#include <stdarg.h>
#ifdef _WIN32
#include <windows.h>
#include <tchar.h>
#endif
};
+void (*sp_debug_handler)(const char *format, ...) = sp_default_debug_handler;
+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define NUM_STD_BAUDRATES ARRAY_SIZE(std_baudrates)
(void)message;
#endif
}
+
+void sp_set_debug_handler(void (*handler)(const char *format, ...))
+{
+ sp_debug_handler = handler;
+}
+
+void sp_default_debug_handler(const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ if (getenv("LIBSERIALPORT_DEBUG")) {
+ fputs("libserialport: ", stderr);
+ vfprintf(stderr, format, args);
+ }
+ va_end(args);
+}