1/*
2 * Copyright 2018, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13/*# Declares C functions and symbols for handling errors
14  #  interface: String that is the name of the current interface
15  #  error_handler: Name of the error handling function that will be created
16  #*/
17/*- macro make_error_handler(interface, error_handler) -*/
18    /*# Assert that our arguments are the correct type #*/
19    /*? assert(isinstance(interface, six.string_types)) ?*/
20    /*? assert(isinstance(error_handler, six.string_types)) ?*/
21
22    /* The currently active error handler. This variable is marked UNUSED to squash
23     * compiler warnings generated when the user's build configuration causes the
24     * two following functions to be pruned from the final source.
25    */
26    static camkes_error_handler_t /*? error_handler ?*/_fn UNUSED;
27
28    camkes_error_handler_t /*? interface ?*/_register_error_handler(
29        camkes_error_handler_t handler) {
30        camkes_error_handler_t old = /*? error_handler ?*/_fn;
31        /*? error_handler ?*/_fn = handler;
32        return old;
33    }
34
35    static camkes_error_action_t UNUSED /*? error_handler ?*/(camkes_error_t *error) {
36        if (/*? error_handler ?*/_fn == NULL) {
37            /* No registered handler; invoke the generic error handler. */
38            return camkes_error(error);
39        }
40        return /*? error_handler ?*/_fn(error);
41    }
42/*- endmacro -*/
43