~youscribe/parted/3.1

« back to all changes in this revision

Viewing changes to include/parted/exception.h

  • Committer: Guilhem Lettron
  • Date: 2012-10-22 14:37:59 UTC
  • Revision ID: guilhem+ubuntu@lettron.fr-20121022143759-m403kecgz13sknvp
3.1 from tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    libparted - a library for manipulating disk partitions
 
3
    Copyright (C) 1999-2000, 2007, 2009-2012 Free Software Foundation, Inc.
 
4
 
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 3 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
/**
 
20
 * \addtogroup PedException
 
21
 * @{
 
22
 */
 
23
 
 
24
/** \file exception.h */
 
25
 
 
26
#ifndef PED_EXCEPTION_H_INCLUDED
 
27
#define PED_EXCEPTION_H_INCLUDED
 
28
 
 
29
typedef struct _PedException PedException;
 
30
 
 
31
/**
 
32
 * Exception type
 
33
 */
 
34
enum _PedExceptionType {
 
35
        PED_EXCEPTION_INFORMATION=1,
 
36
        PED_EXCEPTION_WARNING=2,
 
37
        PED_EXCEPTION_ERROR=3,
 
38
        PED_EXCEPTION_FATAL=4,
 
39
        PED_EXCEPTION_BUG=5,
 
40
        PED_EXCEPTION_NO_FEATURE=6,
 
41
};
 
42
typedef enum _PedExceptionType PedExceptionType;
 
43
 
 
44
/**
 
45
 * Option for resolving the exception
 
46
 */
 
47
enum _PedExceptionOption {
 
48
        PED_EXCEPTION_UNHANDLED=0,
 
49
        PED_EXCEPTION_FIX=1,
 
50
        PED_EXCEPTION_YES=2,
 
51
        PED_EXCEPTION_NO=4,
 
52
        PED_EXCEPTION_OK=8,
 
53
        PED_EXCEPTION_RETRY=16,
 
54
        PED_EXCEPTION_IGNORE=32,
 
55
        PED_EXCEPTION_CANCEL=64,
 
56
};
 
57
typedef enum _PedExceptionOption PedExceptionOption;
 
58
#define PED_EXCEPTION_OK_CANCEL     (PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL)
 
59
#define PED_EXCEPTION_YES_NO        (PED_EXCEPTION_YES + PED_EXCEPTION_NO)
 
60
#define PED_EXCEPTION_YES_NO_CANCEL (PED_EXCEPTION_YES_NO \
 
61
                                     + PED_EXCEPTION_CANCEL)
 
62
#define PED_EXCEPTION_IGNORE_CANCEL (PED_EXCEPTION_IGNORE \
 
63
                                     + PED_EXCEPTION_CANCEL)
 
64
#define PED_EXCEPTION_RETRY_CANCEL  (PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL)
 
65
#define PED_EXCEPTION_RETRY_IGNORE_CANCEL (PED_EXCEPTION_RETRY \
 
66
                                           + PED_EXCEPTION_IGNORE_CANCEL)
 
67
#define PED_EXCEPTION_OPTION_FIRST PED_EXCEPTION_FIX
 
68
#define PED_EXCEPTION_OPTION_LAST PED_EXCEPTION_CANCEL
 
69
 
 
70
/**
 
71
 * Structure with information about exception
 
72
 */
 
73
struct _PedException {
 
74
        char*                   message;        /**< text describing what the event was */
 
75
        PedExceptionType        type;           /**< type of exception */
 
76
        PedExceptionOption      options;        /**< ORed list of options that
 
77
                                                   the exception handler can
 
78
                                                   return (the ways an exception
 
79
                                                   can be resolved) */
 
80
};
 
81
 
 
82
typedef PedExceptionOption (PedExceptionHandler) (PedException* ex);
 
83
 
 
84
extern int ped_exception;       /* set to true if there's an exception */
 
85
 
 
86
extern char* ped_exception_get_type_string (PedExceptionType ex_type)
 
87
    
 
88
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 
89
  __attribute ((__const__))
 
90
#endif
 
91
;
 
92
extern char* ped_exception_get_option_string (PedExceptionOption ex_opt)
 
93
    
 
94
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 
95
  __attribute ((__pure__))
 
96
#endif
 
97
;
 
98
 
 
99
extern void ped_exception_set_handler (PedExceptionHandler* handler);
 
100
extern PedExceptionHandler *ped_exception_get_handler(void)
 
101
    
 
102
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
 
103
  __attribute ((__pure__))
 
104
#endif
 
105
;
 
106
 
 
107
extern PedExceptionOption ped_exception_default_handler (PedException* ex);
 
108
 
 
109
extern PedExceptionOption       ped_exception_throw (PedExceptionType ex_type,
 
110
                                                     PedExceptionOption ex_opt,
 
111
                                                     const char* message,
 
112
                                                     ...);
 
113
/* rethrows an exception - i.e. calls the exception handler, (or returns a
 
114
   code to return to pass up higher) */
 
115
extern PedExceptionOption       ped_exception_rethrow ();
 
116
 
 
117
/* frees an exception, indicating that the exception has been handled.
 
118
   Calling an exception handler counts. */
 
119
extern void                     ped_exception_catch ();
 
120
 
 
121
/* indicate that exceptions should not go to the exception handler, but passed
 
122
   up to the calling function(s) */
 
123
extern void                     ped_exception_fetch_all ();
 
124
 
 
125
/* indicate that exceptions should invoke the exception handler */
 
126
extern void                     ped_exception_leave_all ();
 
127
 
 
128
#endif /* PED_EXCEPTION_H_INCLUDED */
 
129
 
 
130
/** @} */