repository.hh

Go to the documentation of this file.
00001 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
00002 
00003 /*
00004  * Copyright (c) 2005, 2006, 2007, 2008 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_REPOSITORY_HH
00021 #define PALUDIS_GUARD_PALUDIS_REPOSITORY_HH 1
00022 
00023 #include <paludis/action-fwd.hh>
00024 #include <paludis/repository-fwd.hh>
00025 #include <paludis/dep_spec-fwd.hh>
00026 #include <paludis/dep_tree.hh>
00027 #include <paludis/name.hh>
00028 #include <paludis/package_id-fwd.hh>
00029 #include <paludis/qa-fwd.hh>
00030 #include <paludis/util/attributes.hh>
00031 #include <paludis/util/exception.hh>
00032 #include <paludis/util/sr.hh>
00033 #include <paludis/util/fs_entry.hh>
00034 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
00035 #include <paludis/util/options.hh>
00036 #include <paludis/util/named_value.hh>
00037 #include <paludis/util/output_deviator-fwd.hh>
00038 #include <paludis/version_spec.hh>
00039 #include <paludis/metadata_key-fwd.hh>
00040 #include <paludis/metadata_key_holder.hh>
00041 #include <paludis/merger-fwd.hh>
00042 #include <string>
00043 #include <tr1/functional>
00044 
00045 /** \file
00046  * Declarations for Repository classes.
00047  *
00048  * \ingroup g_repository
00049  *
00050  * \section Examples
00051  *
00052  * - \ref example_repository.cc "example_repository.cc"
00053  */
00054 
00055 namespace paludis
00056 {
00057     namespace n
00058     {
00059         struct arch;
00060         struct destination_interface;
00061         struct e_interface;
00062         struct environment_file;
00063         struct environment_variable_interface;
00064         struct hook_interface;
00065         struct image_dir;
00066         struct make_virtuals_interface;
00067         struct manifest_interface;
00068         struct mirrors_interface;
00069         struct options;
00070         struct package_id;
00071         struct path;
00072         struct profile;
00073         struct provided_by;
00074         struct provided_by_spec;
00075         struct provides_interface;
00076         struct qa_interface;
00077         struct sets_interface;
00078         struct status;
00079         struct syncable_interface;
00080         struct used_this_for_config_protect;
00081         struct virtual_name;
00082         struct virtuals_interface;
00083     }
00084 
00085     /**
00086      * Optional interfaces that may be provided by a Repository.
00087      *
00088      * \see Repository
00089      * \ingroup g_repository
00090      * \since 0.30
00091      */
00092     struct RepositoryCapabilities
00093     {
00094         NamedValue<n::destination_interface, RepositoryDestinationInterface *> destination_interface;
00095         NamedValue<n::e_interface, RepositoryEInterface *> e_interface;
00096         NamedValue<n::environment_variable_interface, RepositoryEnvironmentVariableInterface *> environment_variable_interface;
00097         NamedValue<n::hook_interface, RepositoryHookInterface *> hook_interface;
00098         NamedValue<n::make_virtuals_interface, RepositoryMakeVirtualsInterface *> make_virtuals_interface;
00099         NamedValue<n::manifest_interface, RepositoryManifestInterface *> manifest_interface;
00100         NamedValue<n::mirrors_interface, RepositoryMirrorsInterface *> mirrors_interface;
00101         NamedValue<n::provides_interface, RepositoryProvidesInterface *> provides_interface;
00102         NamedValue<n::qa_interface, RepositoryQAInterface *> qa_interface;
00103         NamedValue<n::sets_interface, RepositorySetsInterface *> sets_interface;
00104         NamedValue<n::syncable_interface, RepositorySyncableInterface *> syncable_interface;
00105         NamedValue<n::virtuals_interface, RepositoryVirtualsInterface *> virtuals_interface;
00106     };
00107 
00108     /**
00109      * A profiles.desc line in a Repository implementing RepositoryEInterface.
00110      *
00111      * \see Repository
00112      * \see RepositoryEInterface
00113      * \ingroup g_repository
00114      * \since 0.30
00115      */
00116     struct RepositoryEInterfaceProfilesDescLine
00117     {
00118         NamedValue<n::arch, std::string> arch;
00119         NamedValue<n::path, FSEntry> path;
00120         NamedValue<n::profile, std::tr1::shared_ptr<ERepositoryProfile> > profile;
00121         NamedValue<n::status, std::string> status;
00122     };
00123 
00124     /**
00125      * A provides entry in a Repository implementing RepositoryProvidesInterface.
00126      *
00127      * \see Repository
00128      * \see RepositoryProvidesInterface
00129      * \ingroup g_repository
00130      * \since 0.30
00131      */
00132     struct RepositoryProvidesEntry
00133     {
00134         NamedValue<n::provided_by, std::tr1::shared_ptr<const PackageID> > provided_by;
00135         NamedValue<n::virtual_name, QualifiedPackageName> virtual_name;
00136     };
00137 
00138     /**
00139      * A virtuals entry in a Repository implementing RepositoryVirtualsInterface.
00140      *
00141      * \see Repository
00142      * \see RepositoryVirtualsInterface
00143      * \ingroup g_repository
00144      * \since 0.30
00145      */
00146     struct RepositoryVirtualsEntry
00147     {
00148         NamedValue<n::provided_by_spec, std::tr1::shared_ptr<const PackageDepSpec> > provided_by_spec;
00149         NamedValue<n::virtual_name, QualifiedPackageName> virtual_name;
00150     };
00151 
00152     /**
00153      * Parameters for RepositoryDestinationInterface::merge.
00154      *
00155      * \see RepositoryDestinationInterface
00156      * \ingroup g_repository
00157      * \since 0.30
00158      */
00159     struct MergeParams
00160     {
00161         NamedValue<n::environment_file, FSEntry> environment_file;
00162         NamedValue<n::image_dir, FSEntry> image_dir;
00163         NamedValue<n::options, MergerOptions> options;
00164         NamedValue<n::package_id, std::tr1::shared_ptr<const PackageID> > package_id;
00165         NamedValue<n::used_this_for_config_protect, std::tr1::function<void (const std::string &)> > used_this_for_config_protect;
00166     };
00167 
00168     /**
00169      * Thrown if a Set does not exist
00170      *
00171      * \ingroup g_exceptions
00172      * \ingroup g_repository
00173      * \nosubgrouping
00174      */
00175     class PALUDIS_VISIBLE NoSuchSetError :
00176         public Exception
00177     {
00178         private:
00179             std::string _name;
00180 
00181         public:
00182             ///\name Basic operations
00183             ///\{
00184 
00185             NoSuchSetError(const std::string & name) throw ();
00186 
00187             virtual ~NoSuchSetError() throw ()
00188             {
00189             }
00190 
00191             ///\}
00192 
00193             /**
00194              * Name of the set.
00195              */
00196             const std::string & name() const
00197             {
00198                 return _name;
00199             }
00200     };
00201 
00202     /**
00203      * Thrown if a Set is recursively defined
00204      *
00205      * \ingroup g_exceptions
00206      * \ingroup g_repository
00207      * \nosubgrouping
00208      */
00209     class PALUDIS_VISIBLE RecursivelyDefinedSetError :
00210         public Exception
00211     {
00212         private:
00213             std::string _name;
00214 
00215         public:
00216             ///\name Basic operations
00217             ///\{
00218 
00219             RecursivelyDefinedSetError(const std::string & name) throw ();
00220 
00221             virtual ~RecursivelyDefinedSetError() throw ()
00222             {
00223             }
00224 
00225             ///\}
00226 
00227             /**
00228              * Name of the set.
00229              */
00230             const std::string & name() const
00231             {
00232                 return _name;
00233             }
00234     };
00235 
00236     /**
00237      * A Repository provides a representation of a physical repository to a
00238      * PackageDatabase.
00239      *
00240      * \ingroup g_repository
00241      * \nosubgrouping
00242      */
00243     class PALUDIS_VISIBLE Repository :
00244         private InstantiationPolicy<Repository, instantiation_method::NonCopyableTag>,
00245         private PrivateImplementationPattern<Repository>,
00246         public RepositoryCapabilities,
00247         public MetadataKeyHolder
00248     {
00249         private:
00250             PrivateImplementationPattern<Repository>::ImpPtr & _imp;
00251 
00252         protected:
00253             ///\name Basic operations
00254             ///\{
00255 
00256             Repository(const Environment * const, const RepositoryName &, const RepositoryCapabilities &);
00257 
00258             ///\}
00259 
00260         public:
00261             ///\name Basic operations
00262             ///\{
00263 
00264             virtual ~Repository();
00265 
00266             ///\}
00267 
00268             ///\name Repository information
00269             ///\{
00270 
00271             /**
00272              * Return our name.
00273              */
00274             const RepositoryName name() const PALUDIS_ATTRIBUTE((nothrow))
00275                 PALUDIS_ATTRIBUTE((warn_unused_result));
00276 
00277             /**
00278              * Are we allowed to be favourite repository?
00279              */
00280             virtual bool can_be_favourite_repository() const;
00281 
00282             ///\}
00283 
00284             ///\name Specific metadata keys
00285             ///\{
00286 
00287             /**
00288              * The format_key, if non-zero, holds our repository's format. Repository
00289              * implementations should not return zero here, but clients should still
00290              * check.
00291              */
00292             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::string> > format_key() const = 0;
00293 
00294             /**
00295              * The location_key, if non-zero, holds the file or directory containing
00296              * our repository's data, the format of which depends on the value of
00297              * format_key.
00298              */
00299             virtual const std::tr1::shared_ptr<const MetadataValueKey<FSEntry> > location_key() const = 0;
00300 
00301             /**
00302              * The installed_root_key, if non-zero, specifies that we contain installed
00303              * packages at the specified root.
00304              *
00305              * This key is currently used in various places to determine whether a repository is
00306              * an 'installed' repository or not.
00307              */
00308             virtual const std::tr1::shared_ptr<const MetadataValueKey<FSEntry> > installed_root_key() const = 0;
00309 
00310             ///\}
00311 
00312             ///\name Repository content queries
00313             ///\{
00314 
00315             /**
00316              * Do we have a category with the given name?
00317              */
00318             virtual bool has_category_named(const CategoryNamePart & c) const = 0;
00319 
00320             /**
00321              * Do we have a package in the given category with the given name?
00322              */
00323             virtual bool has_package_named(const QualifiedPackageName & q) const = 0;
00324 
00325             /**
00326              * Fetch our category names.
00327              */
00328             virtual std::tr1::shared_ptr<const CategoryNamePartSet> category_names() const = 0;
00329 
00330             /**
00331              * Fetch unimportant categories.
00332              */
00333             virtual std::tr1::shared_ptr<const CategoryNamePartSet> unimportant_category_names() const;
00334 
00335             /**
00336              * Fetch categories that contain a named package.
00337              */
00338             virtual std::tr1::shared_ptr<const CategoryNamePartSet> category_names_containing_package(
00339                     const PackageNamePart & p) const;
00340 
00341             /**
00342              * Fetch our package names.
00343              */
00344             virtual std::tr1::shared_ptr<const QualifiedPackageNameSet> package_names(
00345                     const CategoryNamePart & c) const = 0;
00346 
00347             /**
00348              * Fetch our IDs.
00349              */
00350             virtual std::tr1::shared_ptr<const PackageIDSequence> package_ids(const QualifiedPackageName & p) const = 0;
00351 
00352             /**
00353              * Might some of our IDs support a particular action?
00354              *
00355              * Used to optimise PackageDatabase::query. If a repository doesn't
00356              * support, say, InstallAction, a query can skip searching it
00357              * entirely when looking for installable packages.
00358              */
00359             virtual bool some_ids_might_support_action(const SupportsActionTestBase &) const = 0;
00360 
00361             ///\}
00362 
00363             ///\name Repository behaviour methods
00364             ///\{
00365 
00366             /**
00367              * Invalidate any in memory cache.
00368              */
00369             virtual void invalidate() = 0;
00370 
00371             /**
00372              * Invalidate cached masks.
00373              */
00374             virtual void invalidate_masks() = 0;
00375 
00376             /**
00377              * Regenerate any on disk cache.
00378              */
00379             virtual void regenerate_cache() const;
00380 
00381             ///\}
00382 
00383     };
00384 
00385     /**
00386      * Interface for package sets for repositories.
00387      *
00388      * \see Repository
00389      * \ingroup g_repository
00390      * \nosubgrouping
00391      */
00392     class PALUDIS_VISIBLE RepositorySetsInterface
00393     {
00394         public:
00395             ///\name Set queries
00396             ///\{
00397 
00398             /**
00399              * Fetch a package set.
00400              */
00401             virtual std::tr1::shared_ptr<SetSpecTree::ConstItem> package_set(const SetName & s) const = 0;
00402 
00403             /**
00404              * Gives a list of the names of all the sets provided by this repo.
00405              */
00406             virtual std::tr1::shared_ptr<const SetNameSet> sets_list() const
00407                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00408 
00409             ///\}
00410 
00411             virtual ~RepositorySetsInterface();
00412     };
00413 
00414     /**
00415      * Interface for syncing for repositories.
00416      *
00417      * \see Repository
00418      * \ingroup g_repository
00419      * \nosubgrouping
00420      */
00421     class PALUDIS_VISIBLE RepositorySyncableInterface
00422     {
00423         public:
00424             ///\name Sync functions
00425             ///\{
00426 
00427             /**
00428              * Sync, if necessary.
00429              *
00430              * \param output_deviant May be an empty pointer, for no deviation.
00431              * \return True if we synced successfully, false if we skipped sync.
00432              */
00433             virtual bool sync(const std::tr1::shared_ptr<const OutputDeviant> & output_deviant) const = 0;
00434 
00435             ///\}
00436 
00437             virtual ~RepositorySyncableInterface();
00438     };
00439 
00440     /**
00441      * Interface for environment variable querying for repositories.
00442      *
00443      * \see Repository
00444      * \ingroup g_repository
00445      * \nosubgrouping
00446      */
00447     class PALUDIS_VISIBLE RepositoryEnvironmentVariableInterface
00448     {
00449         public:
00450             ///\name Environment query functionality
00451             ///\{
00452 
00453             /**
00454              * Query an environment variable
00455              */
00456             virtual std::string get_environment_variable(
00457                     const std::tr1::shared_ptr<const PackageID> & for_package,
00458                     const std::string & var) const
00459                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00460 
00461             ///\}
00462 
00463             virtual ~RepositoryEnvironmentVariableInterface();
00464     };
00465 
00466     /**
00467      * Interface for mirror querying for repositories.
00468      *
00469      * \see Repository
00470      * \ingroup g_repository
00471      * \nosubgrouping
00472      */
00473     class PALUDIS_VISIBLE RepositoryMirrorsInterface
00474     {
00475         public:
00476             ///\name Iterate over our mirrors
00477             ///\{
00478 
00479             struct MirrorsConstIteratorTag;
00480             typedef WrappedForwardIterator<MirrorsConstIteratorTag,
00481                     const std::pair<const std::string, std::string> > MirrorsConstIterator;
00482 
00483             virtual MirrorsConstIterator begin_mirrors(const std::string & s) const
00484                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00485             virtual MirrorsConstIterator end_mirrors(const std::string & s) const
00486                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00487 
00488             /**
00489              * Is the named item a mirror?
00490              */
00491             bool is_mirror(const std::string & s) const;
00492 
00493             ///\}
00494 
00495             virtual ~RepositoryMirrorsInterface();
00496     };
00497 
00498     /**
00499      * Interface for repositories that define virtuals.
00500      *
00501      * \see Repository
00502      * \ingroup g_repository
00503      * \nosubgrouping
00504      */
00505     class PALUDIS_VISIBLE RepositoryVirtualsInterface
00506     {
00507         public:
00508             ///\name Virtuals functionality
00509             ///\{
00510 
00511             /**
00512              * A collection of virtuals.
00513              */
00514             typedef Sequence<RepositoryVirtualsEntry> VirtualsSequence;
00515 
00516             /**
00517              * Fetch our virtual packages.
00518              */
00519             virtual std::tr1::shared_ptr<const VirtualsSequence> virtual_packages() const
00520                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00521 
00522             ///\}
00523 
00524             virtual ~RepositoryVirtualsInterface();
00525     };
00526 
00527     /**
00528      * Interface for repositories that can make virtuals on the fly.
00529      *
00530      * \see Repository
00531      * \ingroup g_repository
00532      * \nosubgrouping
00533      */
00534     class PALUDIS_VISIBLE RepositoryMakeVirtualsInterface
00535     {
00536         public:
00537             virtual ~RepositoryMakeVirtualsInterface();
00538 
00539             virtual const std::tr1::shared_ptr<const PackageID> make_virtual_package_id(
00540                     const QualifiedPackageName & virtual_name, const std::tr1::shared_ptr<const PackageID> & provider) const
00541                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00542     };
00543 
00544     /**
00545      * Interface for repositories that provide packages.
00546      *
00547      * \see Repository
00548      * \ingroup g_repository
00549      * \nosubgrouping
00550      */
00551     class PALUDIS_VISIBLE RepositoryProvidesInterface
00552     {
00553         public:
00554             ///\name Provides functionality
00555             ///\{
00556 
00557             /**
00558              * A collection of provided packages.
00559              */
00560             typedef Sequence<RepositoryProvidesEntry> ProvidesSequence;
00561 
00562             /**
00563              * Fetch our provided packages.
00564              */
00565             virtual std::tr1::shared_ptr<const ProvidesSequence> provided_packages() const
00566                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00567 
00568             ///\}
00569 
00570             virtual ~RepositoryProvidesInterface();
00571     };
00572 
00573     /**
00574      * Interface for repositories that can be used as an install destination.
00575      *
00576      * \see Repository
00577      * \ingroup g_repository
00578      * \nosubgrouping
00579      */
00580     class PALUDIS_VISIBLE RepositoryDestinationInterface
00581     {
00582         public:
00583             ///\name Destination functions
00584             ///\{
00585 
00586             /**
00587              * Are we a suitable destination for the specified package?
00588              */
00589             virtual bool is_suitable_destination_for(const PackageID &) const
00590                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00591 
00592             /**
00593              * Are we to be included in the Environment::default_destinations list?
00594              */
00595             virtual bool is_default_destination() const
00596                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00597 
00598             /**
00599              * If true, pre and post install phases will be used when writing to this
00600              * destination.
00601              *
00602              * This should return true for 'real' filesystem destinations (whether or
00603              * not root is /, if root merges are supported), and false for intermediate
00604              * destinations such as binary repositories.
00605              */
00606             virtual bool want_pre_post_phases() const
00607                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00608 
00609             /**
00610              * Merge a package.
00611              */
00612             virtual void merge(const MergeParams &) = 0;
00613 
00614             ///\}
00615 
00616             virtual ~RepositoryDestinationInterface();
00617     };
00618 
00619     /**
00620      * Interface for handling ERepository specific functionality.
00621      *
00622      * \see Repository
00623      * \ingroup g_repository
00624      * \nosubgrouping
00625      */
00626     class PALUDIS_VISIBLE RepositoryEInterface
00627     {
00628         public:
00629             ///\name Information about a ERepository
00630             ///\{
00631 
00632             virtual std::string profile_variable(const std::string &) const = 0;
00633             virtual std::string accept_keywords_variable() const = 0;
00634             virtual std::string arch_variable() const = 0;
00635 
00636             ///\}
00637 
00638             ///\name Profile setting and querying functions
00639             ///\{
00640 
00641             typedef RepositoryEInterfaceProfilesDescLine ProfilesDescLine;
00642 
00643             struct ProfilesConstIteratorTag;
00644             typedef WrappedForwardIterator<ProfilesConstIteratorTag, const ProfilesDescLine> ProfilesConstIterator;
00645             virtual ProfilesConstIterator begin_profiles() const = 0;
00646             virtual ProfilesConstIterator end_profiles() const = 0;
00647 
00648             virtual ProfilesConstIterator find_profile(const FSEntry & location) const = 0;
00649             virtual void set_profile(const ProfilesConstIterator & iter) = 0;
00650             virtual void set_profile_by_arch(const std::string &) = 0;
00651 
00652             ///\}
00653 
00654             virtual ~RepositoryEInterface();
00655     };
00656 
00657     /**
00658      * Interface for handling QA tasks.
00659      *
00660      * \see Repository
00661      * \ingroup g_repository
00662      * \nosubgrouping
00663      */
00664     class PALUDIS_VISIBLE RepositoryQAInterface
00665     {
00666         public:
00667             /**
00668              * Perform QA checks on the repository.
00669              */
00670             virtual void check_qa(
00671                     QAReporter &,
00672                     const QACheckProperties &,
00673                     const QACheckProperties &,
00674                     const QAMessageLevel,
00675                     const FSEntry &
00676                     ) const = 0;
00677 
00678             ///\name Basic operations
00679             ///\{
00680 
00681             virtual ~RepositoryQAInterface();
00682 
00683             ///\}
00684     };
00685 
00686     /**
00687      * Interface for making and verifying Manifest2-style manifests
00688      *
00689      * \see Repository
00690      * \ingroup g_repository
00691      * \nosubgrouping
00692      */
00693     class PALUDIS_VISIBLE RepositoryManifestInterface
00694     {
00695         public:
00696             /**
00697              * Makes the Manifest for a given package. Requires that all
00698              * the needed DIST files, etc, have already been fetched.
00699              */
00700             virtual void make_manifest(const QualifiedPackageName &) = 0;
00701 
00702             ///\name Basic operations
00703             ///\{
00704 
00705             virtual ~RepositoryManifestInterface();
00706 
00707             ///\}
00708     };
00709 
00710     /**
00711      * Interface for handling hooks.
00712      *
00713      * \see Repository
00714      * \ingroup g_repository
00715      * \nosubgrouping
00716      */
00717     class PALUDIS_VISIBLE RepositoryHookInterface
00718     {
00719         public:
00720             /**
00721              * Perform a hook.
00722              */
00723             virtual HookResult perform_hook(const Hook & hook) const
00724                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00725 
00726             ///\name Basic operations
00727             ///\{
00728 
00729             virtual ~RepositoryHookInterface();
00730 
00731             ///\}
00732     };
00733 }
00734 
00735 #endif

Generated on Mon Dec 22 19:43:51 2008 for paludis by  doxygen 1.5.7.1