libzypp  10.5.0
SolverQueueItemLock.cc
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* SolverQueueItem.cc
00003  *
00004  * Copyright (C) 2008 SUSE Linux Products GmbH
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License,
00008  * version 2, as published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018  * 02111-1307, USA.
00019  */
00020 extern "C"
00021 {
00022 #include <solv/solver.h>
00023 }
00024 
00025 #include "zypp/base/Logger.h"
00026 #include "zypp/solver/detail/SolverQueueItemLock.h"
00027 
00029 namespace zypp
00030 { 
00031 
00032   namespace solver
00033   { 
00034 
00035     namespace detail
00036     { 
00037 
00038 using namespace std;
00039 
00040 IMPL_PTR_TYPE(SolverQueueItemLock);
00041 
00042 //---------------------------------------------------------------------------
00043 
00044 std::ostream &
00045 SolverQueueItemLock::dumpOn( std::ostream & os ) const
00046 {
00047     os << "[" << (_soft?"Soft":"") << "Lock: " <<
00048         _item << "]";
00049 
00050     return os;
00051 }
00052 
00053 //---------------------------------------------------------------------------
00054 
00055 SolverQueueItemLock::SolverQueueItemLock (const ResPool & pool,
00056                                               const PoolItem & item, bool soft)
00057     : SolverQueueItem (QUEUE_ITEM_TYPE_LOCK, pool)
00058     , _item (item)
00059     , _soft (soft)
00060 {
00061 }
00062 
00063 
00064 SolverQueueItemLock::~SolverQueueItemLock()
00065 {
00066 }
00067 
00068 //---------------------------------------------------------------------------
00069 
00070 bool SolverQueueItemLock::addRule (_Queue & q)
00071 {
00072     ::Id id = _item.satSolvable().id();
00073     if (id == ID_NULL) {
00074         ERR << "Lock : " << _item << " not found" << endl;
00075         return false;
00076     }
00077     MIL << "Lock " << _item << " with the SAT-Pool ID: " << id << endl;
00078     if (_item.status().isInstalled()) {
00079         if (_soft) {
00080             queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE | SOLVER_WEAK );
00081         } else {
00082             queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE );
00083         }
00084     } else {
00085         if (_soft) {
00086             queue_push( &(q), SOLVER_ERASE | SOLVER_SOLVABLE | SOLVER_WEAK );
00087         } else {
00088             queue_push( &(q), SOLVER_ERASE | SOLVER_SOLVABLE );
00089         }
00090     }
00091     queue_push( &(q), id );
00092     return true;
00093 }
00094 
00095 SolverQueueItem_Ptr
00096 SolverQueueItemLock::copy (void) const
00097 {
00098     SolverQueueItemLock_Ptr new_lock = new SolverQueueItemLock (pool(), _item);
00099     new_lock->SolverQueueItem::copy(this);
00100 
00101     new_lock->_soft = _soft;
00102     return new_lock;
00103 }
00104 
00105 int
00106 SolverQueueItemLock::cmp (SolverQueueItem_constPtr item) const
00107 {
00108     int cmp = this->compare (item);
00109     if (cmp != 0)
00110         return cmp;
00111     SolverQueueItemLock_constPtr lock = dynamic_pointer_cast<const SolverQueueItemLock>(item);
00112     return compareByNVRA (_item.resolvable(), lock->_item.resolvable());
00113 }
00114 
00115 
00116 //---------------------------------------------------------------------------
00117 
00118 
00120     };// namespace detail
00123   };// namespace solver
00126 };// namespace zypp