view spandsp-0.0.3/spandsp-0.0.3/src/spandsp/logging.h @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
line wrap: on
line source

/*
 * SpanDSP - a series of DSP components for telephony
 *
 * logging.h - definitions for error and debug logging.
 *
 * Written by Steve Underwood <steveu@coppice.org>
 *
 * Copyright (C) 2005 Steve Underwood
 *
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: logging.h,v 1.10 2006/10/24 13:45:28 steveu Exp $
 */

/*! \file */

/*! \page logging_page Logging
\section logging_page_sec_1 What does it do?
???.
*/

#if !defined(_LOGGING_H_)
#define _LOGGING_H_

/*! General logging function for spandsp logging. */
typedef void (*message_handler_func_t)(int level, const char *text);

/*! Error logging function for spandsp logging. */
typedef void (*error_handler_func_t)(const char *text);

/* Logging elements */
enum
{
    SPAN_LOG_SEVERITY_MASK          = 0x00FF,
    SPAN_LOG_SHOW_DATE              = 0x0100,
    SPAN_LOG_SHOW_SAMPLE_TIME       = 0x0200,
    SPAN_LOG_SHOW_SEVERITY          = 0x0400,
    SPAN_LOG_SHOW_PROTOCOL          = 0x0800,
    SPAN_LOG_SHOW_VARIANT           = 0x1000,
    SPAN_LOG_SHOW_TAG               = 0x2000,
    SPAN_LOG_SUPPRESS_LABELLING     = 0x8000
};

/* Logging severity levels */
enum
{
    SPAN_LOG_NONE                       = 0,
    SPAN_LOG_ERROR                      = 1,
    SPAN_LOG_WARNING                    = 2,
    SPAN_LOG_PROTOCOL_ERROR             = 3,
    SPAN_LOG_PROTOCOL_WARNING           = 4,
    SPAN_LOG_FLOW                       = 5,
    SPAN_LOG_FLOW_2                     = 6,
    SPAN_LOG_FLOW_3                     = 7,
    SPAN_LOG_DEBUG                      = 8,
    SPAN_LOG_DEBUG_2                    = 9,
    SPAN_LOG_DEBUG_3                    = 10
};

/*!
    Logging descriptor. This defines the working state for a single instance of
    the logging facility for spandsp.
*/
typedef struct
{
    int level;
    int samples_per_second;
    int64_t elapsed_samples;
    const char *tag;
    const char *protocol;

    message_handler_func_t span_message;
    error_handler_func_t span_error;
} logging_state_t;

#ifdef __cplusplus
extern "C" {
#endif

/*! Test if logging of a specified severity level is enabled.
    \brief Test if logging of a specified severity level is enabled.
    \param s The logging context.
    \param level The severity level to be tested.
    \return TRUE if logging is enable, else FALSE.
*/
int span_log_test(logging_state_t *s, int level);

/*! Generate a log entry.
    \brief Generate a log entry.
    \param s The logging context.
    \param level The severity level of the entry.
    \param format ???
    \return 0 if no output generated, else 1.
*/
int span_log(logging_state_t *s, int level, const char *format, ...);

/*! Generate a log entry displaying the contents of a buffer.
    \brief Generate a log entry displaying the contents of a buffer
    \param s The logging context.
    \param level The severity level of the entry.
    \param tag A label for the log entry.
    \param buf The buffer to be dumped to the log.
    \param len The length of buf.
    \return 0 if no output generated, else 1.
*/
int span_log_buf(logging_state_t *s, int level, const char *tag, const uint8_t *buf, int len);

int span_log_init(logging_state_t *s, int level, const char *tag);

int span_log_set_level(logging_state_t *s, int level);

int span_log_set_tag(logging_state_t *s, const char *tag);

int span_log_set_protocol(logging_state_t *s, const char *protocol);

int span_log_set_sample_rate(logging_state_t *s, int samples_per_second);

int span_log_bump_samples(logging_state_t *s, int samples);

void span_log_set_message_handler(logging_state_t *s, message_handler_func_t func);

void span_log_set_error_handler(logging_state_t *s, error_handler_func_t func);

void span_set_message_handler(message_handler_func_t func);

void span_set_error_handler(error_handler_func_t func);

#ifdef __cplusplus
}
#endif

#endif
/*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.