diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2014-08-27 16:26:52 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2014-08-27 16:26:52 -0400 |
commit | 6203e5b8fcac9d78ea54b7b3c53cb8d084e8a219 (patch) | |
tree | d8611d8e44267151c29ab8920702cc94e86063c5 /gpspacket.c | |
parent | b53db1322c70f8b86dfe72e982d6097304a749ae (diff) | |
download | gpsd-6203e5b8fcac9d78ea54b7b3c53cb8d084e8a219.tar.gz |
Introduce struct errout_t to encapsulate error-reporting hooks.
A major step towards eliminating reverse linkage.
All regression tests pass.
Diffstat (limited to 'gpspacket.c')
-rw-r--r-- | gpspacket.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gpspacket.c b/gpspacket.c index 5d1fbe1f..9d89ec20 100644 --- a/gpspacket.c +++ b/gpspacket.c @@ -40,6 +40,45 @@ void gpsd_report(int unused UNUSED, int errlevel, const char *fmt, ... ) Py_DECREF(args); } +static void basic_report(const char *buf) +{ + (void)fputs(buf, stderr); +} + +void errout_reset(struct errout_t *errout) +{ + errout->debug = 0; + errout->report = basic_report; +} + +void gpsd_notify(const struct errout_t *errout UNUSED, + int errlevel, const char *fmt, ... ) +{ + char buf[BUFSIZ]; + PyObject *args; + va_list ap; + + if (!report_callback) /* no callback defined, exit early */ + return; + + if (!PyCallable_Check(report_callback)) { + PyErr_SetString(ErrorObject, "Cannot call Python callback function"); + return; + } + + va_start(ap, fmt); + (void)vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + + args = Py_BuildValue("(is)", errlevel, buf); + if (!args) + return; + + PyObject_Call(report_callback, args, NULL); + Py_DECREF(args); +} + + static PyTypeObject Lexer_Type; typedef struct { |