1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaManager.h
12 #ifndef ZYPP_MEDIA_MEDIAMANAGER_H
13 #define ZYPP_MEDIA_MEDIAMANAGER_H
15 #include <zypp/media/MediaAccess.h>
17 #include <zypp/base/Deprecated.h>
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/Pathname.h>
26 //////////////////////////////////////////////////////////////////////
28 { ////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////
32 { //////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////
36 typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
39 typedef MediaAccessId MediaId;
40 typedef unsigned int MediaNr;
43 ///////////////////////////////////////////////////////////////////
44 // forward declaration
48 ///////////////////////////////////////////////////////////////////
50 // CLASS NAME : MediaVerifierBase
53 * Interface to implement a media verifier.
55 class MediaVerifierBase //: private zypp::NonCopyable
66 ** Check if the specified attached media contains
67 ** the desired media (e.g. SLES10 CD1).
70 isDesiredMedia(const MediaAccessRef &ref) = 0;
74 ///////////////////////////////////////////////////////////////////
76 // CLASS NAME : NoVerifier
79 * Dummy default media verifier, which is always happy.
81 class NoVerifier : public MediaVerifierBase
84 NoVerifier(): MediaVerifierBase()
92 ** Don't check if the specified attached media contains
93 ** the desired media number. Always return true.
96 isDesiredMedia(const MediaAccessRef &ref)
104 ///////////////////////////////////////////////////////////////////
106 // CLASS NAME : MediaVerifierRef
109 * A shared reference to the MediaVerifier implementation.
111 typedef zypp::RW_pointer<MediaVerifierBase> MediaVerifierRef;
114 ///////////////////////////////////////////////////////////////////
116 // CLASS NAME : MediaManager
119 * Manages coordinated access to 'physical' media, e.g CDROM
122 * \note The MediaManager class is just an envelope around an
123 * inner singelton like implementation. This means, you can
124 * create as many managers as you want, also temporary in a
127 * \note Don't declare static MediaManager instances, unless
128 * you want to force (mutex) initialization order problems!
131 class MediaManager: private zypp::base::NonCopyable
135 * Creates a MediaManager envelope instance.
137 * In the case, that the inner implementation is not already
138 * allocated, and the MediaManager constructor was unable to
139 * allocate it, a std::bad_alloc exception is thrown.
141 * All further instances increase the use counter only.
143 * \throws std::bad_alloc
148 * Destroys MediaManager envelope instance.
149 * Decreases the use counter of the inner implementation.
154 * Opens the media access for specified with the url.
156 * If the \p preferred_attach_point parameter does not
157 * point to a usable attach point directory, the media
158 * manager automatically creates a temporary attach
159 * point in a default directory. This default directory
160 * can be changed using setAttachPrefix() function.
162 * \param url The media access url.
163 * \param preferred_attach_point The preferred, already
164 * existing directory, where the media should be
166 * \return a new media access id.
167 * \throws std::bad_alloc
168 * \throws MediaException
171 open(const Url &url, const Pathname & preferred_attach_point = "");
174 * Close the media access with specified id.
175 * \param accessId The media access id to close.
178 close(MediaAccessId accessId);
181 * Query if the media access is open / exists.
183 * \param accessId The media access id query.
184 * \return true, if access id is known and open.
187 isOpen(MediaAccessId accessId) const;
190 * Query the protocol name used by the media access
191 * handler. Similar to url().getScheme().
193 * \param accessId The media access id query.
194 * \return The protocol name used by the media access
195 * handler, otherwise 'unknown'.
196 * \throws MediaNotOpenException for invalid access id.
199 protocol(MediaAccessId accessId) const;
202 * Url of the media access id, otherwise empty Url.
204 * \throws MediaNotOpenException for invalid access id.
207 url(MediaAccessId accessId) const;
211 * Add verifier implementation for the specified media id.
212 * By default, the NoVerifier is used.
214 * \throws MediaNotOpenException for invalid access id.
217 addVerifier(MediaAccessId accessId,
218 const MediaVerifierRef &verifier);
221 * Remove verifier for specified media id.
223 * \throws MediaNotOpenException for invalid access id.
226 delVerifier(MediaAccessId accessId);
230 * Set or resets the directory name, where the media manager
231 * handlers create their temporary attach points (see open()
233 * It has effect to newly created temporary attach points only.
235 * \param attach_prefix The new prefix for temporary attach
236 * points, or empty pathname to reset to defaults.
237 * \return True on success, false if the \p attach_prefix
238 * parameters contains a path name, that does not
239 * point to a writable directory.
242 setAttachPrefix(const Pathname &attach_prefix);
245 * Attach the media using the concrete handler.
247 * \throws MediaNotOpenException for invalid access id.
250 attach(MediaAccessId accessId, bool next = false);
253 * Reattach to a new attach point.
255 * \deprecated This function will be removed, because the
256 * reattach function has race conditions (e.g. open file
257 * in the old attach point). Use setAttachPrefix() instead.
259 * \param accessId A media access Id.
260 * \param attach_point A new attach point directory.
261 * \param temporary Whether to reattach to a temporary
262 * attach point bellow of \p attach_point and cleanup
263 * it on release (temporary=true), or use the provided
264 * directory as attach point without to cleanup it on
265 * release (temporary=false, default behaviour).
266 * \throws MediaNotOpenException
267 * \throws MediaNotSupportedException
270 reattach(MediaAccessId accessId,
271 const Pathname &attach_point,
272 bool temporary = false) ZYPP_DEPRECATED;
275 * Release the attached media and optionally eject.
277 * \throws MediaNotOpenException for invalid access id.
280 release(MediaAccessId accessId, bool eject = false);
283 * Disconnect a remote media.
285 * This is useful for media which e.g. holds open a connection
286 * to a server like FTP. After calling disconnect() the media
287 * object (attach point) is still valid and files are present.
289 * But after calling disconnect() it's not possible to call
290 * fetch more data using the provideFile() or provideDir()
293 * \throws MediaNotOpenException for invalid access id.
296 disconnect(MediaAccessId accessId);
299 * Check if media is attached or not.
301 * \return True if media is attached.
302 * \throws MediaNotOpenException for invalid access id.
305 isAttached(MediaAccessId accessId) const;
308 * Returns information if media is on a shared
309 * physical device or not.
311 * \return True if it is shared, false if not.
312 * \throws MediaNotOpenException for invalid access id.
315 isSharedMedia(MediaAccessId accessId) const;
318 * Ask the registered verifier if the attached
319 * media is the desired one or not.
320 * \return True if media is attached and desired
321 * according to the actual verifier.
322 * \throws MediaNotOpenException for invalid access id.
325 isDesiredMedia(MediaAccessId accessId) const;
328 * Ask the specified verifier if the attached
329 * media is the desired one or not.
330 * \return True if media is attached and desired
331 * according to the specified verifier.
332 * \throws MediaNotOpenException for invalid access id.
335 isDesiredMedia(MediaAccessId accessId,
336 const MediaVerifierRef &verifier) const;
339 * Return the local directory that corresponds to medias url,
340 * no matter if media isAttached or not. Files requested will
341 * be available at 'localRoot() + filename' or even better
342 * 'localPath( filename )'
344 * \returns The directory name pointing to the media root
345 * in local filesystem or an empty pathname if the
346 * media is not attached.
347 * \throws MediaNotOpenException for invalid access id.
350 localRoot(MediaAccessId accessId) const;
353 * Shortcut for 'localRoot() + pathname', but returns an empty
354 * pathname if media is not attached.
355 * Files provided will be available at 'localPath(filename)'.
356 * \returns The directory name in local filesystem pointing
357 * to the desired relative pathname on the media
358 * or an empty pathname if the media is not attached.
359 * \throws MediaNotOpenException for invalid access id.
362 localPath(MediaAccessId accessId, const Pathname & pathname) const;
366 * Provide provide file denoted by relative path below of the
367 * 'attach point' of the specified media and the path prefix
370 * \param accessId The media access id to use.
371 * \param cached If cached is set to true, the function checks, if
372 * the file already exists and doesn't download it again
373 * if it does. Currently only the existence is checked,
374 * no other file attributes.
375 * \param checkonly If this and 'cached' are set to true only the
376 * existence of the file is checked but it's not
377 * downloaded. If 'cached' is unset an errer is
380 * \throws MediaNotOpenException in case of invalid access id.
381 * \throws MediaNotAttachedException in case, that the media is not attached.
382 * \throws MediaNotDesiredException in case, that the media verification failed.
383 * \throws MediaNotAFileException in case, that the requested filename is not a file.
384 * \throws MediaFileNotFoundException in case, that the requested filenamedoes not exists.
385 * \throws MediaWriteException in case, that the file can't be copied from from remote source.
386 * \throws MediaSystemException in case a system operation fails.
387 * \throws MediaException derived exception, depending on the url (handler).
390 provideFile(MediaAccessId accessId,
391 const Pathname &filename,
393 bool checkonly = false) const;
398 provideDir(MediaAccessId accessId,
399 const Pathname &dirname) const;
404 provideDirTree(MediaAccessId accessId,
405 const Pathname &dirname) const;
410 releaseFile(MediaAccessId accessId,
411 const Pathname &filename) const;
416 releaseDir(MediaAccessId accessId,
417 const Pathname &dirname) const;
422 releasePath(MediaAccessId accessId,
423 const Pathname &pathname) const;
428 dirInfo(MediaAccessId accessId,
429 std::list<std::string> &retlist,
430 const Pathname &dirname,
431 bool dots = true) const;
436 dirInfo(MediaAccessId accessId,
437 filesystem::DirContent &retlist,
438 const Pathname &dirname,
439 bool dots = true) const;
444 getMountTableMTime() const;
446 std::vector<MountEntry>
447 getMountEntries() const;
450 isUseableAttachPoint(const Pathname &path) const;
453 friend class MediaHandler;
456 getAttachedMedia(MediaAccessId &accessId) const;
459 findAttachedMedia(const MediaSourceRef &media) const;
462 forceMediaRelease(const MediaSourceRef &media);
466 static zypp::RW_pointer<MediaManager::Impl> m_impl;
470 //////////////////////////////////////////////////////////////////
472 ////////////////////////////////////////////////////////////////////
474 ////////////////////////////////////////////////////////////////////
476 //////////////////////////////////////////////////////////////////////
478 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
481 ** vim: set ts=2 sts=2 sw=2 ai et: