libzypp  10.5.0
SolutionAction.cc
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* SolutionAction.cc
00003  *
00004  * Easy-to use interface to the ZYPP dependency resolver
00005  *
00006  * Copyright (C) 2000-2002 Ximian, Inc.
00007  * Copyright (C) 2005 SUSE Linux Products GmbH
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License,
00011  * version 2, as published by the Free Software Foundation.
00012  *
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00021  * 02111-1307, USA.
00022  */
00023 
00024 #include "zypp/solver/detail/Resolver.h"
00025 #include "zypp/solver/detail/SolutionAction.h"
00026 #include "zypp/Capabilities.h"
00027 #include "zypp/base/Logger.h"
00028 
00030 namespace zypp
00031 { 
00032 
00033   namespace solver
00034   { 
00035 
00036     namespace detail
00037     { 
00038 
00039 using namespace std;
00040 
00041 IMPL_PTR_TYPE(SolutionAction);
00042 IMPL_PTR_TYPE(TransactionSolutionAction);
00043 IMPL_PTR_TYPE(InjectSolutionAction);
00044 
00045 //---------------------------------------------------------------------------
00046 
00047 SolutionAction::SolutionAction()
00048 {
00049 }
00050 
00051 
00052 SolutionAction::~SolutionAction()
00053 {
00054 }
00055 
00056 
00057 //---------------------------------------------------------------------------
00058 
00059 ostream &
00060 TransactionSolutionAction::dumpOn( ostream& os) const
00061 {
00062     os << "TransactionSolutionAction: ";
00063     switch (_action) {
00064         case KEEP:                      os << "Keep " << _item; break;
00065         case INSTALL:                   os << "Install " << _item; break;
00066         case REMOVE:                    os << "Remove " << _item; break;
00067         case UNLOCK:                    os << "Unlock " << _item; break;
00068         case LOCK:                      os << "Lock " << _item; break;
00069         case REMOVE_EXTRA_REQUIRE:      os << "Remove require " << _capability; break;
00070         case REMOVE_EXTRA_CONFLICT:     os << "Remove conflict " << _capability; break;
00071         case ADD_SOLVE_QUEUE_ITEM:      os << "Add SolveQueueItem " <<  _solverQueueItem; break;
00072         case REMOVE_SOLVE_QUEUE_ITEM:   os << "Remove SolveQueueItem " <<  _solverQueueItem; break;
00073     }
00074 
00075     os << endl;
00076     return os;
00077 }
00078 
00079 
00080 ostream&
00081 operator<<( ostream& os, const SolutionActionList & actionlist)
00082 {
00083     for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
00084         os << *(*iter);
00085         os << endl;
00086     }
00087     return os;
00088 }
00089 
00090 
00091 ostream&
00092 operator<<( ostream& os, const CSolutionActionList & actionlist)
00093 {
00094     for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
00095         os << *(*iter);
00096         os << endl;
00097     }
00098     return os;
00099 }
00100 
00101 //---------------------------------------------------------------------------
00102 
00103 ostream &
00104 InjectSolutionAction::dumpOn( ostream& os ) const
00105 {
00106     os << "InjectSolutionAction: ";
00107     switch (_kind) {
00108         case WEAK:      os << "Weak"; break;
00109         default: os << "Wrong kind"; break;
00110     }
00111     os << " ";
00112     os << _item;
00113     os << endl;
00114     return os;
00115 }
00116 
00117 //---------------------------------------------------------------------------
00118 
00119 
00120 ostream &
00121 SolutionAction::dumpOn( std::ostream & os ) const
00122 {
00123     os << "SolutionAction<";
00124     os << "not specified";
00125     os << "> ";
00126     return os;
00127 }
00128 
00129 
00130 bool
00131 TransactionSolutionAction::execute(Resolver & resolver) const
00132 {
00133     bool ret = true;
00134     switch (action()) {
00135         case KEEP:
00136             _item.status().resetTransact (ResStatus::USER);
00137             ret = _item.status().setTransact (false, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
00138             break;
00139         case INSTALL:
00140             if (_item.status().isToBeUninstalled())
00141                 ret = _item.status().setTransact (false, ResStatus::USER);
00142             else
00143                 _item.status().setToBeInstalled (ResStatus::USER);
00144             break;
00145         case REMOVE:
00146             if (_item.status().isToBeInstalled()) {
00147                 _item.status().setTransact (false,ResStatus::USER);
00148                 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
00149             } else if (_item.status().isInstalled())
00150                 _item.status().setToBeUninstalled (ResStatus::USER);
00151             else
00152                 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
00153             break;
00154         case UNLOCK:
00155             ret = _item.status().setLock (false, ResStatus::USER);
00156             if (!ret) ERR << "Cannot unlock " << _item << endl;
00157             break;
00158         case LOCK:
00159             _item.status().resetTransact (ResStatus::USER);
00160             ret = _item.status().setLock (true, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
00161             if (!ret) ERR << "Cannot lock " << _item << endl;
00162             break;          
00163         case REMOVE_EXTRA_REQUIRE:
00164             resolver.removeExtraRequire (_capability);
00165             break;
00166         case REMOVE_EXTRA_CONFLICT:
00167             resolver.removeExtraConflict (_capability);
00168             break;
00169         case ADD_SOLVE_QUEUE_ITEM:
00170             resolver.addQueueItem(_solverQueueItem);
00171             break;
00172         case REMOVE_SOLVE_QUEUE_ITEM:
00173             resolver.removeQueueItem(_solverQueueItem);
00174             break;
00175         default:
00176             ERR << "Wrong TransactionKind" << endl;
00177             ret = false;
00178     }
00179     return ret;
00180 }
00181 
00182 bool
00183 InjectSolutionAction::execute(Resolver & resolver) const
00184 {
00185     switch (_kind) {
00186         case WEAK:
00187             // set item dependencies to weak
00188             resolver.addWeak (_item);
00189             break;
00190         default:
00191             ERR << "No valid InjectSolutionAction kind found" << endl;
00192             return false;
00193     }
00194 
00195     return true;
00196 }
00197 
00199     };// namespace detail
00202   };// namespace solver
00205 };// namespace zypp