libzypp 17.37.10

mediaconfig.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
13#include "mediaconfig.h"
14#include <zypp-core/Pathname.h>
15#include <zypp-core/base/String.h>
16
17 namespace zypp {
18
19 class MediaConfigPrivate {
20 public:
21
22 MediaConfigPrivate()
23 : download_max_concurrent_connections( 5 )
24 , download_min_download_speed ( 0 )
25 , download_max_download_speed ( 0 )
26 , download_max_silent_tries ( 1 )
27 , download_transfer_timeout ( 180 )
28 , download_connect_timeout ( 60 )
29 { }
30
31 Pathname credentials_global_dir_path;
32 Pathname credentials_global_file_path;
33
34 int download_max_concurrent_connections;
35 int download_min_download_speed;
36 int download_max_download_speed;
37 int download_max_silent_tries;
38 int download_transfer_timeout;
39 int download_connect_timeout;
40
41 };
42
43 MediaConfig::MediaConfig() : d_ptr( new MediaConfigPrivate() )
44 { }
45
46 MediaConfig &MediaConfig::instance()
47 {
48 static MediaConfig instance;
49 return instance;
50 }
51
52 bool MediaConfig::setConfigValue( const std::string &section, const std::string &entry, const std::string &value )
53 {
54 Z_D();
55 if ( section == "main" ) {
56 if ( entry == "credentials.global.dir" ) {
57 d->credentials_global_dir_path = Pathname(value);
58 return true;
59 } else if ( entry == "credentials.global.file" ) {
60 d->credentials_global_file_path = Pathname(value);
61 return true;
62
63 } else if ( entry == "download.max_concurrent_connections" ) {
64 str::strtonum(value, d->download_max_concurrent_connections);
65 return true;
66
67 } else if ( entry == "download.min_download_speed" ) {
68 str::strtonum(value, d->download_min_download_speed);
69 return true;
70
71 } else if ( entry == "download.max_download_speed" ) {
72 str::strtonum(value, d->download_max_download_speed);
73 return true;
74
75 } else if ( entry == "download.max_silent_tries" ) {
76 str::strtonum(value, d->download_max_silent_tries);
77 return true;
78
79 } else if ( entry == "download.connect_timeout" ) {
80 str::strtonum(value, d->download_connect_timeout);
81 if ( d->download_connect_timeout < 0 )
82 d->download_connect_timeout = 0;
83 return true;
84
85 } else if ( entry == "download.transfer_timeout" ) {
86 str::strtonum(value, d->download_transfer_timeout);
87 if ( d->download_transfer_timeout < 0 ) d->download_transfer_timeout = 0;
88 else if ( d->download_transfer_timeout > 3600 ) d->download_transfer_timeout = 3600;
89 return true;
90 }
91 }
92 return false;
93 }
94
95 Pathname MediaConfig::credentialsGlobalDir() const
96 {
97 Z_D();
98 return ( d->credentials_global_dir_path.empty() ?
99 Pathname("/etc/zypp/credentials.d") : d->credentials_global_dir_path );
100 }
101
102 Pathname MediaConfig::credentialsGlobalFile() const
103 {
104 Z_D();
105 return ( d->credentials_global_file_path.empty() ?
106 Pathname("/etc/zypp/credentials.cat") : d->credentials_global_file_path );
107 }
108
109 long MediaConfig::download_max_concurrent_connections() const
110 { return d_func()->download_max_concurrent_connections; }
111
112 long MediaConfig::download_min_download_speed() const
113 { return d_func()->download_min_download_speed; }
114
115 long MediaConfig::download_max_download_speed() const
116 { return d_func()->download_max_download_speed; }
117
118 long MediaConfig::download_max_silent_tries() const
119 { return d_func()->download_max_silent_tries; }
120
121 long MediaConfig::download_transfer_timeout() const
122 { return d_func()->download_transfer_timeout; }
123
124 long MediaConfig::download_connect_timeout() const
125 { return d_func()->download_connect_timeout; }
126
127 ZYPP_IMPL_PRIVATE(MediaConfig)
128}
129
130
zypp::MediaConfigPrivate
Definition mediaconfig.cc:19
zypp::MediaConfigPrivate::download_transfer_timeout
int download_transfer_timeout
Definition mediaconfig.cc:38
zypp::MediaConfigPrivate::credentials_global_dir_path
Pathname credentials_global_dir_path
Definition mediaconfig.cc:31
zypp::MediaConfigPrivate::MediaConfigPrivate
MediaConfigPrivate()
Definition mediaconfig.cc:22
zypp::MediaConfigPrivate::download_max_download_speed
int download_max_download_speed
Definition mediaconfig.cc:36
zypp::MediaConfigPrivate::download_min_download_speed
int download_min_download_speed
Definition mediaconfig.cc:35
zypp::MediaConfigPrivate::credentials_global_file_path
Pathname credentials_global_file_path
Definition mediaconfig.cc:32
zypp::MediaConfigPrivate::download_max_concurrent_connections
int download_max_concurrent_connections
Definition mediaconfig.cc:34
zypp::MediaConfigPrivate::download_connect_timeout
int download_connect_timeout
Definition mediaconfig.cc:39
zypp::MediaConfigPrivate::download_max_silent_tries
int download_max_silent_tries
Definition mediaconfig.cc:37
zypp::MediaConfig
Definition mediaconfig.h:43
zypp::MediaConfig::credentialsGlobalFile
Pathname credentialsGlobalFile() const
Definition mediaconfig.cc:102
zypp::MediaConfig::download_max_download_speed
long download_max_download_speed() const
Definition mediaconfig.cc:115
zypp::MediaConfig::credentialsGlobalDir
Pathname credentialsGlobalDir() const
Definition mediaconfig.cc:95
zypp::MediaConfig::download_min_download_speed
long download_min_download_speed() const
Definition mediaconfig.cc:112
zypp::MediaConfig::download_connect_timeout
long download_connect_timeout() const
Definition mediaconfig.cc:124
zypp::MediaConfig::MediaConfig
MediaConfig()
Definition mediaconfig.cc:43
zypp::MediaConfig::download_max_concurrent_connections
long download_max_concurrent_connections() const
Definition mediaconfig.cc:109
zypp::MediaConfig::d_ptr
std::unique_ptr< MediaConfigPrivate > d_ptr
Definition mediaconfig.h:95
zypp::MediaConfig::setConfigValue
bool setConfigValue(const std::string &section, const std::string &entry, const std::string &value)
Definition mediaconfig.cc:52
zypp::MediaConfig::instance
static MediaConfig & instance()
Definition mediaconfig.cc:46
zypp::MediaConfig::download_transfer_timeout
long download_transfer_timeout() const
Definition mediaconfig.cc:121
zypp::MediaConfig::download_max_silent_tries
long download_max_silent_tries() const
Definition mediaconfig.cc:118
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
mediaconfig.h
zypp::str::strtonum
TInt strtonum(const C_Str &str)
Parsing numbers from string.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
Pathname.h
String.h
ZYPP_IMPL_PRIVATE
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:92
Z_D
#define Z_D()
Definition zyppglobal.h:105