- one more fix - having a reference as exception data is probably not a
[platform/upstream/libzypp.git] / zypp / media / MediaException.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaException.h
10  *
11 */
12 #ifndef ZYPP_MEDIA_MEDIAEXCEPTION_H
13 #define ZYPP_MEDIA_MEDIAEXCEPTION_H
14
15 #include <iosfwd>
16
17 #include <string>
18 #include <vector>
19
20 #include "zypp/base/Exception.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/Url.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27   namespace media {
28     ///////////////////////////////////////////////////////////////
29     //
30     //  CLASS NAME : MediaException
31     /** Just inherits Exception to separate media exceptions
32      *
33      **/
34     class MediaException : public Exception
35     {
36     public:
37       /** Ctor taking message.
38        * Use \ref ZYPP_THROW to throw exceptions.
39       */
40       MediaException() : Exception( "Media Exception" ), _dev_current(0)
41       {}
42       /** Ctor taking message.
43        * Use \ref ZYPP_THROW to throw exceptions.
44       */
45       MediaException( const std::string & msg_r )
46       : Exception( msg_r ), _dev_current(0)
47       {}
48
49       /**
50        * Ctor taking the message and detected device list (e.g. for ejecting).
51        * \param msg_r
52        * \param devices    list of available devices as vector
53        * \param devCurrent index of the currently used device in the \a devices vector
54        */
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)
59       {}
60
61       const std::vector<std::string> & devices() const { return _devices; }
62       unsigned int deviceCurrent() const { return _dev_current; }
63
64       /** Dtor. */
65       virtual ~MediaException() throw() {};
66
67 //    private:
68 //      void operator = (const MediaException & ex) {}
69     private:
70       std::vector<std::string> _devices;
71       unsigned int _dev_current;
72     };
73
74     class MediaMountException : public MediaException
75     {
76     public:
77       MediaMountException()
78       : MediaException( "Media Mount Exception" )
79       {}
80
81       /** Ctor taking message.
82        * Use \ref ZYPP_THROW to throw exceptions.
83       */
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="")
88       : MediaException()
89       , _error(error_r)
90       , _source(source_r)
91       , _target(target_r)
92       , _cmdout(cmdout_r)
93       {}
94       /** Dtor. */
95       virtual ~MediaMountException() throw() {};
96
97       const std::string & mountError() const
98       { return _error;  }
99       const std::string & mountSource() const
100       { return _source; }
101       const std::string & mountTarget() const
102       { return _target; }
103       const std::string & mountOutput() const
104       { return _cmdout; }
105
106     protected:
107       virtual std::ostream & dumpOn( std::ostream & str ) const;
108     private:
109       std::string _error;
110       std::string _source;
111       std::string _target;
112       std::string _cmdout;
113     };
114
115     class MediaUnmountException : public MediaException
116     {
117     public:
118       /** Ctor taking message.
119        * Use \ref ZYPP_THROW to throw exceptions.
120       */
121       MediaUnmountException( const std::string & error_r,
122                              const std::string & path_r )
123       : MediaException()
124       , _error(error_r)
125       , _path(path_r)
126       {}
127       /** Dtor. */
128       virtual ~MediaUnmountException() throw() {};
129     protected:
130       virtual std::ostream & dumpOn( std::ostream & str ) const;
131     private:
132       std::string _error;
133       std::string _path;
134     };
135
136     class MediaBadFilenameException : public MediaException
137     {
138     public:
139       MediaBadFilenameException(const std::string & filename_r)
140       : MediaException()
141       , _filename(filename_r)
142       {}
143       virtual ~MediaBadFilenameException() throw() {};
144       std::string filename() const { return _filename; }
145     protected:
146       virtual std::ostream & dumpOn( std::ostream & str ) const;
147     private:
148       std::string _filename;
149     };
150
151     class MediaNotOpenException : public MediaException
152     {
153     public:
154       MediaNotOpenException(const std::string & action_r)
155       : MediaException()
156       , _action(action_r)
157       {}
158       virtual ~MediaNotOpenException() throw() {};
159     protected:
160       virtual std::ostream & dumpOn( std::ostream & str ) const;
161     private:
162       std::string _action;
163     };
164
165     class MediaFileNotFoundException : public MediaException
166     {
167     public:
168       MediaFileNotFoundException(const Url & url_r,
169                                  const Pathname & filename_r)
170       : MediaException()
171       , _url(url_r.asString())
172       , _filename(filename_r.asString())
173       {}
174       virtual ~MediaFileNotFoundException() throw() {};
175     protected:
176       virtual std::ostream & dumpOn( std::ostream & str ) const;
177     private:
178       std::string _url;
179       std::string _filename;
180     };
181
182     class MediaWriteException : public MediaException
183     {
184     public:
185       MediaWriteException(const Pathname & filename_r)
186       : MediaException()
187       , _filename(filename_r.asString())
188       {}
189       virtual ~MediaWriteException() throw() {};
190     protected:
191       virtual std::ostream & dumpOn( std::ostream & str ) const;
192     private:
193       std::string _filename;
194     };
195
196     class MediaNotAttachedException : public MediaException
197     {
198     public:
199       MediaNotAttachedException(const Url & url_r)
200       : MediaException()
201       , _url(url_r.asString())
202       {}
203       virtual ~MediaNotAttachedException() throw() {};
204     protected:
205       virtual std::ostream & dumpOn( std::ostream & str ) const;
206     private:
207       std::string _url;
208     };
209
210     class MediaBadAttachPointException : public MediaException
211     {
212     public:
213       MediaBadAttachPointException(const Url & url_r)
214       : MediaException()
215       , _url(url_r.asString())
216       {}
217       virtual ~MediaBadAttachPointException() throw() {};
218     protected:
219       virtual std::ostream & dumpOn( std::ostream & str ) const;
220     private:
221       std::string _url;
222     };
223
224     class MediaCurlInitException : public MediaException
225     {
226     public:
227       MediaCurlInitException(const Url & url_r)
228       : MediaException()
229       , _url(url_r.asString())
230       {}
231       virtual ~MediaCurlInitException() throw() {};
232     protected:
233       virtual std::ostream & dumpOn( std::ostream & str ) const;
234     private:
235       std::string _url;
236     };
237
238     class MediaSystemException : public MediaException
239     {
240     public:
241       MediaSystemException(const Url & url_r,
242                            const std::string & message_r)
243       : MediaException()
244       , _url(url_r.asString())
245       , _message(message_r)
246       {}
247       virtual ~MediaSystemException() throw() {};
248     protected:
249       virtual std::ostream & dumpOn( std::ostream & str ) const;
250     private:
251       std::string _url;
252       std::string _message;
253     };
254
255     class MediaNotAFileException : public MediaException
256     {
257     public:
258       MediaNotAFileException(const Url & url_r,
259                              const Pathname & path_r)
260       : MediaException()
261       , _url(url_r.asString())
262       , _path(path_r.asString())
263       {}
264       virtual ~MediaNotAFileException() throw() {};
265     protected:
266       virtual std::ostream & dumpOn( std::ostream & str ) const;
267     private:
268       std::string _url;
269       std::string _path;
270     };
271
272     class MediaNotADirException : public MediaException
273     {
274     public:
275       MediaNotADirException(const Url & url_r,
276                             const Pathname & path_r)
277       : MediaException()
278       , _url(url_r.asString())
279       , _path(path_r.asString())
280       {}
281       virtual ~MediaNotADirException() throw() {};
282     protected:
283       virtual std::ostream & dumpOn( std::ostream & str ) const;
284     private:
285       std::string _url;
286       std::string _path;
287     };
288
289     class MediaBadUrlException : public MediaException
290     {
291     public:
292       MediaBadUrlException(const Url & url_r,
293                            const std::string &msg_r = std::string())
294       : MediaException()
295       , _url(url_r.asString())
296       , _msg(msg_r)
297       {}
298       virtual ~MediaBadUrlException() throw() {};
299     protected:
300       virtual std::ostream & dumpOn( std::ostream & str ) const;
301       std::string _url;
302       std::string _msg;
303     };
304
305     class MediaBadUrlEmptyHostException : public MediaBadUrlException
306     {
307     public:
308       MediaBadUrlEmptyHostException(const Url & url_r)
309       : MediaBadUrlException(url_r)
310       {}
311       virtual ~MediaBadUrlEmptyHostException() throw() {};
312     protected:
313       virtual std::ostream & dumpOn( std::ostream & str ) const;
314     };
315
316     class MediaBadUrlEmptyFilesystemException : public MediaBadUrlException
317     {
318     public:
319       MediaBadUrlEmptyFilesystemException(const Url & url_r)
320       : MediaBadUrlException(url_r)
321       {}
322       virtual ~MediaBadUrlEmptyFilesystemException() throw() {};
323     protected:
324       virtual std::ostream & dumpOn( std::ostream & str ) const;
325     };
326
327     class MediaBadUrlEmptyDestinationException : public MediaBadUrlException
328     {
329     public:
330       MediaBadUrlEmptyDestinationException(const Url & url_r)
331       : MediaBadUrlException(url_r)
332       {}
333       virtual ~MediaBadUrlEmptyDestinationException() throw() {};
334     protected:
335       virtual std::ostream & dumpOn( std::ostream & str ) const;
336     };
337
338     class MediaUnsupportedUrlSchemeException : public MediaBadUrlException
339     {
340     public:
341       MediaUnsupportedUrlSchemeException(const Url & url_r)
342       : MediaBadUrlException(url_r)
343       {}
344       virtual ~MediaUnsupportedUrlSchemeException() throw() {};
345     protected:
346       virtual std::ostream & dumpOn( std::ostream & str ) const;
347     };
348
349     class MediaNotSupportedException : public MediaException
350     {
351     public:
352       MediaNotSupportedException(const Url & url_r)
353       : MediaException()
354       , _url(url_r.asString())
355       {}
356       virtual ~MediaNotSupportedException() throw() {};
357     protected:
358       virtual std::ostream & dumpOn( std::ostream & str ) const;
359       std::string _url;
360     };
361
362     class MediaCurlException : public MediaException
363     {
364     public:
365       MediaCurlException(const Url & url_r,
366                          const std::string & err_r,
367                          const std::string & msg_r)
368       : MediaException()
369       , _url(url_r.asString())
370       , _err(err_r)
371       , _msg(msg_r)
372       {}
373       virtual ~MediaCurlException() throw() {};
374     protected:
375       virtual std::ostream & dumpOn( std::ostream & str ) const;
376       std::string _url;
377       std::string _err;
378       std::string _msg;
379     };
380
381     class MediaCurlSetOptException : public MediaException
382     {
383     public:
384       MediaCurlSetOptException(const Url & url_r, const std::string & msg_r)
385       : MediaException()
386       , _url(url_r.asString())
387       , _msg(msg_r)
388       {}
389       virtual ~MediaCurlSetOptException() throw() {};
390     protected:
391       virtual std::ostream & dumpOn( std::ostream & str ) const;
392       std::string _url;
393       std::string _msg;
394     };
395
396     class MediaNotDesiredException : public MediaException
397     {
398     public:
399       MediaNotDesiredException(const Url & url_r)
400       : MediaException()
401       , _url(url_r.asString())
402       {}
403       virtual ~MediaNotDesiredException() throw() {};
404     protected:
405       virtual std::ostream & dumpOn( std::ostream & str ) const;
406     private:
407       std::string  _url;
408     };
409
410     class MediaIsSharedException : public MediaException
411     {
412     public:
413       /**
414        * \param name A media source as string (see MediaSource class).
415        */
416       MediaIsSharedException(const std::string &name)
417       : MediaException()
418       , _name(name)
419       {}
420       virtual ~MediaIsSharedException() throw() {};
421     protected:
422       virtual std::ostream & dumpOn( std::ostream & str ) const;
423     private:
424       std::string _name;
425     };
426
427     class MediaNotEjectedException: public MediaException
428     {
429     public:
430       MediaNotEjectedException()
431       : MediaException("Can't eject any media")
432       , _name("")
433       {}
434
435       MediaNotEjectedException(const std::string &name)
436       : MediaException("Can't eject media")
437       , _name(name)
438       {}
439       virtual ~MediaNotEjectedException() throw() {};
440     protected:
441       virtual std::ostream & dumpOn( std::ostream & str ) const;
442     private:
443       std::string _name;
444     };
445
446     class MediaUnauthorizedException: public MediaException
447     {
448     public:
449       MediaUnauthorizedException()
450       : MediaException("Unauthorized media access")
451       , _url("")
452       , _err("")
453       , _hint("")
454       {}
455
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)
461       , _url(url_r)
462       , _err(err_r)
463       , _hint(hint_r)
464       {}
465
466       virtual ~MediaUnauthorizedException() throw() {};
467
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; }
472
473     protected:
474       virtual std::ostream & dumpOn( std::ostream & str ) const;
475     private:
476       Url         _url;
477       std::string _err;
478       std::string _hint;
479     };
480
481     class MediaForbiddenException : public MediaException
482     {
483     public:
484       MediaForbiddenException(const Url & url_r, const std::string & msg = "")
485       : MediaException(msg)
486       , _url(url_r.asString()), _msg(msg)
487       {}
488       virtual ~MediaForbiddenException() throw() {};
489     protected:
490       virtual std::ostream & dumpOn( std::ostream & str ) const;
491       std::string _url;
492       std::string _msg;
493     };
494
495   /////////////////////////////////////////////////////////////////
496   } // namespace media
497 } // namespace zypp
498 ///////////////////////////////////////////////////////////////////
499 #endif // ZYPP_MEDIA_MEDIAEXCEPTION_H