1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/MediaProducts.h
10 * Functions to find out products in media
12 #ifndef ZYPP_MEDIAPRODUCTS_H_
13 #define ZYPP_MEDIAPRODUCTS_H_
18 #include "zypp/ZConfig.h"
19 #include "zypp/base/Logger.h"
20 #include "zypp/media/MediaManager.h"
21 #include "zypp/base/UserRequestException.h"
23 #include "zypp/ProgressData.h"
28 * \short Represents an available product in media
30 struct MediaProductEntry
38 MediaProductEntry( const Pathname & dir_r = "/", const std::string & name_r = std::string() )
39 : _dir(dir_r), _name(name_r)
43 bool operator<( const MediaProductEntry &rhs ) const
45 return ( _name < rhs._name );
50 * A set of available products in media
52 typedef std::set<MediaProductEntry> MediaProductSet;
55 * FIXME: add a comment here...
57 template <class _OutputIterator>
58 static void scanProductsFile( const Pathname & file_r, _OutputIterator result )
60 std::ifstream pfile( file_r.asString().c_str() );
61 while ( pfile.good() ) {
63 std::string value = str::getline( pfile, str::TRIM );
65 ERR << "Error parsing " << file_r << std::endl;
66 ZYPP_THROW(Exception("Error parsing " + file_r.asString()));
69 break; // no data on last line
71 std::string tag = str::stripFirstWord( value, true );
74 *result = MediaProductEntry( tag, value );
80 * \short Available products in a url location
82 * \param url_r url to inspect
83 * \param result output iterator where \ref MediaProductEntry
84 * items will be inserted.
85 * \throws MediaException If accessng the media fails
87 template <class _OutputIterator>
88 void productsInMedia( const Url & url_r, _OutputIterator result )
90 media::MediaManager media_mgr;
92 media::MediaId id = media_mgr.open(url_r);
93 media_mgr.attachDesiredMedia(id);
94 Pathname products_file = Pathname("media.1/products");
97 media_mgr.provideFile (id, products_file);
98 products_file = media_mgr.localPath (id, products_file);
99 scanProductsFile (products_file, result);
101 catch ( const Exception & excpt ) {
103 MIL << "No products description found on the Url" << std::endl;
105 media_mgr.release(id, "");
109 * \short Available products in a url location
111 * \param url_r url to inspect
112 * \param set ef MediaProductEntry set where
113 * items will be inserted.
114 * \throws MediaException If accessng the media fails
116 void productsInMedia( const Url & url_r, MediaProductSet &set )
118 productsInMedia(url_r, std::inserter(set, set.end()));
125 // vim: set ts=2 sts=2 sw=2 et ai: