Edinburgh Speech Tools 2.4-release
EST_rw_status.h
1/*************************************************************************/
2/* */
3/* Centre for Speech Technology Research */
4/* University of Edinburgh, UK */
5/* Copyright (c) 1994,1995,1996 */
6/* All Rights Reserved. */
7/* */
8/* Permission is hereby granted, free of charge, to use and distribute */
9/* this software and its documentation without restriction, including */
10/* without limitation the rights to use, copy, modify, merge, publish, */
11/* distribute, sublicense, and/or sell copies of this work, and to */
12/* permit persons to whom this work is furnished to do so, subject to */
13/* the following conditions: */
14/* 1. The code must retain the above copyright notice, this list of */
15/* conditions and the following disclaimer. */
16/* 2. Any modifications must be clearly marked as such. */
17/* 3. Original authors' names are not deleted. */
18/* 4. The authors' names are not used to endorse or promote products */
19/* derived from this software without specific prior written */
20/* permission. */
21/* */
22/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30/* THIS SOFTWARE. */
31/* */
32/*************************************************************************/
33/* Author : Paul Taylor */
34/* Date : April 1994 */
35/*-----------------------------------------------------------------------*/
36/* Utility Function header file for C and C++ */
37/* */
38/*=======================================================================*/
39
40#ifndef __RW_STATUS_H__
41#define __RW_STATUS_H__
42
43#ifdef __cplusplus
44#include <cstdio>
45#include <cerrno>
46#else
47#include <stdio.h>
48#include <errno.h>
49
50#endif
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56
57 /*
58 * make_status_int builds the status as an integer
59 * make_X_status casts it to the required type.
60 */
61
62#define make_status_int(STATE, REASON, ERRNO) \
63 ( ((((unsigned int)(STATE)) & 0xff) <<24) \
64 | ((((unsigned int)(REASON)) & 0xff) <<16) \
65 | ((((unsigned int)(ERRNO)) & 0xffff) <<00) \
66 )
67
68#define make_read_status(STATE, REASON, ERRNO)\
69 ((EST_read_status)(make_status_int(STATE, REASON, ERRNO)))
70
71#define make_write_status(STATE, REASON, ERRNO) \
72 ((EST_write_status)(make_status_int(REASON, STATE, ERRNO)))
73
74 /*
75 * Extract the bits.
76 */
77
78#define get_rw_state(STATUS) \
79 ((EST_rw_state)((((unsigned int)(STATUS)) >> 24) & 0xff))
80#define get_rw_reason(STATUS) \
81 ((EST_rw_reason)((((unsigned int)(STATUS)) >> 16) & 0xff))
82#define get_rw_errno(STATUS) \
83 ((int)((((unsigned int)(STATUS)) >> 0) & 0xff))
84
85
86 /*
87 * Why we failed.
88 */
89
90enum EST_rw_reason {
91 rwr_none=0,
92 rwr_format=1,
93 rwr_existance=2,
94 rwr_permission=3,
95 rwr_system=4,
96 rwr_unknown=0xff
97};
98
99/** State of rw */
100enum EST_rw_state {
101 /// ok
102 rws_ok=0,
103 /// partial
104 rws_partial=1,
105 /// failed
106 rws_failed=0xff
107};
108
109
110/** Possible outcomes of a file reading operation. More stuff*/
111enum EST_read_status {
112 /// The file was read in successfully
113 read_ok = make_status_int(rws_ok, rwr_none, 0),
114 /// The file exists but is not in the format specified
115 read_format_error = make_status_int(rws_failed, rwr_format, 0),
116 /// The file does not exist.
117 read_not_found_error = make_status_int(rws_failed, rwr_existance, 0),
118 /// An error occurred while reading
119 read_error = make_status_int(rws_failed, rwr_unknown, 0)
120};
121
122
123/** Possible outcomes of a file writing operation */
124enum EST_write_status {
125 /// The file was written successfully
126 write_ok = make_status_int(rws_ok, rwr_none, 0),
127 /// The file was not written successfully
128 write_fail = make_status_int(rws_failed, rwr_unknown, 0),
129 /// The file was not written successfully
130 write_error = make_status_int(rws_failed, rwr_unknown, 0),
131 /// A valid file was created, but only some of the requested data is in there
132 write_partial = make_status_int(rws_partial, rwr_unknown, 0)
133};
134
135/** Possible outcomes of a network connection operation */
136enum EST_connect_status {
137 /// Connection made.
138 connect_ok = make_status_int(rws_ok, rwr_none, 0),
139 /// Connection failed.
140 connect_not_found_error = make_status_int(rws_failed, rwr_existance, 0),
141 /// Connection failed.
142 connect_not_allowed_error = make_status_int(rws_failed, rwr_permission, 0),
143 /// System failure of some kind
144 connect_system_error = make_status_int(rws_failed, rwr_system, 0),
145 /// The file was not written successfully
146 connect_error = make_status_int(rws_failed, rwr_unknown, 0)
147};
148
149
150
151#ifdef __cplusplus
152}
153#endif
154
155/*
156 * Temporary redefinitions of the old values.
157 */
158
159#define format_ok read_ok
160#define wrong_format read_format_error
161#define misc_read_error read_error
162#define misc_write_error write_error
163
164#endif /*__RW_STATUS_H__ */