00001 #ifndef __archiver_h__
00002 #define __archiver_h__
00003
00004 #include <string>
00005 #include <map>
00006
00007 #include "asserts.h"
00008 #include "estring.h"
00009 #include "timer.h"
00010 #include "exec.h"
00011 #include "rconfig.h"
00012 #include "logger.h"
00013 #include "vaulter.h"
00014 #include "reporter.h"
00015
00016
00017 class rstat
00018 {
00019 public:
00020 rstat();
00021 const std::string& exit(const int a_int) const;
00022 const std::string& signal(const int a_int) const;
00023
00024 private:
00025 std::map<int,std::string> m_exit_str;
00026 std::map<int,std::string> m_signal_str;
00027 std::string m_unknown_exit;
00028 std::string m_unknown_signal;
00029 };
00030
00031 extern class rstat rsync_estat_str;
00032
00033 class archiver;
00034
00035
00036 class job_archiver {
00037 public:
00038 enum archiving_status {
00039 status_pending,
00040 status_processing,
00041 status_reschedule,
00042 status_fatal_error,
00043 status_error,
00044 status_completed,
00045 status_done,
00046 };
00047
00048 job_archiver(const job * a_job);
00049 const std::string prefix(void);
00050 const std::string id(void);
00051 void clear(void);
00052 void end(void);
00053 const archiving_status status(void);
00054 void start(void);
00055 void process(void);
00056
00057 single_job_report report(void) const;
00058
00059 private:
00060 const job* m_job;
00061 archiving_status m_status;
00062 timer m_timer;
00063 timer m_io_timer;
00064 bool m_rsync_timeout_flag;
00065 execute m_exec;
00066 bool m_success;
00067 estring m_io_out;
00068 estring m_io_err;
00069 pid_t m_child_pid;
00070 job_path_report m_jpr;
00071 single_job_report m_jr;
00072 std::string m_error_msg;
00073
00074 void mf_do_chores(void);
00075 void mf_process_report(const std::string& a_str);
00076 void mf_process_child_io(bool a_finalize);
00077 void mf_process_rsync_io(
00078 execute& a_exec,
00079 uint16 a_timeout,
00080 uint64& a_files_total,
00081 uint64& a_files_xferd,
00082 uint64& a_size_total,
00083 uint64& a_size_xferd,
00084 bool& a_overflow_detected
00085 );
00086 void mf_parse_rsync_io(
00087 std::string a_str,
00088 uint64& a_files_total,
00089 uint64& a_files_xferd,
00090 uint64& a_size_total,
00091 uint64& a_size_xferd
00092 );
00093 void mf_trim_string(std::string& a_str);
00094 void mf_parse_report(const std::string& a_str);
00095 };
00096
00097
00098 class archive_manager {
00099 public:
00100 archive_manager();
00101
00102 void clear(void);
00103 void init(void);
00104 const bool initialized(void) const;
00105
00106 void archive(void);
00107
00108 const std::string archive_path(void) const;
00109 const std::string working_archive_path(void) const;
00110
00111 private:
00112 std::vector<job_archiver*> m_jobs;
00113 bool m_initialized;
00114
00115 void mf_log_status(void);
00116 };
00117
00118 extern archive_manager archiver;
00119
00120 #endif