environment.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_ENVIRONMENT_HH
00021 #define PALUDIS_GUARD_PALUDIS_ENVIRONMENT_HH 1
00022 
00023 #include <paludis/environment-fwd.hh>
00024 #include <paludis/util/instantiation_policy.hh>
00025 #include <paludis/util/options-fwd.hh>
00026 #include <paludis/util/fs_entry-fwd.hh>
00027 #include <paludis/util/tribool-fwd.hh>
00028 #include <paludis/name-fwd.hh>
00029 #include <paludis/hook-fwd.hh>
00030 #include <paludis/repository-fwd.hh>
00031 #include <paludis/dep_spec.hh>
00032 #include <paludis/dep_tree.hh>
00033 #include <paludis/package_id-fwd.hh>
00034 #include <paludis/mask-fwd.hh>
00035 #include <paludis/package_database-fwd.hh>
00036 #include <paludis/selection-fwd.hh>
00037 #include <paludis/metadata_key_holder.hh>
00038 #include <paludis/choice-fwd.hh>
00039 
00040 /** \file
00041  * Declarations for the Environment class.
00042  *
00043  * \ingroup g_environment
00044  *
00045  * \section Examples
00046  *
00047  * - \ref example_environment.cc "example_environment.cc"
00048  */
00049 
00050 namespace paludis
00051 {
00052     /**
00053      * Represents a working environment, which contains an available packages
00054      * database and provides various methods for querying package visibility
00055      * and options.
00056      *
00057      * Contains a PackageDatabase, which in turn contains a number of Repository
00058      * instances.
00059      *
00060      * Environment itself is purely an interface class. Actual Environment
00061      * implementations usually descend from EnvironmentImplementation, which
00062      * provides much of the common implementation details. EnvironmentFactory is
00063      * often used to create the appropriate Environment subclass for an
00064      * application.
00065      *
00066      * \ingroup g_environment
00067      * \see PackageDatabase
00068      * \see EnvironmentFactory
00069      * \see EnvironmentImplementation
00070      * \nosubgrouping
00071      */
00072     class PALUDIS_VISIBLE Environment :
00073         private InstantiationPolicy<Environment, instantiation_method::NonCopyableTag>,
00074         public MetadataKeyHolder
00075     {
00076         public:
00077             ///\name Basic operations
00078             ///\{
00079 
00080             virtual ~Environment() = 0;
00081 
00082             ///\}
00083 
00084             ///\name Choice-related queries
00085             ///\{
00086 
00087             /**
00088              * Do we want a choice enabled for a particular package?
00089              *
00090              * Only for use by Repository, to get defaults from the environment.
00091              * Clients should query the metadata key directly.
00092              *
00093              * The third parameter is the name of the value, which might not
00094              * have been created yet.
00095              */
00096             virtual const Tribool want_choice_enabled(
00097                     const std::tr1::shared_ptr<const PackageID> &,
00098                     const std::tr1::shared_ptr<const Choice> &,
00099                     const UnprefixedChoiceName &
00100                     ) const
00101                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00102 
00103             /**
00104              * Return a collection of known value names for a particular
00105              * choice.
00106              *
00107              * Only for use by Repository, to get defaults from the environment.
00108              * Clients should query the metadata key directly.
00109              *
00110              * This is to deal with cases like USE_EXPAND values, where the
00111              * repository doesn't know all possible values.
00112              */
00113             virtual std::tr1::shared_ptr<const Set<UnprefixedChoiceName> > known_choice_value_names(
00114                     const std::tr1::shared_ptr<const PackageID> &,
00115                     const std::tr1::shared_ptr<const Choice> &
00116                     ) const
00117                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00118 
00119             ///\}
00120 
00121             ///\name Mask-related queries
00122             ///\{
00123 
00124             /**
00125              * Do we accept a particular license for a particular package?
00126              *
00127              * Used by PackageID implementations. Generally PackageID's masks methods
00128              * should be used rather than calling this directly.
00129              */
00130             virtual bool accept_license(const std::string &, const PackageID &) const
00131                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00132 
00133             /**
00134              * Do we accept any of the specified keywords for a particular package?
00135              *
00136              * If the collection includes "*", should return true.
00137              *
00138              * Used by PackageID implementations. Generally PackageID's masks methods
00139              * should be used rather than calling this directly.
00140              */
00141             virtual bool accept_keywords(const std::tr1::shared_ptr<const KeywordNameSet> &, const PackageID &) const
00142                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00143 
00144             /**
00145              * Do we have a 'breaks' mask for a particular package?
00146              *
00147              * Returns a zero pointer if no.
00148              *
00149              * Used by PackageID implementations. Generally PackageID's masks methods
00150              * should be used rather than calling this directly.
00151              */
00152             virtual const std::tr1::shared_ptr<const Mask> mask_for_breakage(const PackageID &) const
00153                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00154 
00155             /**
00156              * Do we have a 'user' mask for a particular package?
00157              *
00158              * Returns a zero pointer if no.
00159              *
00160              * Used by PackageID implementations. Generally PackageID's masks methods
00161              * should be used rather than calling this directly.
00162              */
00163             virtual const std::tr1::shared_ptr<const Mask> mask_for_user(const PackageID &) const
00164                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00165 
00166             /**
00167              * Do we have a user unmask for a particular package?
00168              *
00169              * This is only applied to repository and profile style masks, not
00170              * keywords, licences etc. If true, user_mask shouldn't be used.
00171              *
00172              * Used by PackageID implementations. Generally PackageID's masks methods
00173              * should be used rather than calling this directly.
00174              */
00175             virtual bool unmasked_by_user(const PackageID &) const
00176                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00177 
00178             ///\}
00179 
00180             ///\name Database-related functions
00181             ///\{
00182 
00183             virtual std::tr1::shared_ptr<PackageDatabase> package_database()
00184                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00185 
00186             virtual std::tr1::shared_ptr<const PackageDatabase> package_database() const
00187                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00188 
00189             /**
00190              * Select some packages.
00191              */
00192             virtual std::tr1::shared_ptr<PackageIDSequence> operator[] (const Selection &) const
00193                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00194 
00195             ///\}
00196 
00197             ///\name System information
00198             ///\{
00199 
00200             /**
00201              * Return a collection of bashrc files to be used by the various components
00202              * that are implemented in bash.
00203              */
00204             virtual std::tr1::shared_ptr<const FSEntrySequence> bashrc_files() const
00205                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00206 
00207             /**
00208              * Return directories to search for syncer scripts.
00209              */
00210             virtual std::tr1::shared_ptr<const FSEntrySequence> syncers_dirs() const
00211                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00212 
00213             /**
00214              * Return directories to search for fetcher scripts.
00215              */
00216             virtual std::tr1::shared_ptr<const FSEntrySequence> fetchers_dirs() const
00217                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00218 
00219             /**
00220              * Return directories to search for hooks.
00221              */
00222             virtual std::tr1::shared_ptr<const FSEntrySequence> hook_dirs() const
00223                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00224 
00225             /**
00226              * Return the command used to launch paludis (the client).
00227              */
00228             virtual std::string paludis_command() const
00229                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00230 
00231             /**
00232              * Change the command used to launch paludis (the client).
00233              */
00234             virtual void set_paludis_command(const std::string &) = 0;
00235 
00236             /**
00237              * Our root location for installs.
00238              */
00239             virtual const FSEntry root() const = 0;
00240 
00241             /**
00242              * User id to use when reduced privs are permissible.
00243              */
00244             virtual uid_t reduced_uid() const = 0;
00245 
00246             /**
00247              * Group id to use when reduced privs are permissible.
00248              */
00249             virtual gid_t reduced_gid() const = 0;
00250 
00251             /**
00252              * Is the specified package Paludis?
00253              *
00254              * Used by InstallTask to decide whether to exec() after installing
00255              * a package.
00256              */
00257             virtual bool is_paludis_package(const QualifiedPackageName &) const
00258                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00259 
00260             ///\}
00261 
00262             ///\name Mirror information
00263             ///\{
00264 
00265             /**
00266              * Return the mirror URI prefixes for a named mirror.
00267              */
00268             virtual std::tr1::shared_ptr<const MirrorsSequence> mirrors(const std::string &) const
00269                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00270 
00271             ///\}
00272 
00273             ///\name Package sets
00274             ///\{
00275 
00276             /**
00277              * Return all known named sets.
00278              */
00279             virtual std::tr1::shared_ptr<const SetNameSet> set_names() const
00280                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00281 
00282             /**
00283              * Return a named set.
00284              *
00285              * If the named set is not known, returns a zero pointer.
00286              */
00287             virtual std::tr1::shared_ptr<SetSpecTree::ConstItem> set(const SetName &) const
00288                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00289 
00290             ///\}
00291 
00292             ///\name Destination information
00293             ///\{
00294 
00295             /**
00296              * Default destination candidates for installing packages.
00297              */
00298             virtual std::tr1::shared_ptr<const DestinationsSet> default_destinations() const
00299                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00300 
00301             ///\}
00302 
00303             ///\name Hook methods
00304             ///\{
00305 
00306             /**
00307              * Perform a hook.
00308              */
00309             virtual HookResult perform_hook(const Hook &) const
00310                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00311 
00312             ///\}
00313 
00314             ///\name Distribution information
00315             ///\{
00316 
00317             virtual std::string distribution() const
00318                 PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
00319 
00320             ///\}
00321 
00322             ///\name World functionality
00323             ///\{
00324 
00325             /**
00326              * Add this package to world.
00327              */
00328             virtual void add_to_world(const QualifiedPackageName &) const = 0;
00329 
00330             /**
00331              * Add this set to world.
00332              */
00333             virtual void add_to_world(const SetName &) const = 0;
00334 
00335             /**
00336              * Remove this package from world, if it is present.
00337              */
00338             virtual void remove_from_world(const QualifiedPackageName &) const = 0;
00339 
00340             /**
00341              * Remove this set from world, if it is present.
00342              */
00343             virtual void remove_from_world(const SetName &) const = 0;
00344 
00345             ///\}
00346 
00347             ///\name Specific metadata keys
00348             ///\{
00349 
00350             /**
00351              * The format_key, if non-zero, holds our environment's format. Environment
00352              * implementations should not return zero here, but clients should still
00353              * check.
00354              */
00355             virtual const std::tr1::shared_ptr<const MetadataValueKey<std::string> > format_key() const = 0;
00356 
00357             /**
00358              * The config_location_key, if non-zero, specifies the location of the configuration file or directory,
00359              * the contents of which depends on the format returned by format_key.
00360              */
00361             virtual const std::tr1::shared_ptr<const MetadataValueKey<FSEntry> > config_location_key() const = 0;
00362 
00363             ///\}
00364     };
00365 }
00366 
00367 #endif

Generated on Sun Nov 30 23:01:32 2008 for paludis by  doxygen 1.5.5