err.h 3.63 KB
Newer Older
Cullen Jennings's avatar
Cullen Jennings committed
1 2
/*
 * err.h
3
 *
Cullen Jennings's avatar
Cullen Jennings committed
4 5 6 7 8 9
 * error status codes
 *
 * David A. McGrew
 * Cisco Systems, Inc.
 */
/*
10
 *
David McGrew's avatar
David McGrew committed
11
 * Copyright (c) 2001-2006, Cisco Systems, Inc.
Cullen Jennings's avatar
Cullen Jennings committed
12
 * All rights reserved.
13
 *
Cullen Jennings's avatar
Cullen Jennings committed
14 15 16
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
17
 *
Cullen Jennings's avatar
Cullen Jennings committed
18 19
 *   Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
20
 *
Cullen Jennings's avatar
Cullen Jennings committed
21 22 23 24
 *   Redistributions in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following
 *   disclaimer in the documentation and/or other materials provided
 *   with the distribution.
25
 *
Cullen Jennings's avatar
Cullen Jennings committed
26 27 28
 *   Neither the name of the Cisco Systems, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
29
 *
Cullen Jennings's avatar
Cullen Jennings committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */


#ifndef ERR_H
#define ERR_H

49 50
#include <stdio.h>
#include <stdarg.h>
51
#include "srtp.h"
Cullen Jennings's avatar
Cullen Jennings committed
52

53 54 55 56
#ifdef __cplusplus
extern "C" {
#endif

Cullen Jennings's avatar
Cullen Jennings committed
57 58
/**
 * @defgroup Error Error Codes
59
 *
60
 * Error status codes are represented by the enumeration srtp_err_status_t.
61
 *
Cullen Jennings's avatar
Cullen Jennings committed
62 63 64 65 66 67 68 69 70
 * @{
 */


/**
 * @}
 */

typedef enum {
71 72 73
    srtp_err_level_error,
    srtp_err_level_warning,
    srtp_err_level_info,
74
    srtp_err_level_debug
75
} srtp_err_reporting_level_t;
Cullen Jennings's avatar
Cullen Jennings committed
76 77 78

/*
 * err_reporting_init prepares the error system.  If
79
 * ERR_REPORTING_STDOUT is defined, it will log to stdout.
Cullen Jennings's avatar
Cullen Jennings committed
80 81 82
 *
 */

83
srtp_err_status_t srtp_err_reporting_init();
84

85 86 87 88
typedef void (srtp_err_report_handler_func_t)(srtp_err_reporting_level_t level, const char * msg);

srtp_err_status_t srtp_install_err_report_handler(srtp_err_report_handler_func_t func);

Cullen Jennings's avatar
Cullen Jennings committed
89
/*
90 91 92
 * srtp_err_report reports a 'printf' formatted error
 * string, followed by a an arg list.  The level argument
 * is one of srtp_err_reporting_level_t.
Cullen Jennings's avatar
Cullen Jennings committed
93
 *
94 95
 * Errors will be reported to stdout, if ERR_REPORTING_STDOUT
 * is defined.
Cullen Jennings's avatar
Cullen Jennings committed
96 97 98 99
 *
 */

void
100
srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...);
Cullen Jennings's avatar
Cullen Jennings committed
101 102 103


/*
104
 * debug_module_t defines a debug module
Cullen Jennings's avatar
Cullen Jennings committed
105 106
 */

107
typedef struct {
108 109 110
    int on;           /* 1 if debugging is on, 0 if it is off */
    const char *name; /* printable name for debug module      */
} srtp_debug_module_t;
Cullen Jennings's avatar
Cullen Jennings committed
111

112
#ifdef ENABLE_DEBUG_LOGGING
Cullen Jennings's avatar
Cullen Jennings committed
113

114 115 116 117
#define debug_print(mod, format, arg)                  \
    srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
#define debug_print2(mod, format, arg1, arg2)                  \
    srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg1, arg2)
Cullen Jennings's avatar
Cullen Jennings committed
118

119
#else
Cullen Jennings's avatar
Cullen Jennings committed
120 121

#define debug_print(mod, format, arg)                  \
122 123 124
    if (mod.on) srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
#define debug_print2(mod, format, arg1, arg2)                  \
    if (mod.on) srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg1, arg2)
Cullen Jennings's avatar
Cullen Jennings committed
125 126 127

#endif

128 129 130 131
#ifdef __cplusplus
}
#endif

Cullen Jennings's avatar
Cullen Jennings committed
132
#endif /* ERR_H */