xref: /titanic_50/usr/src/cmd/audio/utilities/AudioDebug.cc (revision e5dcf7beb7c949f9234713d5818b581ec3825443)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1993-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 // XXX - all this either goes away or gets repackaged
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 
34 #include <AudioDebug.h>
35 
36 // Global debugging level variable
37 int	Audio_debug;
38 
39 
40 // Get debug level
41 int
42 GetDebug()
43 {
44 	return (Audio_debug);
45 }
46 
47 // Set debug level
48 void
49 SetDebug(
50 	int	val)			// new level
51 {
52 	Audio_debug = val;
53 }
54 
55 // Default error printing routine
56 Boolean
57 AudioStderrMsg(
58 	const Audio*	cp,		// object pointer
59 	AudioError	code,		// error code
60 	AudioSeverity	sev,		// error severity
61 	char		*str)		// additional message string
62 {
63 	int		id;
64 	char		*name;
65 
66 	id = cp->getid();
67 	switch (sev) {
68 	default:
69 		name = cp->GetName();
70 		break;
71 	case InitMessage:		// virtual function table not ready
72 	case InitFatal:
73 		name = cp->Audio::GetName();
74 		break;
75 	}
76 
77 	switch (sev) {
78 	case InitMessage:
79 	case Message:
80 		if (Audio_debug > 1)
81 			(void) fprintf(stderr, _MGET_("%d: %s (%s) %s\n"),
82 			    id, str, name, code.msg());
83 		return (TRUE);
84 	case Warning:
85 		(void) fprintf(stderr, _MGET_("Warning: %s: %s %s\n"),
86 		    name, code.msg(), str);
87 		if (Audio_debug > 2)
88 			abort();
89 		return (TRUE);
90 	case Error:
91 		(void) fprintf(stderr, _MGET_("Error: %s: %s %s\n"),
92 		    name, code.msg(), str);
93 		if (Audio_debug > 1)
94 			abort();
95 		return (FALSE);
96 	case Consistency:
97 		(void) fprintf(stderr,
98 		    _MGET_("Audio Consistency Error: %s: %s %s\n"),
99 		    name, str, code.msg());
100 		if (Audio_debug > 0)
101 			abort();
102 		return (FALSE);
103 	case InitFatal:
104 	case Fatal:
105 		(void) fprintf(stderr,
106 		    _MGET_("Audio Internal Error: %s: %s %s\n"),
107 		    name, str, code.msg());
108 		if (Audio_debug > 0)
109 			abort();
110 		return (FALSE);
111 	}
112 	return (TRUE);
113 }
114 
115 #ifdef DEBUG
116 void
117 AudioDebugMsg(
118 	int	level,
119 	char	*fmt,
120 		...)
121 {
122 	va_list ap;
123 
124 	if (Audio_debug >= level) {
125 		va_start(ap, fmt);
126 		vfprintf(stderr, fmt, ap);
127 		va_end(ap);
128 	}
129 }
130 #endif
131