libzypp: zypp/media/MediaPriority.cc Source File

libzypp 17.38.7

MediaPriority.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <zypp-core/base/LogTools.h>
14
15#include <zypp-core/Url.h>
16#include <zypp/ZConfig.h>
17
18#include <zypp/media/MediaPriority.h>
19
20using std::endl;
21
23namespace zypp
24{
26 namespace media
27 {
28
30 namespace
31 {
32
40 MediaPriority::value_type scheme2priority( const std::string & scheme_r )
41 {
42 switch ( scheme_r[0] )
43 {
44#define RETURN_IF(scheme,value) \
45 if ( ::strcmp( scheme+1, scheme_r.c_str()+1 ) == 0 ) return value;
46 case 'c':
47 RETURN_IF( "cd", ZConfig::instance().download_media_prefer_download() ? 1 : 2 );
48 RETURN_IF( "cifs", 3 );
49 break;
50
51 case 'd':
52 RETURN_IF( "dvd", ZConfig::instance().download_media_prefer_download() ? 1 : 2 );
53 RETURN_IF( "dir", 4 );
54 break;
55
56 case 'f':
57 RETURN_IF( "file", 4 );
58 RETURN_IF( "ftp", ZConfig::instance().download_media_prefer_download() ? 2 : 1);
59 break;
60
61 case 't':
62 RETURN_IF( "tftp", ZConfig::instance().download_media_prefer_download() ? 2 : 1);
63 break;
64
65 case 'h':
66 RETURN_IF( "http", ZConfig::instance().download_media_prefer_download() ? 2 : 1 );
67 RETURN_IF( "https", ZConfig::instance().download_media_prefer_download() ? 2 : 1 );
68 RETURN_IF( "hd", 4 );
69 break;
70
71 case 'n':
72 RETURN_IF( "nfs", 3 );
73 RETURN_IF( "nfs4", 3 );
74 break;
75
76 case 's':
77 RETURN_IF( "sftp", ZConfig::instance().download_media_prefer_download() ? 2 : 1 );
78 RETURN_IF( "smb", 3 );
79 break;
80#undef RETURN_IF
81 }
82 return 0;
83 }
84
86 } // namespace
88
90 //
91 // METHOD NAME : MediaPriority::MediaPriority
92 // METHOD TYPE : Ctor
93 //
94 MediaPriority::MediaPriority( const std::string & scheme_r )
95 : _val( scheme2priority( scheme_r ) )
96 {}
97
98 MediaPriority::MediaPriority( const Url & url_r )
99 : _val( scheme2priority( url_r.getScheme() ) )
100 {}
101
103 } // namespace media
106} // namespace zypp
LogTools.h
RETURN_IF
#define RETURN_IF(scheme, value)
MediaPriority.h
Url.h
ZConfig.h
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:756
zypp::media::MediaPriority::value_type
int value_type
Definition MediaPriority.h:46
zypp::media::MediaPriority::MediaPriority
MediaPriority()
Default ctor.
Definition MediaPriority.h:50
zypp::media::MediaPriority::_val
value_type _val
Definition MediaPriority.h:92
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2