1 /* 2 libparted - a library for manipulating disk partitions 3 Copyright (C) 1999, 2000, 2007 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 extern char* ped_exception_get_option_string (PedExceptionOption ex_opt); 88 89 extern void ped_exception_set_handler (PedExceptionHandler* handler); 90 extern PedExceptionHandler *ped_exception_get_handler(void); 91 92 extern PedExceptionOption ped_exception_default_handler (PedException* ex); 93 94 extern PedExceptionOption ped_exception_throw (PedExceptionType ex_type, 95 PedExceptionOption ex_opt, 96 const char* message, 97 ...); 98 /* rethrows an exception - i.e. calls the exception handler, (or returns a 99 code to return to pass up higher) */ 100 extern PedExceptionOption ped_exception_rethrow (); 101 102 /* frees an exception, indicating that the exception has been handled. 103 Calling an exception handler counts. */ 104 extern void ped_exception_catch (); 105 106 /* indicate that exceptions should not go to the exception handler, but passed 107 up to the calling function(s) */ 108 extern void ped_exception_fetch_all (); 109 110 /* indicate that exceptions should invoke the exception handler */ 111 extern void ped_exception_leave_all (); 112 113 #endif /* PED_EXCEPTION_H_INCLUDED */ 114 115 /** @} */ 116