ResolverInfo.cc

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* ResolverInfo.cc
00003  *
00004  * Copyright (C) 2000-2002 Ximian, Inc.
00005  * Copyright (C) 2005 SUSE Linux Products GmbH
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #include <map>
00023 #include <sstream>
00024 
00025 #include "zypp/solver/detail/ResolverInfo.h"
00026 #include "zypp/Source.h"
00027 #include "zypp/Capability.h"
00028 #include "zypp/base/String.h"
00029 #include "zypp/base/Gettext.h"
00030 #include "zypp/base/Logger.h"
00031 
00033 namespace zypp 
00034 { 
00035 
00036   namespace solver
00037   { 
00038 
00039     namespace detail
00040     { 
00041 
00042 using namespace std;
00043 
00044 IMPL_PTR_TYPE(ResolverInfo);
00045 
00046 //---------------------------------------------------------------------------
00047 
00048 #define RIT(x) RESOLVER_INFO_TYPE_ ## x, #x
00049 static struct {
00050     ResolverInfoType type;
00051     const char  *typestr;
00052     const char  *str;
00053 } type_str_table[] = {
00054     { RIT(NEEDED_BY),                   "needed_by" },
00055     { RIT(CONFLICTS_WITH),              "conflicts_with" },
00056     { RIT(OBSOLETES),                   "obsoletes" },
00057     { RIT(DEPENDS_ON),                  "depended_on" },
00058     { RIT(CHILD_OF),                    "child_of" },
00059     { RIT(MISSING_REQ),                 "missing_req" },
00060 
00061     { RIT(INVALID_SOLUTION),            "Marking this resolution attempt as invalid" },
00062     { RIT(UNINSTALLABLE),               "Marking p as uninstallable" },
00063     { RIT(REJECT_INSTALL),              "p is scheduled to be installed, but this is not possible because of dependency problems." },
00064     { RIT(INSTALL_TO_BE_UNINSTALLED),   "Can't install p since it is already marked as needing to be uninstalled" },
00065     { RIT(INSTALL_UNNEEDED),            "Can't install p since it is does not apply to this system." },
00066     { RIT(INSTALL_PARALLEL),            "Can't install p, since a resolvable of the same name is already marked as needing to be installed." },
00067     { RIT(INCOMPLETES),                 "This would invalidate p" },
00068         // from QueueItemEstablish
00069     { RIT(ESTABLISHING),                "Establishing p" },
00070         // from QueueItemInstall
00071     { RIT(INSTALLING),                  "Installing p" },
00072     { RIT(UPDATING),                    "Updating p" },
00073     { RIT(SKIPPING),                    "Skipping p, already installed" },
00074         // from QueueItemRequire
00075     { RIT(NO_OTHER_PROVIDER),           "There are no alternative installed providers of c [for p]" },
00076     { RIT(NO_PROVIDER),                 "There are no installable providers of c [for p]" },
00077     { RIT(NO_UPGRADE),                  "Upgrade to q to avoid removing p is not possible." },
00078     { RIT(UNINSTALL_PROVIDER),          "p provides c but is scheduled to be uninstalled" },
00079     { RIT(PARALLEL_PROVIDER),           "p provides c but another version is already installed" },
00080     { RIT(NOT_INSTALLABLE_PROVIDER),    "p provides c but is uninstallable" },
00081     { RIT(LOCKED_PROVIDER),             "p provides c but is locked" },
00082     { RIT(OTHER_ARCH_PROVIDER),         "p provides c but has other architecture" },
00083     { RIT(CANT_SATISFY),                "Can't satisfy requirement c" },
00084         // from QueueItemUninstall
00085     { RIT(UNINSTALL_TO_BE_INSTALLED),   "p is to-be-installed, so it won't be unlinked." },
00086     { RIT(UNINSTALL_INSTALLED),         "p is required by installed, so it won't be unlinked." },
00087     { RIT(UNINSTALL_LOCKED),            "cant uninstall, its locked" },
00088         // from QueueItemConflict
00089     { RIT(CONFLICT_CANT_INSTALL),       "to-be-installed p conflicts with q due to c" },
00090     { RIT(CONFLICT_UNINSTALLABLE),      "uninstalled p is marked uninstallable it conflicts [with q] due to c" },
00091     { RIT(INVALID),                     "invalid" },
00092     { RIT(INVALID), NULL }
00093 };
00094 #undef RIT
00095 
00096 static const char *
00097 info_type_to_string (ResolverInfoType type)
00098 {
00099     int i;
00100 
00101     for (i = 0; type_str_table[i].str != NULL; ++i) {
00102         if (type == type_str_table[i].type)
00103             return type_str_table[i].typestr;
00104     }
00105 
00106     return "?ResolverInfoType?";
00107 }
00108 
00109 
00110 static const char *
00111 info_type_to_message (ResolverInfoType type)
00112 {
00113     int i;
00114 
00115     for (i = 0; type_str_table[i].str != NULL; ++i) {
00116         if (type == type_str_table[i].type)
00117             return type_str_table[i].str;
00118     }
00119 
00120     return "?ResolverInfoType?";
00121 }
00122 
00123 
00124 ResolverInfoType
00125 resolver_info_type_from_string (const char *str)
00126 {
00127     int i;
00128 
00129     if (str == NULL) return RESOLVER_INFO_TYPE_INVALID;
00130 
00131     for (i = 0; type_str_table[i].str != NULL; ++i) {
00132         if (strcasecmp (str, type_str_table[i].str) == 0)
00133             return type_str_table[i].type;
00134     }
00135 
00136     return RESOLVER_INFO_TYPE_INVALID;
00137 }
00138 
00139 string
00140 ResolverInfo::toString (PoolItem_Ref item)
00141 {
00142     ostringstream os;
00143     if (!item) return "";
00144 
00145     if (item->kind() != ResTraits<zypp::Package>::kind)
00146         os << item->kind() << ':';
00147     os  << item->name() << '-' << item->edition();
00148     if (item->arch() != "") {
00149         os << '.' << item->arch();
00150     }
00151     Source_Ref s = item->source();
00152     if (s) {
00153         string alias = s.alias();
00154         if (!alias.empty()
00155             && alias != "@system")
00156         {
00157             os << '[' << s.alias() << ']';
00158         }
00159     }
00160     return os.str();
00161 }
00162 
00163 
00164 string
00165 ResolverInfo::toString (const Capability & capability)
00166 {
00167     ostringstream os;
00168     os << capability.asString();
00169     return os.str();
00170 }
00171 
00172 string
00173 ResolverInfo::message( ) const
00174 {
00175     return string(info_type_to_message(_type)) + " " + toString(_affected);
00176 }
00177 //---------------------------------------------------------------------------
00178 
00179 std::ostream &
00180 ResolverInfo::dumpOn( std::ostream & os ) const
00181 {
00182     os << "ResolverInfo<";
00183     os << info_type_to_string (_type);
00184     os << "> ";
00185 
00186     if (_affected) {
00187         os << toString (_affected);
00188     }
00189 
00190     if (_error) os << _(" Error!");
00191     if (_important) os << _(" Important!");
00192 
00193     return os;
00194 }
00195 
00196 //---------------------------------------------------------------------------
00197 
00198 ResolverInfo::ResolverInfo (ResolverInfoType type, PoolItem_Ref item, int priority)
00199     : _type (type)
00200     , _affected (item)
00201     , _priority (priority)
00202     , _error (false)
00203     , _important (false)
00204 {
00205     _XDEBUG(*this);
00206 }
00207 
00208 
00209 ResolverInfo::~ResolverInfo()
00210 {
00211 }
00212 
00213 //---------------------------------------------------------------------------
00214 
00215 bool
00216 ResolverInfo::merge (ResolverInfo_Ptr to_be_merged)
00217 {
00218     if (to_be_merged == NULL) return false;
00219 
00220     if (_type != to_be_merged->_type
00221         || _affected != to_be_merged->_affected
00222         || _error != to_be_merged->_error) {
00223         return false;
00224     }
00225 
00226     return true;
00227 }
00228 
00229 void
00230 ResolverInfo::copy (ResolverInfo_constPtr from)
00231 {
00232     _error = from->_error;
00233     _important = from->_important;
00234 }
00235 
00236 
00237 ResolverInfo_Ptr
00238 ResolverInfo::copy (void) const
00239 {
00240     ResolverInfo_Ptr cpy = new ResolverInfo(_type, _affected, _priority);
00241 
00242     cpy->copy (this);
00243  
00244     return cpy;
00245 }
00246 
00247 
00248 //---------------------------------------------------------------------------
00249 
00250 bool
00251 ResolverInfo::isAbout (PoolItem_Ref item) const
00252 {
00253     if (!_affected)
00254         return false;
00255 
00256     return _affected->name() == item->name();
00257 }
00258   
00260     };// namespace detail
00263   };// namespace solver
00266 };// namespace zypp
00268 

Generated on Thu Jul 6 00:07:23 2006 for zypp by  doxygen 1.4.6