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