VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prerror.h@ 50011

Last change on this file since 50011 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.1 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef prerror_h___
39#define prerror_h___
40
41#include "prtypes.h"
42
43#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
44#define PR_SetError VBoxNsprPR_SetError
45#define PR_SetErrorText VBoxNsprPR_SetErrorText
46#define PR_GetError VBoxNsprPR_GetError
47#define PR_GetOSError VBoxNsprPR_GetOSError
48#define PR_GetErrorTextLength VBoxNsprPR_GetErrorTextLength
49#define PR_GetErrorText VBoxNsprPR_GetErrorText
50#define PR_ErrorToString VBoxNsprPR_ErrorToString
51#define PR_ErrorToName VBoxNsprPR_ErrorToName
52#define PR_ErrorLanguages VBoxNsprPR_ErrorLanguages
53#define PR_ErrorInstallTable VBoxNsprPR_ErrorInstallTable
54#define PR_ErrorInstallCallback VBoxNsprPR_ErrorInstallCallback
55#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
56PR_BEGIN_EXTERN_C
57
58typedef PRInt32 PRErrorCode;
59
60#define PR_NSPR_ERROR_BASE -6000
61
62#include "prerr.h"
63
64/*
65** Set error will preserve an error condition within a thread context.
66** The values stored are the NSPR (platform independent) translation of
67** the error. Also, if available, the platform specific oserror is stored.
68** If there is no appropriate OS error number, a zero my be supplied.
69*/
70NSPR_API(void) PR_SetError(PRErrorCode errorCode, PRInt32 oserr);
71
72/*
73** The text value specified may be NULL. If it is not NULL and the text length
74** is zero, the string is assumed to be a null terminated C string. Otherwise
75** the text is assumed to be the length specified and possibly include NULL
76** characters (e.g., a multi-national string).
77**
78** The text will be copied into to thread structure and remain there
79** until the next call to PR_SetError.
80*/
81NSPR_API(void) PR_SetErrorText(
82 PRIntn textLength, const char *text);
83
84/*
85** Return the current threads last set error code.
86*/
87NSPR_API(PRErrorCode) PR_GetError(void);
88
89/*
90** Return the current threads last set os error code. This is used for
91** machine specific code that desires the underlying os error.
92*/
93NSPR_API(PRInt32) PR_GetOSError(void);
94
95/*
96** Get the length of the error text. If a zero is returned, then there
97** is no text. Otherwise, the value returned is sufficient to contain
98** the error text currently available.
99*/
100NSPR_API(PRInt32) PR_GetErrorTextLength(void);
101
102/*
103** Copy the current threads current error text. Then actual number of bytes
104** copied is returned as the result. If the result is zero, the 'text' area
105** is unaffected.
106*/
107NSPR_API(PRInt32) PR_GetErrorText(char *text);
108
109
110/*
111Copyright (C) 1987, 1988 Student Information Processing Board of the
112Massachusetts Institute of Technology.
113
114Permission to use, copy, modify, and distribute this software and its
115documentation for any purpose and without fee is hereby granted, provided
116that the above copyright notice appear in all copies and that both that
117copyright notice and this permission notice appear in supporting
118documentation, and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
119used in advertising or publicity pertaining to distribution of the software
120without specific, written prior permission. M.I.T. and the M.I.T. S.I.P.B.
121make no representations about the suitability of this software for any
122purpose. It is provided "as is" without express or implied warranty.
123*/
124
125
126/*
127 * NOTE:
128 * The interfaces for error-code-translation described in the rest of
129 * this file are preliminary in the 3.1 release of nspr and are subject
130 * to change in future releases.
131 */
132
133/*
134** Description: Localizable error code to string function.
135**
136**
137** NSPR provides a mechanism for converting an error code to a
138** descriptive string, in a caller-specified language.
139**
140** Error codes themselves are 32 bit (signed) integers. Typically,
141** the high order 24 bits are an identifier of which error table the
142** error code is from, and the low order 8 bits are a sequential error
143** number within the table. NSPR supports error tables whose first
144** error code is not a multiple of 256, such error code assignments
145** should be avoided when possible.
146**
147** Error table 0 is defined to match the UNIX system call error table
148** (sys_errlist); this allows errno values to be used directly in the
149** library. Other error table numbers are typically formed by
150** compacting together the first four characters of the error table
151** name. The mapping between characters in the name and numeric
152** values in the error code are defined in a system-independent
153** fashion, so that two systems that can pass integral values between
154** them can reliably pass error codes without loss of meaning; this
155** should work even if the character sets used are not the
156** same. (However, if this is to be done, error table 0 should be
157** avoided, since the local system call error tables may differ.)
158**
159** Libraries defining error codes need only provide a table mapping
160** error code numbers to names and default English descriptions,
161** calling a routine to install the table, making it ``known'' to NSPR
162** library. Once installed, a table may not be removed. Any error
163** code the library generates can be converted to the corresponding
164** error message. There is also a default format for error codes
165** accidentally returned before making the table known, which is of
166** the form "unknown code foo 32", where "foo" would be the name of
167** the table.
168**
169** Normally, the error code conversion routine only supports the
170** languages "i-default" and "en", returning the error-table-provided
171** English description for both languages. The application may
172** provide a localization plugin, allowing support for additional
173** languages.
174**
175**/
176
177/**********************************************************************/
178/************************* TYPES AND CONSTANTS ************************/
179/**********************************************************************/
180
181/*
182 * PRLanguageCode --
183 *
184 * NSPR represents a language code as a non-negative integer.
185 * Languages 0 is always "i-default" the language you get without
186 * explicit negotiation. Language 1 is always "en", English
187 * which has been explicitly negotiated. Additional language
188 * codes are defined by an application-provided localization plugin.
189 */
190typedef PRUint32 PRLanguageCode;
191#define PR_LANGUAGE_I_DEFAULT 0 /* i-default, the default language */
192#define PR_LANGUAGE_EN 1 /* English, explicitly negotiated */
193
194/*
195 * struct PRErrorMessage --
196 *
197 * An error message in an error table.
198 */
199struct PRErrorMessage {
200 const char * name; /* Macro name for error */
201 const char * en_text; /* Default English text */
202};
203
204/*
205 * struct PRErrorTable --
206 *
207 * An error table, provided by a library.
208 */
209struct PRErrorTable {
210 const struct PRErrorMessage * msgs; /* Array of error information */
211 const char *name; /* Name of error table source */
212 PRErrorCode base; /* Error code for first error in table */
213 int n_msgs; /* Number of codes in table */
214};
215
216/*
217 * struct PRErrorCallbackPrivate --
218 *
219 * A private structure for the localization plugin
220 */
221struct PRErrorCallbackPrivate;
222
223/*
224 * struct PRErrorCallbackTablePrivate --
225 *
226 * A data structure under which the localization plugin may store information,
227 * associated with an error table, that is private to itself.
228 */
229struct PRErrorCallbackTablePrivate;
230
231/*
232 * PRErrorCallbackLookupFn --
233 *
234 * A function of PRErrorCallbackLookupFn type is a localization
235 * plugin callback which converts an error code into a description
236 * in the requested language. The callback is provided the
237 * appropriate error table, private data for the plugin and the table.
238 * The callback returns the appropriate UTF-8 encoded description, or NULL
239 * if no description can be found.
240 */
241typedef const char *
242PRErrorCallbackLookupFn(PRErrorCode code, PRLanguageCode language,
243 const struct PRErrorTable *table,
244 struct PRErrorCallbackPrivate *cb_private,
245 struct PRErrorCallbackTablePrivate *table_private);
246
247/*
248 * PRErrorCallbackNewTableFn --
249 *
250 * A function PRErrorCallbackNewTableFn type is a localization plugin
251 * callback which is called once with each error table registered
252 * with NSPR. The callback is provided with the error table and
253 * the plugin's private structure. The callback returns any table private
254 * data it wishes to associate with the error table. Does not need to be thread
255 * safe.
256 */
257typedef struct PRErrorCallbackTablePrivate *
258PRErrorCallbackNewTableFn(const struct PRErrorTable *table,
259 struct PRErrorCallbackPrivate *cb_private);
260
261/**********************************************************************/
262/****************************** FUNCTIONS *****************************/
263/**********************************************************************/
264
265/***********************************************************************
266** FUNCTION: PR_ErrorToString
267** DESCRIPTION:
268** Returns the UTF-8 message for an error code in
269** the requested language. May return the message
270** in the default language if a translation in the requested
271** language is not available. The returned string is
272** valid for the duration of the process. Never returns NULL.
273**
274***********************************************************************/
275NSPR_API(const char *) PR_ErrorToString(PRErrorCode code,
276 PRLanguageCode language);
277
278
279/***********************************************************************
280** FUNCTION: PR_ErrorToName
281** DESCRIPTION:
282** Returns the macro name for an error code, or NULL
283** if the error code is not known. The returned string is
284** valid for the duration of the process.
285**
286** Does not work for error table 0, the system error codes.
287**
288***********************************************************************/
289NSPR_API(const char *) PR_ErrorToName(PRErrorCode code);
290
291
292/***********************************************************************
293** FUNCTION: PR_ErrorLanguages
294** DESCRIPTION:
295** Returns the RFC 1766 language tags for the language
296** codes PR_ErrorToString() supports. The returned array is valid
297** for the duration of the process. Never returns NULL. The first
298** item in the returned array is the language tag for PRLanguageCode 0,
299** the second is for PRLanguageCode 1, and so on. The array is terminated
300** with a null pointer.
301**
302***********************************************************************/
303NSPR_API(const char * const *) PR_ErrorLanguages(void);
304
305
306/***********************************************************************
307** FUNCTION: PR_ErrorInstallTable
308** DESCRIPTION:
309** Registers an error table with NSPR. Must be done exactly once per
310** table. Memory pointed to by `table' must remain valid for the life
311** of the process.
312**
313** NOT THREAD SAFE!
314**
315***********************************************************************/
316NSPR_API(PRErrorCode) PR_ErrorInstallTable(const struct PRErrorTable *table);
317
318
319/***********************************************************************
320** FUNCTION: PR_ErrorInstallCallback
321** DESCRIPTION:
322** Registers an error localization plugin with NSPR. May be called
323** at most one time. `languages' contains the language codes supported
324** by this plugin. Languages 0 and 1 must be "i-default" and "en"
325** respectively. `lookup' and `newtable' contain pointers to
326** the plugin callback functions. `cb_private' contains any information
327** private to the plugin functions.
328**
329** NOT THREAD SAFE!
330**
331***********************************************************************/
332NSPR_API(void) PR_ErrorInstallCallback(const char * const * languages,
333 PRErrorCallbackLookupFn *lookup,
334 PRErrorCallbackNewTableFn *newtable,
335 struct PRErrorCallbackPrivate *cb_private);
336
337PR_END_EXTERN_C
338
339#endif /* prerror_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette