File: cmpack_console.h

package info (click to toggle)
c-munipack 2.1.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,888 kB
  • sloc: ansic: 200,762; cpp: 106,123; lex: 9,035; yacc: 4,916; sh: 4,074; fortran: 2,613; xml: 2,105; python: 1,182; makefile: 546; perl: 104
file content (113 lines) | stat: -rw-r--r-- 4,045 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
	\file
	\brief Console related functions

	C-Munipack functions use a console as an output device for
	output and debug messages. By default, all messages are thrown away.
	If you want to print them to standard error stream or process them
	in a user defined callback, make a console and attach it to an object
	using cmpack_*_set_console function.

	\author David Motl <dmotl@volny.cz>
	
	\par Copying
	This program 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, version 2.
	
	$Id: cmpack_console.h,v 1.1 2015/07/06 08:33:22 dmotl Exp $
*/

#ifndef _CMPACK_CONSOLE_H_INCLUDED
#define _CMPACK_CONSOLE_H_INCLUDED

#include "cmpack_config.h"

/********************   Public constants   ********************************/

/** \brief Verbosity level */
typedef enum _CmpackOutputLevel
{
	CMPACK_LEVEL_QUIET,			/**< Be quiet, suppress all messages */
	CMPACK_LEVEL_NORMAL,		/**< Print messages, suppress debug output (default) */
	CMPACK_LEVEL_DEBUG			/**< Be verbose, print all messages including debug ones */
} CmpackOutputLevel;

/********************   Public data types   ********************************/

/**
	\brief Callback procedure
	\details Prototype for custom callback procedures. The procedure
	receives the pointer to message string. It points to internal memory
	buffer, the callee must not free or modify it. The second parameter 
	contains callback registration data.
	\param[in] text			text to be printed to output device
	\param[in] user_data	callback registration data
*/
typedef void CmpackCallbackType(const char *text, void *user_data);

/**	
	\brief Console context 
	\details This private structure holds the console parameters
*/
typedef struct _CmpackConsole CmpackConsole;

/******************   Public functions   ***************************/

#ifdef __cplusplus
extern "C" {
#endif

/**
	\brief Create a new console (for 'stderr' stream)
	\details The function makes a new console that prints the
	information to the standard error stream. This is intended 
	to be used in the console applications.
	\return pointer to context of zero if failed
*/
	CMPACK_EXPORT(CmpackConsole*, cmpack_con_init, (void));

/**
	\brief Create a new console (user-defined processing)
	\details The function makes a new console that sends the output
	to a user-defined callback function. The second parameter is passed
	to the callback function without any processing. The caller can use
	this to pass a context to the callback.
	\return pointer to context of zero if failed
*/
	CMPACK_EXPORT(CmpackConsole*, cmpack_con_init_cb, (CmpackCallbackType* cbproc, void* cbdata));

/**
	\brief Make a new reference to the console
	\details The function makes a new reference to the file and returns a 
	pointer to it. The reference counter is incremented by one. The caller 
	is responsible to call cmpack_con_destroy() when the reference is 
	no longer needed.
	\return pointer to a new reference
*/
	CMPACK_EXPORT(CmpackConsole*, cmpack_con_reference, (CmpackConsole* con));

/**
	\brief Release a reference to the console
	\details The function releases a reference to the console. The reference 
	counter is decreased by one and when it was the last reference to the 
	file, the content of the disk file is updated and it is closed. The data
	are freed from the memory.
*/
	CMPACK_EXPORT(void, cmpack_con_destroy, (CmpackConsole* con));

/**
	\brief Set the debug level
	\details The function sets the debug level to the console. Each message
	has an integer number that indicates the level of the message. The console
	filters out the messages with level lower that the debug level.
	\param[in] ctx			any context
	\param[in] level		verbosity level (see CMPACK_LEVEL_xxx constants)
*/
	CMPACK_EXPORT(void, cmpack_con_set_level, (CmpackConsole* ctx, CmpackOutputLevel level));

#ifdef __cplusplus
}
#endif

#endif