1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaException.h
12 #ifndef ZYPP_MEDIA_MEDIAEXCEPTION_H
13 #define ZYPP_MEDIA_MEDIAEXCEPTION_H
20 #include "zypp/base/Exception.h"
21 #include "zypp/Pathname.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////
30 // CLASS NAME : MediaException
31 /** Just inherits Exception to separate media exceptions
34 class MediaException : public Exception
37 /** Ctor taking message.
38 * Use \ref ZYPP_THROW to throw exceptions.
40 MediaException() : Exception( "Media Exception" ), _dev_current(0)
42 /** Ctor taking message.
43 * Use \ref ZYPP_THROW to throw exceptions.
45 MediaException( const std::string & msg_r )
46 : Exception( msg_r ), _dev_current(0)
50 * Ctor taking the message and detected device list (e.g. for ejecting).
52 * \param devices list of available devices as vector
53 * \param devCurrent index of the currently used device in the \a devices vector
55 MediaException( const std::string & msg_r,
56 const std::vector<std::string> & devices,
57 unsigned int devCurrent)
58 : Exception( msg_r ), _devices(devices), _dev_current(devCurrent)
61 const std::vector<std::string> & devices() const { return _devices; }
62 unsigned int deviceCurrent() const { return _dev_current; }
65 virtual ~MediaException() throw() {};
68 // void operator = (const MediaException & ex) {}
70 std::vector<std::string> _devices;
71 unsigned int _dev_current;
74 class MediaMountException : public MediaException
78 : MediaException( "Media Mount Exception" )
81 /** Ctor taking message.
82 * Use \ref ZYPP_THROW to throw exceptions.
84 MediaMountException( const std::string & error_r,
85 const std::string & source_r,
86 const std::string & target_r,
87 const std::string & cmdout_r="")
95 virtual ~MediaMountException() throw() {};
97 const std::string & mountError() const
99 const std::string & mountSource() const
101 const std::string & mountTarget() const
103 const std::string & mountOutput() const
107 virtual std::ostream & dumpOn( std::ostream & str ) const;
115 class MediaUnmountException : public MediaException
118 /** Ctor taking message.
119 * Use \ref ZYPP_THROW to throw exceptions.
121 MediaUnmountException( const std::string & error_r,
122 const std::string & path_r )
128 virtual ~MediaUnmountException() throw() {};
130 virtual std::ostream & dumpOn( std::ostream & str ) const;
136 class MediaBadFilenameException : public MediaException
139 MediaBadFilenameException(const std::string & filename_r)
141 , _filename(filename_r)
143 virtual ~MediaBadFilenameException() throw() {};
144 std::string filename() const { return _filename; }
146 virtual std::ostream & dumpOn( std::ostream & str ) const;
148 std::string _filename;
151 class MediaNotOpenException : public MediaException
154 MediaNotOpenException(const std::string & action_r)
158 virtual ~MediaNotOpenException() throw() {};
160 virtual std::ostream & dumpOn( std::ostream & str ) const;
165 class MediaFileNotFoundException : public MediaException
168 MediaFileNotFoundException(const Url & url_r,
169 const Pathname & filename_r)
171 , _url(url_r.asString())
172 , _filename(filename_r.asString())
174 virtual ~MediaFileNotFoundException() throw() {};
176 virtual std::ostream & dumpOn( std::ostream & str ) const;
179 std::string _filename;
182 class MediaWriteException : public MediaException
185 MediaWriteException(const Pathname & filename_r)
187 , _filename(filename_r.asString())
189 virtual ~MediaWriteException() throw() {};
191 virtual std::ostream & dumpOn( std::ostream & str ) const;
193 std::string _filename;
196 class MediaNotAttachedException : public MediaException
199 MediaNotAttachedException(const Url & url_r)
201 , _url(url_r.asString())
203 virtual ~MediaNotAttachedException() throw() {};
205 virtual std::ostream & dumpOn( std::ostream & str ) const;
210 class MediaBadAttachPointException : public MediaException
213 MediaBadAttachPointException(const Url & url_r)
215 , _url(url_r.asString())
217 virtual ~MediaBadAttachPointException() throw() {};
219 virtual std::ostream & dumpOn( std::ostream & str ) const;
224 class MediaCurlInitException : public MediaException
227 MediaCurlInitException(const Url & url_r)
229 , _url(url_r.asString())
231 virtual ~MediaCurlInitException() throw() {};
233 virtual std::ostream & dumpOn( std::ostream & str ) const;
238 class MediaSystemException : public MediaException
241 MediaSystemException(const Url & url_r,
242 const std::string & message_r)
244 , _url(url_r.asString())
245 , _message(message_r)
247 virtual ~MediaSystemException() throw() {};
249 virtual std::ostream & dumpOn( std::ostream & str ) const;
252 std::string _message;
255 class MediaNotAFileException : public MediaException
258 MediaNotAFileException(const Url & url_r,
259 const Pathname & path_r)
261 , _url(url_r.asString())
262 , _path(path_r.asString())
264 virtual ~MediaNotAFileException() throw() {};
266 virtual std::ostream & dumpOn( std::ostream & str ) const;
272 class MediaNotADirException : public MediaException
275 MediaNotADirException(const Url & url_r,
276 const Pathname & path_r)
278 , _url(url_r.asString())
279 , _path(path_r.asString())
281 virtual ~MediaNotADirException() throw() {};
283 virtual std::ostream & dumpOn( std::ostream & str ) const;
289 class MediaBadUrlException : public MediaException
292 MediaBadUrlException(const Url & url_r,
293 const std::string &msg_r = std::string())
295 , _url(url_r.asString())
298 virtual ~MediaBadUrlException() throw() {};
300 virtual std::ostream & dumpOn( std::ostream & str ) const;
305 class MediaBadUrlEmptyHostException : public MediaBadUrlException
308 MediaBadUrlEmptyHostException(const Url & url_r)
309 : MediaBadUrlException(url_r)
311 virtual ~MediaBadUrlEmptyHostException() throw() {};
313 virtual std::ostream & dumpOn( std::ostream & str ) const;
316 class MediaBadUrlEmptyFilesystemException : public MediaBadUrlException
319 MediaBadUrlEmptyFilesystemException(const Url & url_r)
320 : MediaBadUrlException(url_r)
322 virtual ~MediaBadUrlEmptyFilesystemException() throw() {};
324 virtual std::ostream & dumpOn( std::ostream & str ) const;
327 class MediaBadUrlEmptyDestinationException : public MediaBadUrlException
330 MediaBadUrlEmptyDestinationException(const Url & url_r)
331 : MediaBadUrlException(url_r)
333 virtual ~MediaBadUrlEmptyDestinationException() throw() {};
335 virtual std::ostream & dumpOn( std::ostream & str ) const;
338 class MediaUnsupportedUrlSchemeException : public MediaBadUrlException
341 MediaUnsupportedUrlSchemeException(const Url & url_r)
342 : MediaBadUrlException(url_r)
344 virtual ~MediaUnsupportedUrlSchemeException() throw() {};
346 virtual std::ostream & dumpOn( std::ostream & str ) const;
349 class MediaNotSupportedException : public MediaException
352 MediaNotSupportedException(const Url & url_r)
354 , _url(url_r.asString())
356 virtual ~MediaNotSupportedException() throw() {};
358 virtual std::ostream & dumpOn( std::ostream & str ) const;
362 class MediaCurlException : public MediaException
365 MediaCurlException(const Url & url_r,
366 const std::string & err_r,
367 const std::string & msg_r)
369 , _url(url_r.asString())
373 virtual ~MediaCurlException() throw() {};
375 virtual std::ostream & dumpOn( std::ostream & str ) const;
381 class MediaCurlSetOptException : public MediaException
384 MediaCurlSetOptException(const Url & url_r, const std::string & msg_r)
386 , _url(url_r.asString())
389 virtual ~MediaCurlSetOptException() throw() {};
391 virtual std::ostream & dumpOn( std::ostream & str ) const;
396 class MediaNotDesiredException : public MediaException
399 MediaNotDesiredException(const Url & url_r)
401 , _url(url_r.asString())
403 virtual ~MediaNotDesiredException() throw() {};
405 virtual std::ostream & dumpOn( std::ostream & str ) const;
410 class MediaIsSharedException : public MediaException
414 * \param name A media source as string (see MediaSource class).
416 MediaIsSharedException(const std::string &name)
420 virtual ~MediaIsSharedException() throw() {};
422 virtual std::ostream & dumpOn( std::ostream & str ) const;
427 class MediaNotEjectedException: public MediaException
430 MediaNotEjectedException()
431 : MediaException("Can't eject any media")
435 MediaNotEjectedException(const std::string &name)
436 : MediaException("Can't eject media")
439 virtual ~MediaNotEjectedException() throw() {};
441 virtual std::ostream & dumpOn( std::ostream & str ) const;
446 class MediaUnauthorizedException: public MediaException
449 MediaUnauthorizedException()
450 : MediaException("Unauthorized media access")
456 MediaUnauthorizedException(const Url &url_r,
457 const std::string &msg_r,
458 const std::string &err_r,
459 const std::string &hint_r)
460 : MediaException(msg_r)
466 virtual ~MediaUnauthorizedException() throw() {};
468 const Url & url() const { return _url; }
469 const std::string & err() const { return _err; }
470 /** comma separated list of available authentication types */
471 const std::string & hint() const { return _hint; }
474 virtual std::ostream & dumpOn( std::ostream & str ) const;
481 class MediaForbiddenException : public MediaException
484 MediaForbiddenException(const Url & url_r, const std::string & msg = "")
485 : MediaException(msg)
486 , _url(url_r.asString()), _msg(msg)
488 virtual ~MediaForbiddenException() throw() {};
490 virtual std::ostream & dumpOn( std::ostream & str ) const;
495 /////////////////////////////////////////////////////////////////
498 ///////////////////////////////////////////////////////////////////
499 #endif // ZYPP_MEDIA_MEDIAEXCEPTION_H