libzypp 17.25.7
MediaAccess.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_MEDIA_MEDIAACCESS_H
13#define ZYPP_MEDIA_MEDIAACCESS_H
14
15#include <iosfwd>
16#include <map>
17#include <list>
18#include <string>
19
22#include <zypp/base/PtrTypes.h>
23#include <zypp/APIConfig.h>
24
25#include <zypp/Pathname.h>
26#include <zypp/PathInfo.h>
27
30
31#include <zypp/Url.h>
32
33namespace zypp {
34 namespace media {
35
36 class MediaHandler;
37
39 //
40 // CLASS NAME : MediaAccess
51 {
52 public:
53 typedef intrusive_ptr<MediaAccess> Ptr;
54 typedef intrusive_ptr<const MediaAccess> constPtr;
55
56 private:
57
58 static const Pathname _noPath;
59
65
66 friend class MediaManager;
67 friend class MediaManager_Impl;
68
70
71 bool isSharedMedia() const;
72
73 void resetParentId();
74 bool dependsOnParent() const;
75
76 bool dependsOnParent(MediaAccessId parentId,
77 bool exactIdMatch) const;
78 public:
79
84
95 void open( const Url& url, const Pathname & preferred_attach_point = "" );
96
100 bool isOpen() const { return( _handler != 0 ); }
101
106 bool downloads() const;
107
111 std::string protocol() const;
112
116 Url url() const;
117
124 void close();
125
126 public:
127
138 void attach(bool next = false);
139
146 bool isAttached() const;
147
148 bool hasMoreDevices() const;
149
158 virtual void
159 getDetectedDevices(std::vector<std::string> & devices,
160 unsigned int & index) const;
161
162
171 Pathname localRoot() const;
172
179 Pathname localPath( const Pathname & pathname ) const;
180
194 void disconnect();
195
203 void release( const std::string & ejectDev = "" );
204
222 void provideFile( const Pathname & filename, const ByteCount &expectedFileSize ) const;
223
231 void releaseFile( const Pathname & filename ) const;
232
242 void provideDir( const Pathname & dirname ) const;
243
253 void provideDirTree( const Pathname & dirname ) const;
254
262 void releaseDir( const Pathname & dirname ) const;
263
275 void releasePath( const Pathname & pathname ) const;
276
280 void setDeltafile( const Pathname & filename ) const;
281
282 public:
283
297 void dirInfo( std::list<std::string> & retlist,
298 const Pathname & dirname, bool dots = true ) const;
299
312 void dirInfo( filesystem::DirContent & retlist,
313 const Pathname & dirname, bool dots = true ) const;
314
323 bool doesFileExist( const Pathname & filename ) const;
324
328 virtual ~MediaAccess();
329
330 public:
331
332 virtual std::ostream & dumpOn( std::ostream & str ) const;
333
334 public:
345 void getFile( const Url &from, const Pathname &to );
346
347 public:
348
370 FileProvider( const FileProvider & ); // no copy
371 FileProvider & operator=( const FileProvider & ); // no assign
372 private:
376 public:
380 FileProvider( MediaAccess::constPtr media_r, const Pathname & file_r )
381 : _media( media_r )
382 , _file( file_r )
383 , _local_file( "" )
384 {
385 if ( _file.empty() ) {
387 } else if ( _media ) {
388 try {
389 _media->provideFile( _file, 0 );
390 _local_file = _media->localPath( _file );
391 }
392 catch (const MediaException & excpt_r)
393 {
394 ZYPP_CAUGHT(excpt_r);
395 _media = NULL;
396 ZYPP_RETHROW(excpt_r);
397 }
398 }
399 }
400
402 if ( _media )
403 {
404 try {
405 _media->releaseFile( _file );
406 }
407 catch (const MediaException &excpt_r)
408 {
409 ZYPP_CAUGHT(excpt_r);
410 }
411 catch(...) {} // No exception from dtor!
412 }
413 }
414
415 public:
416
421 Pathname localFile() const { return _local_file; }
422
428 if ( _media )
429 return _media->localPath( _file );
430 return Pathname();
431 }
432 };
433 };
434
435 std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
436
438
439 } // namespace media
440} // namespace zypp
441
442#endif // ZYPP_MEDIA_MEDIAACCESS_H
443
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:400
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
Store and operate with byte count.
Definition: ByteCount.h:31
Url manipulation class.
Definition: Url.h:92
Base class for reference counted objects.
const std::string & asString() const
String representation.
Definition: Pathname.h:91
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
Helper class that provides file on construction and cleans up on destruction.
Definition: MediaAccess.h:369
Pathname operator()() const
Return the local Pathname of the provided file or an empty Pathname on error.
Definition: MediaAccess.h:427
Pathname localFile() const
If no error, expect operator() to return the local Pathname of the provided file.
Definition: MediaAccess.h:421
FileProvider(MediaAccess::constPtr media_r, const Pathname &file_r)
Definition: MediaAccess.h:380
FileProvider & operator=(const FileProvider &)
Handle access to a medium.
Definition: MediaAccess.h:51
void getFile(const Url &from, const Pathname &to)
Get file from location at specified by URL and copy it to destination.
Definition: MediaAccess.cc:456
bool isOpen() const
True if media is open.
Definition: MediaAccess.h:100
Pathname localPath(const Pathname &pathname) const
Short for 'localRoot() + pathname', but returns an empty pathname if media is not open.
Definition: MediaAccess.cc:307
void releaseFile(const Pathname &filename) const
Remove filename below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:359
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
Definition: MediaAccess.cc:411
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaAccess.cc:210
void releaseDir(const Pathname &dirname) const
Remove directory tree below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:392
void releasePath(const Pathname &pathname) const
Remove pathname below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:401
bool dependsOnParent() const
Definition: MediaAccess.cc:89
void open(const Url &url, const Pathname &preferred_attach_point="")
open url.
Definition: MediaAccess.cc:104
virtual ~MediaAccess()
Destructor.
Definition: MediaAccess.cc:59
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition: MediaAccess.cc:326
static const Pathname _noPath
Definition: MediaAccess.h:58
void provideFile(const Pathname &filename, const ByteCount &expectedFileSize) const
Use concrete handler to provide file denoted by path below 'attach point'.
Definition: MediaAccess.cc:339
void disconnect()
Use concrete handler to disconnect the media.
Definition: MediaAccess.cc:316
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below 'attach point' (not recursive!...
Definition: MediaAccess.cc:372
void close()
close url
Definition: MediaAccess.cc:231
bool doesFileExist(const Pathname &filename) const
check if a file exists
Definition: MediaAccess.cc:437
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below 'attach point' (recursive!...
Definition: MediaAccess.cc:382
void attach(bool next=false)
Use concrete handler to attach the media.
Definition: MediaAccess.cc:255
AttachedMedia attachedMedia() const
Definition: MediaAccess.cc:69
MediaHandler * _handler
handler for 'physical' media == 0 if not open
Definition: MediaAccess.h:64
bool hasMoreDevices() const
Definition: MediaAccess.cc:271
intrusive_ptr< MediaAccess > Ptr
Definition: MediaAccess.h:53
intrusive_ptr< const MediaAccess > constPtr
Definition: MediaAccess.h:54
bool isSharedMedia() const
Definition: MediaAccess.cc:76
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
Definition: MediaAccess.cc:447
std::string protocol() const
Used Protocol if media is opened, otherwise 'unknown'.
Definition: MediaAccess.cc:201
void setDeltafile(const Pathname &filename) const
set a deltafile to be used in the next download
Definition: MediaAccess.cc:349
virtual void getDetectedDevices(std::vector< std::string > &devices, unsigned int &index) const
Fill in a vector of detected ejectable devices and the index of the currently attached device within ...
Definition: MediaAccess.cc:278
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Definition: MediaAccess.cc:296
bool isAttached() const
True if media is attached.
Definition: MediaAccess.cc:265
MediaAccess()
constructor
Definition: MediaAccess.cc:53
Url url() const
Url if media is opened, otherwise empty.
Definition: MediaAccess.cc:221
Just inherits Exception to separate media exceptions.
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees,...
Definition: MediaManager.h:471
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
std::ostream & operator<<(std::ostream &str, const MediaAccess &obj)
Definition: MediaAccess.cc:481
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:134