00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */ 00002 00003 /* 00004 * Copyright (c) 2006, 2007, 2008, 2009 Ciaran McCreesh 00005 * 00006 * This file is part of the Paludis package manager. Paludis is free software; 00007 * you can redistribute it and/or modify it under the terms of the GNU General 00008 * Public License version 2, as published by the Free Software Foundation. 00009 * 00010 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY 00011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00013 * details. 00014 * 00015 * You should have received a copy of the GNU General Public License along with 00016 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00017 * Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #ifndef PALUDIS_GUARD_PALUDIS_SYNCER_HH 00021 #define PALUDIS_GUARD_PALUDIS_SYNCER_HH 1 00022 00023 #include <paludis/util/exception.hh> 00024 #include <paludis/output_manager-fwd.hh> 00025 #include <paludis/repository.hh> 00026 #include <string> 00027 00028 /** \file 00029 * Declarations for the Syncer class, which can be used by repositories to 00030 * simplify syncing. 00031 * 00032 * \ingroup g_repository 00033 * 00034 * \section Examples 00035 * 00036 * - None at this time. 00037 */ 00038 00039 namespace paludis 00040 { 00041 namespace n 00042 { 00043 struct environment; 00044 struct filter_file; 00045 struct local; 00046 struct options; 00047 struct output_manager; 00048 struct remote; 00049 } 00050 00051 /** 00052 * Options used by Syncer. 00053 * 00054 * \see Syncer 00055 * \ingroup g_repository 00056 * \nosubgrouping 00057 */ 00058 struct SyncOptions 00059 { 00060 NamedValue<n::filter_file, FSEntry> filter_file; 00061 NamedValue<n::options, std::string> options; 00062 00063 /** 00064 * \since 0.36 00065 */ 00066 NamedValue<n::output_manager, std::tr1::shared_ptr<OutputManager> > output_manager; 00067 }; 00068 00069 /** 00070 * Parameters for a Syncer. 00071 * 00072 * \see Syncer 00073 * \ingroup g_repository 00074 * \nosubgrouping 00075 */ 00076 struct SyncerParams 00077 { 00078 NamedValue<n::environment, const Environment *> environment; 00079 NamedValue<n::local, std::string> local; 00080 NamedValue<n::remote, std::string> remote; 00081 }; 00082 00083 /** 00084 * A Syncer subclass handles syncing Repository instances. 00085 * 00086 * \ingroup g_repository 00087 */ 00088 class PALUDIS_VISIBLE Syncer : 00089 private InstantiationPolicy<Syncer, instantiation_method::NonCopyableTag> 00090 { 00091 protected: 00092 /** 00093 * Constructor. 00094 */ 00095 Syncer(); 00096 00097 public: 00098 /** 00099 * Destructor. 00100 */ 00101 virtual ~Syncer(); 00102 00103 /** 00104 * Perform the sync. 00105 */ 00106 virtual void sync(const SyncOptions &) const = 0; 00107 }; 00108 00109 /** 00110 * A Syncer subclass that uses a program from the syncers/ directory. 00111 * 00112 * \ingroup g_repository 00113 */ 00114 class PALUDIS_VISIBLE DefaultSyncer : 00115 public Syncer 00116 { 00117 private: 00118 std::string _local, _remote; 00119 const Environment *_environment; 00120 00121 std::string _syncer; 00122 00123 public: 00124 /** 00125 * Constructor. 00126 */ 00127 DefaultSyncer(const SyncerParams &); 00128 00129 /** 00130 * Destructor. 00131 */ 00132 virtual ~DefaultSyncer(); 00133 00134 /** 00135 * Perform the sync. 00136 */ 00137 virtual void sync(const SyncOptions &) const; 00138 }; 00139 00140 /** 00141 * Thrown if a sync fails. 00142 * 00143 * \ingroup g_repository 00144 * \ingroup g_exceptions 00145 */ 00146 class PALUDIS_VISIBLE SyncFailedError : 00147 public Exception 00148 { 00149 public: 00150 /** 00151 * Constructor. 00152 */ 00153 SyncFailedError(const std::string & msg) throw (); 00154 00155 /** 00156 * Constructor. 00157 */ 00158 SyncFailedError(const std::string & local, const std::string & remote) throw (); 00159 }; 00160 00161 /** 00162 * Thrown if a syncer of the specified type does not exist. 00163 * 00164 * \ingroup g_repository 00165 * \ingroup g_exceptions 00166 */ 00167 class PALUDIS_VISIBLE NoSuchSyncerError : public SyncFailedError 00168 { 00169 public: 00170 /** 00171 * Constructor. 00172 */ 00173 NoSuchSyncerError(const std::string & format) throw (); 00174 }; 00175 } 00176 00177 #endif