From 76f4ad0d529623ecd36ce8b0a4f3e73c0240e60c Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 4 Jan 2013 11:01:15 +0100 Subject: Rename project from 'Debug Module' to 'Hugin' --- hugin.h | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 hugin.h (limited to 'hugin.h') diff --git a/hugin.h b/hugin.h new file mode 100644 index 0000000..3f3b753 --- /dev/null +++ b/hugin.h @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * debug.h + * + * Thu Nov 1 13:38:47 CET 2012 + * Copyright 2012 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Debug Module. + * + * Debug Module is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Debug Module 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 Debug Module; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __DEBUG_MODULE_DEBUG_H__ +#define __DEBUG_MODULE_DEBUG_H__ + +enum DBG_FLAG { + // Features +#ifdef WITH_DBG_THREAD + DBG_FLAG_USE_THREAD = 0x00000001, +#endif +#ifdef WITH_DBG_MUTEX + DBG_FLAG_USE_MUTEX = 0x00000002, +#endif +#ifdef WITH_DBG_FILTER + DBG_FLAG_USE_FILTER = 0x00000004, +#endif + + // Outputs + DBG_FLAG_OUTPUT_TO_STDOUT = 0x00010000, + DBG_FLAG_OUTPUT_TO_STDERR = 0x00020000, + DBG_FLAG_OUTPUT_TO_FD = 0x00040000, + DBG_FLAG_OUTPUT_TO_FILE = 0x00080000, +#ifdef WITH_DBG_SYSLOG + DBG_FLAG_OUTPUT_TO_SYSLOG = 0x00100000, +#endif + + // Default value of flags + DBG_FLAG_DEFAULT = DBG_FLAG_OUTPUT_TO_STDOUT, // Output to stdout +}; + +enum DBG_OPTION { + /** + * No more options / last option. This is used + * to terminate the VARARGs list. + */ + DBG_OPTION_END, + + /** + * const char* argument containing a filename which will be used for log + * output. To be used with the DBG_FLAG_OUTPUT_TO_FILE flag. + */ + DBG_OPTION_FILENAME, + + /** + * Integer argument describing a file descriptor which will be used for log + * output. To be used with the DBG_FLAG_OUTPUT_TO_FD flag. + */ + DBG_OPTION_FD, + + /** + * Set this option to make the stdout output to be printed without any date + * information in the header. + * Parameter is an integer. + * Values: + * 0 := use date + * 1 := do not use date. + */ + DBG_OPTION_STDOUT_NO_DATE, + + /** + * Host and port to use when logging on an external server. + * Host is a const char* argument, port is an integer. + * To be used with the DBG_FLAG_USE_SYSLOG flag. + * Linux: If DBG_OPTION_SYSLOG_HOST is not supplied, the local syslog will be + * used. + * Windows: If DBG_OPTION_SYSLOG_HOST is not supplied an error will be + * returned by debug_init. + * If DBG_OPTION_SYSLOG_PORT is not supplied, the default syslogd port will + * be used (port 514). + */ +#ifdef WITH_DBG_SYSLOG + DBG_OPTION_SYSLOG_HOST, + DBG_OPTION_SYSLOG_PORT, +#endif + + /** + * Filter option. Argument is a const char *. + * fmt := [set[,set]*]* + * set := [+-]channel + * | class[+-]channel + * | [+-]all + */ +#ifdef WITH_DBG_FILTER + DBG_OPTION_FILTER, +#endif +}; + +typedef enum { + DBG_STATUS_OK = 0, + DBG_STATUS_UNKNOWN_OPTION, + DBG_STATUS_ERROR, +} dbg_status_t; + +/** + * @param flags combination of DBG_FLAG values + * @param ... list of options (type-value pairs, + * terminated with DBG_OPTION_END). + * @return 0 on success, 1 on error. + */ +dbg_status_t dbg_init(unsigned int flags, ...); +void dbg_close(); + +/** + * Example of usage (use mutex protected calls, send output to file): + * + * dbg_status_t status; + * status = debug_init(DBG_FLAG_OUTPUT_TO_FILE | DBG_FLAG_USE_MUTEX, + * DBG_OPTION_FILENAME, "/tmp/my.log", + DBG_OPTION_END); + * if(status != DBG_STATUS_OK) exit(1); + * INFO(example, "We are up and running\n"); + * dbg_close(); + */ + +/** + * Example of usage (simply outputs to stdout): + * + * INFO(example, "We are up and running\n"); + */ + +enum __debug_class +{ + __class_fixme = 0, + __class_err = 1, + __class_warn = 2, + __class_info = 3, + __class_debug = 4 +}; + +int __debug(const char *func, const int line, enum __debug_class cl, + const char *ch, const char *fmt, ...) + __attribute__((format (printf,5,6))); + +#define __DEBUG_PRINT(cl, ch, fmt...) \ + do { __debug(__func__, __LINE__, cl, ch, fmt); } while(0) +#define __DEBUG(cl, ch, fmt...) \ + __DEBUG_PRINT(__class##cl, #ch, fmt) + +#define ERR(ch, fmt...) __DEBUG(_err, ch, fmt) +#define WARN(ch, fmt...) __DEBUG(_warn, ch, fmt) +#define INFO(ch, fmt...) __DEBUG(_info, ch, fmt) +#define DEBUG(ch, fmt...) __DEBUG(_debug, ch, fmt) + +#endif/*__DEBUG_MODULE_DEBUG_H__*/ -- cgit v1.2.3