xref: /titanic_41/usr/src/cmd/audio/include/AudioError.h (revision e0724c534a46ca4754330bc022bf1e2a68f5bb93)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _MULTIMEDIA_AUDIOERROR_H
28 #define	_MULTIMEDIA_AUDIOERROR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <locale.h>
33 #include <errno.h>
34 #include <audio_errno.h>	/* to get enum for error codes */
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
41 #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
42 #endif
43 
44 #define	_MGET_(str)	(char *)dgettext(TEXT_DOMAIN, str)
45 #define	_GETTEXT_(str)	(char *)gettext(str)
46 
47 // The AudioError class allows various interesting automatic conversions
48 class AudioError {
49 private:
50 	audioerror_t	code;			// error code
51 
52 public:
53 	int		sys;			// system error code
54 
55 	inline AudioError(audioerror_t val = AUDIO_SUCCESS):	// Constructor
56 	    code(val), sys(0)
57 	    { if (code == AUDIO_UNIXERROR) sys = errno; }
58 	inline AudioError(int val):			// Constructor from int
59 	    code((audioerror_t)val), sys(0)
60 	    { if (code == AUDIO_UNIXERROR) sys = errno; }
61 
62 	inline AudioError operator = (AudioError val)	// Assignment
63 	    { code = val.code; sys = val.sys; return (*this); }
64 	inline operator int()				// Cast to integer
65 	    { return (code); }
66 	inline int operator == (audioerror_t e)		// Compare
67 	    { return (code == e); }
68 	inline int operator != (audioerror_t e)		// Compare
69 	    { return (code != e); }
70 	inline int operator == (AudioError e)		// Compare
71 	    { return ((code == e.code) && (sys == e.sys)); }
72 	inline int operator != (AudioError e)		// Compare
73 	    { return ((code != e.code) || (sys != e.sys)); }
74 
75 	char *msg();					// Return error string
76 };
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif /* !_MULTIMEDIA_AUDIOERROR_H */
83