00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef PMError_h
00022 #define PMError_h
00023
00024 #include <iosfwd>
00025
00026 #include <y2util/stringutil.h>
00027
00029
00030
00139 class PMError {
00140
00141 static const unsigned _valrange = 0x400;
00142 static const unsigned _valmask = _valrange-1;
00143 static const unsigned _repmask = ~_valmask;
00144
00145 static const std::string errstrPrefix;
00146
00147 static std::string defaulterrstr( const std::string & cl, const std::string & txt );
00148
00149 public:
00150
00151 static const unsigned E_ok = 0;
00152 static const unsigned E_error = 1;
00153 static const std::string OKstring;
00154 static const std::string ERRORstring;
00155
00156 enum ErrClass {
00157 C_Error = 0,
00158
00159
00160 C_InstSrcError = 10*_valrange,
00161 C_MediaError = 11*_valrange,
00162 C_InstTargetError = 12*_valrange,
00163 C_YouError = 14*_valrange,
00164 C_ModulePkgError = 15*_valrange
00165 };
00166
00167 enum Error {
00168
00169 E_TBD = C_Error+1
00170 };
00171
00172 unsigned _errval;
00173
00174 std::string _errdetails;
00175
00176 public:
00177
00181 PMError( const unsigned e = E_ok ) { _errval = e; }
00182
00186 PMError( const unsigned e, const std::string & details )
00187 {
00188 _errval = e;
00189 _errdetails = details;
00190 }
00191
00195 operator unsigned() const { return _errval; }
00196
00200 static std::string errstr( const unsigned e );
00201
00205 std::string errstr() const { return errstr( _errval ); }
00206
00210 static ErrClass errClass( const unsigned e );
00211
00215 ErrClass errClass() const { return errClass( _errval ); }
00216
00220 void addDetails( const std::string & );
00221
00225 void setDetails( const std::string & details ) { _errdetails = details; }
00226
00230 std::string details() const { return _errdetails; }
00231
00235 std::string asString() const;
00236
00240 friend std::ostream & operator<<( std::ostream & str, const PMError & obj );
00241 };
00242
00244
00245 #if 0 //draft
00246 class PMError
00247 {
00248 public:
00249 enum Serverity
00250 {
00251 None = 0,
00252 Normal,
00253 Grave,
00254 Fatal
00255 };
00256
00261 enum SuggestedAction
00262 {
00263 Continue = 0,
00264 Retry,
00265 Fail
00266 };
00267
00272 enum PossibleAction
00273 {
00274 Continue = 1,
00275 Retry = 2,
00276 Fail = 4
00277 };
00278
00279 public:
00289 PMError(
00290 const std::string& reporter,
00291 enum Severity s = None,
00292 const std::string& message = "",
00293 unsigned possibleAction = Continue,
00294 enum SuggestedAction a = Continue
00295 );
00296
00302 PMError(
00303 const std::string& reporter,
00304 enum Severity s = None,
00305 int errnoval,
00306 unsigned possibleAction = Continue,
00307 enum SuggestedAction a = Continue
00308 );
00309
00314 void setDescription(const std::string& descr);
00315
00319 void setAskUserFunc(bool (*callbac)(const PMError&));
00320
00321
00327 enum SuggestedAction askUser();
00328
00329
00330 enum Severity getSeverity() const;
00331
00332 enum SuggestedAction getSuggestedAction() const;
00333
00334 unsigned getPossibleAction() const;
00335
00336 bool isActionPossible(enum PossibleAction a) const;
00337
00338 const std::string& getMessage() const;
00339
00340 const std::string& getDescription() const;
00341
00342 int getErrno() const;
00343
00344 private:
00345
00346 std::string _reporter;
00347
00348 enum Severity _severity;
00349
00350 std::string _message;
00351
00352 int _errno;
00353
00354 enum SuggestedAction _suggestedAction;
00355
00356 unsigned _possibleAction;
00357
00358 std::string _description;
00359
00360 bool (*_askuserfunc)(const PMError&);
00361 };
00362 #endif
00363
00364 #endif // PMError_h