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 // XXX - all this either goes away or gets repackaged
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 
32 #include <AudioDebug.h>
33 
34 // Global debugging level variable
35 int	Audio_debug;
36 
37 
38 // Get debug level
39 int
GetDebug()40 GetDebug()
41 {
42 	return (Audio_debug);
43 }
44 
45 // Set debug level
46 void
SetDebug(int val)47 SetDebug(
48 	int	val)			// new level
49 {
50 	Audio_debug = val;
51 }
52 
53 // Default error printing routine
54 Boolean
AudioStderrMsg(const Audio * cp,AudioError code,AudioSeverity sev,const char * str)55 AudioStderrMsg(
56 	const Audio*	cp,		// object pointer
57 	AudioError	code,		// error code
58 	AudioSeverity	sev,		// error severity
59 	const char	*str)		// additional message string
60 {
61 	int		id;
62 	char		*name;
63 
64 	id = cp->getid();
65 	switch (sev) {
66 	default:
67 		name = cp->GetName();
68 		break;
69 	case InitMessage:		// virtual function table not ready
70 	case InitFatal:
71 		name = cp->Audio::GetName();
72 		break;
73 	}
74 
75 	switch (sev) {
76 	case InitMessage:
77 	case Message:
78 		if (Audio_debug > 1)
79 			(void) fprintf(stderr, _MGET_("%d: %s (%s) %s\n"),
80 			    id, str, name, code.msg());
81 		return (TRUE);
82 	case Warning:
83 		(void) fprintf(stderr, _MGET_("Warning: %s: %s %s\n"),
84 		    name, code.msg(), str);
85 		if (Audio_debug > 2)
86 			abort();
87 		return (TRUE);
88 	case Error:
89 		(void) fprintf(stderr, _MGET_("Error: %s: %s %s\n"),
90 		    name, code.msg(), str);
91 		if (Audio_debug > 1)
92 			abort();
93 		return (FALSE);
94 	case Consistency:
95 		(void) fprintf(stderr,
96 		    _MGET_("Audio Consistency Error: %s: %s %s\n"),
97 		    name, str, code.msg());
98 		if (Audio_debug > 0)
99 			abort();
100 		return (FALSE);
101 	case InitFatal:
102 	case Fatal:
103 		(void) fprintf(stderr,
104 		    _MGET_("Audio Internal Error: %s: %s %s\n"),
105 		    name, str, code.msg());
106 		if (Audio_debug > 0)
107 			abort();
108 		return (FALSE);
109 	}
110 	return (TRUE);
111 }
112 
113 #ifdef DEBUG
114 void
AudioDebugMsg(int level,char * fmt,...)115 AudioDebugMsg(
116 	int	level,
117 	char	*fmt,
118 		...)
119 {
120 	va_list ap;
121 
122 	if (Audio_debug >= level) {
123 		va_start(ap, fmt);
124 		vfprintf(stderr, fmt, ap);
125 		va_end(ap);
126 	}
127 }
128 #endif
129