rconfig.h

Go to the documentation of this file.
00001 #ifndef __rconfig_h__
00002 #define __rconfig_h__
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 #include <vector>
00008 #include <map>
00009 
00010 #include "asserts.h"
00011 #include "types.h"
00012 #include "tstamp.h"
00013 
00014 //----------------------------------------------------------------------------
00015 
00016 class parser;
00017 class parse_job;
00018 
00019 /** A configuration manager support class:
00020         Used to specify a single subdirectory in a path of subdirectory names for a
00021         unique path under the archive directory for each job
00022         */
00023 class archive_path_element
00024 {
00025 public:
00026         enum element_type {
00027                 jobname,
00028                 groupname,
00029                 hostname,
00030                 pathname,
00031                 permutation,
00032                 literal
00033         };
00034 
00035         void clear(void);
00036 
00037         archive_path_element();
00038         archive_path_element(const archive_path_element& a_class);
00039         archive_path_element(const element_type& a_enum);
00040         archive_path_element(const std::string& a_str);
00041 
00042         void assign(const archive_path_element& a_class);
00043         void assign(const element_type& a_enum);
00044         void assign(const std::string& a_str);
00045 
00046         const element_type& type(void) const;
00047         const std::string& value(void) const;
00048         const std::string str(void) const;
00049 
00050         archive_path_element& operator=(const archive_path_element& a_class);
00051         archive_path_element& operator=(const element_type a_enum);
00052         archive_path_element& operator=(const std::string& a_str);
00053 
00054 private:
00055         element_type m_type;
00056         std::string m_literal;
00057 };
00058 
00059 /** A configuration manager support class:
00060         Used to specify a unique subdirectory in the archive for each job (made up
00061         of archive_path_element's)
00062  */
00063 class archive_path : public std::vector<archive_path_element>
00064 {
00065 public:
00066         typedef std::vector<archive_path_element> type;
00067 
00068         void reset(void);
00069 
00070         archive_path();
00071         archive_path(const archive_path& a_class);
00072         archive_path(const archive_path_element& a_class);
00073         archive_path(const std::string& a_class);
00074 
00075         void push_back(const archive_path& a_class);
00076         void push_back(const archive_path_element& a_class);
00077         void push_back(const std::string& a_str);
00078 
00079         void assign(const archive_path& a_class);
00080         void assign(const archive_path_element& a_class);
00081         void assign(const std::string& a_str);
00082 
00083         const std::string str(void) const;
00084 
00085         archive_path& operator=(const archive_path& a_class);
00086         archive_path& operator=(const archive_path_element& a_class);
00087         archive_path& operator=(const std::string& a_str);
00088 
00089 private:
00090 };
00091 
00092 /** A configuration manager support class:
00093         Used to map rsync exit codes to actions for rvm to take
00094  */
00095 class rsync_behavior
00096 {
00097 public:
00098         enum behavior_type {
00099                 quit,
00100                 fail,
00101                 retry,
00102                 retry_without_hardlinks,
00103                 ok
00104         };
00105         typedef behavior_type value_type;
00106         typedef std::map<uint16, value_type> map_type;
00107         static const uint16 default_behavior = ((uint16)-1);
00108 
00109         void clear(void);
00110         void reset(void);
00111 
00112         rsync_behavior();
00113         rsync_behavior(const rsync_behavior& a_class);
00114 
00115         void assign(const uint16 a_code, const value_type a_action);
00116         void assign(const rsync_behavior& a_class);
00117         void assign(const std::string& a_str);
00118 
00119         const value_type operator[](const uint16 a_code) const;
00120         value_type& operator[](const uint16 a_code);
00121         rsync_behavior& operator=(const rsync_behavior& a_class);
00122         rsync_behavior& operator=(const behavior_type a_enum);
00123         rsync_behavior& operator=(const std::string& a_str);
00124 
00125         const value_type default_value(void) const;
00126         const map_type& map_value(void) const;
00127 
00128 private:
00129         map_type m_map;
00130         value_type m_default;
00131 };
00132 
00133 class configuration_manager;
00134 
00135 /** Hold configuration data for a single job */
00136 class job
00137 {
00138 public:
00139         enum rsync_connection_type {
00140                 connection_remote,
00141                 connection_local,
00142                 connection_server
00143         };
00144         enum rsync_behavior_type {
00145                 behavior_ok,
00146                 behavior_fail,
00147                 behavior_retry,
00148                 behavior_retry_without_hardlinks
00149         };
00150         typedef std::vector<std::string> excludes_type;
00151         typedef std::vector<std::string> includes_type;
00152         typedef std::vector<std::string> paths_type;
00153 
00154         job();
00155         job(const job& a_job);
00156 
00157         void clear(void);
00158         void assign(const job& a_job);
00159 
00160         job& operator=(const job& a_job);
00161 
00162         std::string default_config_path;
00163         uint16 default_config_line;
00164         std::string config_path;
00165         uint16 config_line;
00166         class archive_path archive_path;
00167         excludes_type excludes;
00168         includes_type includes;
00169         std::string groupname;
00170         std::string hostname;
00171         std::string jobname;
00172         paths_type paths;
00173         class rsync_behavior rsync_behavior;
00174         rsync_connection_type rsync_connection;
00175         bool rsync_hardlink;
00176         std::string rsync_options;
00177         std::string rsync_remote_user;
00178         std::string rsync_remote_path;
00179         std::string rsync_remote_module;
00180         uint16 rsync_remote_port;
00181         uint16 rsync_retry_count;
00182         uint16 rsync_timeout;
00183 
00184         const std::string generate_archive_path(const std::string& a_path) const;
00185         const std::string generate_source_path(const std::string& a_path) const;
00186         const std::string generate_job_id(void) const;
00187         const std::string common_pathname(void) const;
00188         void check(void);
00189 
00190 private:
00191 
00192         friend class parser;
00193 };
00194 
00195 /** Keep up with configuration settings for RVM and it's jobs */
00196 class configuration_manager
00197 {
00198 public:
00199         enum action_type {
00200                 action_help,
00201                 action_version,
00202                 action_archive,
00203                 action_relink,
00204                 action_check_config
00205         };
00206         enum cfgfile_type {
00207                 config_file,
00208                 job_file,
00209         };
00210         enum overflow_type {
00211                 overflow_quit,
00212                 overflow_delete_oldest,
00213                 overflow_delete_until_free
00214         };
00215         enum selection_type {
00216                 selection_round_robin,
00217                 selection_max_free
00218         };
00219         enum logging_type {
00220                 logging_manager,
00221                 logging_child,
00222                 logging_rsync
00223         };
00224         typedef std::pair<cfgfile_type, std::string> cfgfile_element;
00225         typedef std::vector<cfgfile_element> cfgfiles_type;
00226         typedef std::vector<job> jobs_type;
00227         typedef std::vector<std::string> vaults_type;
00228 
00229         void clear(void);
00230 
00231         configuration_manager();
00232 
00233         void init(int argc, char *argv[]);
00234         void check(void) const;
00235         const bool initialized(void) const;
00236 
00237         const action_type action(void) const;
00238         const bool use_default(void) const;
00239         void default_file(const std::string& a_path);
00240         const std::string& default_file(void) const;
00241         void default_logdir(const std::string& a_path);
00242         const class timestamp& timestamp(void) const;
00243         const std::string& link_catalog_dir(void) const;
00244         const std::string& log_dir(void) const;
00245         const bool delete_old_log_files(void) const;
00246         const bool delete_old_report_files(void) const;
00247         const std::string& rsync_local_path(void) const;
00248         const uint16& rsync_parallel(void) const;
00249         const uint16& io_poll_interval(void) const;
00250         const timestamp::resolution_type timestamp_resolution(void) const;
00251         const vaults_type& vaults(void) const;
00252         const overflow_type& vault_overflow_behavior(void) const;
00253         const uint16& vault_overflow_blocks(void) const;
00254         const uint16& vault_overflow_inodes(void) const;
00255         const selection_type& vault_selection_behavior(void) const;
00256         const bool vault_locking(void) const;
00257         const job& default_job(void) const;
00258         const jobs_type& jobs(void) const;
00259         const logging_type& logging_level(void) const;
00260         const logging_type& error_logging_level(void) const;
00261 
00262 private:
00263         bool m_initialized;
00264         uint16 m_configs_read;
00265         std::string m_default_file;
00266         action_type m_action;
00267         bool m_default;
00268         class timestamp m_timestamp;
00269         class cfgfiles_type m_cfgfiles;
00270         std::string m_link_catalog_dir;
00271         std::string m_log_dir;
00272         std::string m_rsync_local_path;
00273         uint16 m_rsync_parallel;
00274         uint16 m_io_poll_interval;
00275         std::vector<std::string> m_vaults;
00276         overflow_type m_vault_overflow_behavior;
00277         uint16 m_vault_overflow_blocks;
00278         uint16 m_vault_overflow_inodes;
00279         selection_type m_vault_selection_behavior;
00280         bool m_vault_locking;
00281         bool m_delete_old_log_files;
00282         bool m_delete_old_report_files;
00283         job m_default_job;
00284         jobs_type m_jobs;
00285         logging_type m_logging_level;
00286         logging_type m_error_logging_level;
00287 
00288         friend class global_parser;
00289         friend class job_parser;
00290 
00291         void read_config(const std::string& a_path);
00292         void read_job(const std::string& a_path);
00293 };
00294 
00295 void parse_line(
00296         std::istream& a_in, 
00297         std::string& a_keyword, 
00298         std::string& a_value
00299         );
00300 
00301 /** A configuration manager support class:
00302         Used to parse a configuration file from the perspective of a global context
00303  */
00304 class global_parser
00305 {
00306 public:
00307         global_parser(
00308                 const std::string& a_path,
00309                 uint16& a_line,
00310                 std::istream& a_in
00311                 );
00312 
00313 private:
00314         const std::string* m_path;
00315         std::istream* m_in;
00316         uint16* m_line;
00317 
00318         const std::string location(void);
00319         void read_config(const std::string& a_path);
00320         void read_job(const std::string& a_path, job& a_job);
00321 
00322         void parse(void);
00323         void parse_default(const std::string& a_value);
00324         void parse_include(const std::string& a_value);
00325         void parse_include_job(const std::string& a_value);
00326         void parse_job(const std::string& a_value);
00327         void parse_link_catalog_dir(const std::string& a_value);
00328         void parse_log_dir(const std::string& a_value);
00329         void parse_delete_old_log_files(const std::string& a_value);
00330         void parse_delete_old_report_files(const std::string& a_value);
00331         void parse_logging_level(const std::string& a_value);
00332         void parse_error_logging_level(const std::string& a_value);
00333         void parse_rsync_local_path(const std::string& a_value);
00334         void parse_rsync_parallel(const std::string& a_value);
00335         void parse_io_poll_interval(const std::string& a_value);
00336         void parse_timestamp_resolution(const std::string& a_value);
00337         void parse_vault(const std::string& a_value);
00338         void parse_vault_overflow_behavior(const std::string& a_value);
00339         void parse_vault_overflow_blocks(const std::string& a_value);
00340         void parse_vault_overflow_inodes(const std::string& a_value);
00341         void parse_vault_selection_behavior(const std::string& a_value);
00342         void parse_vault_locking(const std::string& a_value);
00343 };
00344 
00345 /** A configuration manager support class:
00346         Used to parse a configuration file from the perspective of a job context
00347  */
00348 class job_parser
00349 {
00350 public:
00351         job_parser(
00352                 job * a_job, 
00353                 const std::string& a_path,
00354                 uint16& a_line,
00355                 std::istream& a_in,
00356                 const std::string& a_block_delimiter,
00357                 const bool a_default_context
00358                 );
00359 
00360 private:
00361         job* m_job;
00362         const std::string* m_path;
00363         std::istream* m_in;
00364         uint16* m_line;
00365         const std::string* m_delimiter;
00366         bool m_default_context;
00367 
00368         const std::string location(void);
00369         void job_parser::read_job(const std::string& a_path);
00370 
00371         void parse(void);
00372         void parse_archive_path(const std::string& a_value);
00373         void parse_clear(const std::string& a_value);
00374         void parse_exclude_from(const std::string& a_value);
00375         void parse_include_from(const std::string& a_value);
00376         void parse_groupname(const std::string& a_value);
00377         void parse_hostname(const std::string& a_value);
00378         void parse_include(const std::string& a_value);
00379         void parse_jobname(const std::string& a_value);
00380         void parse_path(const std::string& a_value);
00381         void parse_rsync_behavior(const std::string& a_value);
00382         void parse_rsync_connection_type(const std::string& a_value);
00383         void parse_rsync_hardlink(const std::string& a_value);
00384         void parse_rsync_options(const std::string& a_value);
00385         void parse_rsync_options_context(const std::string& a_value);
00386         void parse_rsync_remote_user(const std::string& a_value);
00387         void parse_rsync_remote_path(const std::string& a_value);
00388         void parse_rsync_remote_port(const std::string& a_value);
00389         void parse_rsync_remote_module(const std::string& a_value);
00390         void parse_rsync_retry_count(const std::string& a_value);
00391         void parse_rsync_timeout(const std::string& a_value);
00392 };
00393 
00394 extern configuration_manager config;
00395 
00396 #endif

Generated on Fri Jun 23 16:46:30 2006 for rvm by  doxygen 1.4.2