ref: refs/heads/master
commit 8f174adf4599ebd4066e92650c9baa8cb9a74438
Author: Michael Andres
Date: Tue Mar 31 15:47:34 2009 +0200
New class MediaPriority: Derive a numeric priority from Url scheme according to zypp.conf(download.media_preference).
---
zypp/CMakeLists.txt | 2 +
zypp/media/MediaPriority.cc | 102 +++++++++++++++++++++++++++++++++++++++++++
zypp/media/MediaPriority.h | 101 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 205 insertions(+), 0 deletions(-)
diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt
index 7a7f27f..145e5bc 100644
--- a/zypp/CMakeLists.txt
+++ b/zypp/CMakeLists.txt
@@ -271,6 +271,7 @@ SET( zypp_media_SRCS
media/CredentialManager.cc
media/CurlConfig.cc
media/TransferSettings.cc
+ media/MediaPriority.cc
)
SET( zypp_media_HEADERS
@@ -295,6 +296,7 @@ SET( zypp_media_HEADERS
media/CredentialManager.h
media/CurlConfig.h
media/TransferSettings.h
+ media/MediaPriority.h
)
INSTALL( FILES
diff --git a/zypp/media/MediaPriority.cc b/zypp/media/MediaPriority.cc
new file mode 100644
index 0000000..5731ad4
--- /dev/null
+++ b/zypp/media/MediaPriority.cc
@@ -0,0 +1,102 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/MediaPriority.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/LogTools.h"
+
+#include "zypp/Url.h"
+#include "zypp/ZConfig.h"
+
+#include "zypp/media/MediaPriority.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace media
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ namespace
+ { /////////////////////////////////////////////////////////////////
+
+ /**
+ * 4: local: file,dir,hd
+ * 3: remote: nfs,cifs,smb
+ * ?: download: http,https,ftp,sftp
+ * ?: volatile: cd,dvd
+ * 0: the rest
+ */
+ MediaPriority::value_type scheme2priority( const std::string & scheme_r )
+ {
+ switch ( scheme_r[0] )
+ {
+#define RETURN_IF(scheme,value) \
+ if ( ::strcmp( scheme+1, scheme_r.c_str()+1 ) == 0 ) return value;
+ case 'c':
+ RETURN_IF( "cd", ZConfig::instance().download_media_prefer_download() ? 1 : 2 );
+ RETURN_IF( "cifs", 3 );
+ break;
+
+ case 'd':
+ RETURN_IF( "dvd", ZConfig::instance().download_media_prefer_download() ? 1 : 2 );
+ RETURN_IF( "dir", 4 );
+ break;
+
+ case 'f':
+ RETURN_IF( "file", 4 );
+ RETURN_IF( "ftp", ZConfig::instance().download_media_prefer_download() ? 2 : 1);
+ break;
+
+ case 'h':
+ RETURN_IF( "http", ZConfig::instance().download_media_prefer_download() ? 2 : 1 );
+ RETURN_IF( "https", ZConfig::instance().download_media_prefer_download() ? 2 : 1 );
+ RETURN_IF( "hd", 4 );
+ break;
+
+ case 'n':
+ RETURN_IF( "nfs", 3 );
+ break;
+
+ case 's':
+ RETURN_IF( "sftp", ZConfig::instance().download_media_prefer_download() ? 2 : 1 );
+ RETURN_IF( "smb", 3 );
+ break;
+#undef RETURN_IF
+ }
+ return 0;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : MediaPriority::MediaPriority
+ // METHOD TYPE : Ctor
+ //
+ MediaPriority::MediaPriority( const std::string & scheme_r )
+ : _val( scheme2priority( scheme_r ) )
+ {}
+
+ MediaPriority::MediaPriority( const Url & url_r )
+ : _val( scheme2priority( url_r.getScheme() ) )
+ {}
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace media
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/media/MediaPriority.h b/zypp/media/MediaPriority.h
new file mode 100644
index 0000000..aef3199
--- /dev/null
+++ b/zypp/media/MediaPriority.h
@@ -0,0 +1,101 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/MediaPriority.h
+ *
+*/
+#ifndef ZYPP_MEDIA_MEDIAPRIORITY_H
+#define ZYPP_MEDIA_MEDIAPRIORITY_H
+
+#include <string>
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+ class Url;
+
+ ///////////////////////////////////////////////////////////////////
+ namespace media
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : MediaPriority
+ //
+ /** Derive a numeric priority from \ref Url scheme according to zypp.conf(download.media_preference).
+ *
+ * The class is simple. Constructable and assignable from \ref Url
+ * or scheme string. Implicit convertible into a numic \ref value_type.
+ *
+ * \code
+ * if ( MediaPriority("cd") \< MediaPriority("ftp") )
+ * ...
+ * \endcode
+ *
+ * \todo Maybe introduce a static tribool, to allow overwriting zypp.conf(download.media_preference) default.
+ */
+ class MediaPriority
+ {
+ public:
+ typedef int value_type;
+
+ public:
+ /** Default ctor. Least priority \c 0.*/
+ MediaPriority()
+ : _val( 0 )
+ {}
+
+ /** Copy ctor. */
+ MediaPriority( value_type val_r )
+ : _val( val_r )
+ {}
+
+ /** Ctor from scheme string.*/
+ MediaPriority( const std::string & scheme_r );
+
+ /** Ctor from scheme string defined by Url. */
+ MediaPriority( const Url & url_r );
+
+ public:
+ /** Assign. */
+ MediaPriority & operator=( value_type rhs )
+ { _val = rhs; return *this; }
+
+ /** Assign priority of scheme string. */
+ MediaPriority & operator=( const std::string & scheme_r )
+ { _val = MediaPriority(scheme_r); return *this; }
+
+ /** Assign priority of scheme string defined by Url. */
+ MediaPriority & operator=( const Url & url_r )
+ { _val = MediaPriority(url_r); return *this; }
+
+ public:
+ /** Conversion to value_type. */
+ //@{
+ /** Explicit */
+ value_type & get() { return _val; }
+ /** Explicit */
+ const value_type & get() const { return _val; }
+ /** Implicit */
+ operator value_type &() { return get(); }
+ /** Implicit */
+ operator const value_type &() const { return get(); }
+ //@}
+
+ private:
+ value_type _val;
+ };
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace media
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_MEDIA_MEDIAPRIORITY_H
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org