Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / solver / detail / SolverQueueItemLock.cc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SolverQueueItem.cc
3  *
4  * Copyright (C) 2008 SUSE Linux Products GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 extern "C"
21 {
22 #include <solv/solver.h>
23 }
24
25 #define ZYPP_USE_RESOLVER_INTERNALS
26
27 #include "zypp/base/Logger.h"
28 #include "zypp/solver/detail/SolverQueueItemLock.h"
29
30 /////////////////////////////////////////////////////////////////////////
31 namespace zypp
32 { ///////////////////////////////////////////////////////////////////////
33   ///////////////////////////////////////////////////////////////////////
34   namespace solver
35   { /////////////////////////////////////////////////////////////////////
36     /////////////////////////////////////////////////////////////////////
37     namespace detail
38     { ///////////////////////////////////////////////////////////////////
39
40 using namespace std;
41
42 IMPL_PTR_TYPE(SolverQueueItemLock);
43
44 //---------------------------------------------------------------------------
45
46 std::ostream &
47 SolverQueueItemLock::dumpOn( std::ostream & os ) const
48 {
49     os << "[" << (_soft?"Soft":"") << "Lock: " <<
50         _item << "]";
51
52     return os;
53 }
54
55 //---------------------------------------------------------------------------
56
57 SolverQueueItemLock::SolverQueueItemLock (const ResPool & pool,
58                                               const PoolItem & item, bool soft)
59     : SolverQueueItem (QUEUE_ITEM_TYPE_LOCK, pool)
60     , _item (item)
61     , _soft (soft)
62 {
63 }
64
65
66 SolverQueueItemLock::~SolverQueueItemLock()
67 {
68 }
69
70 //---------------------------------------------------------------------------
71
72 bool SolverQueueItemLock::addRule (sat::detail::CQueue & q)
73 {
74     ::Id id = _item.satSolvable().id();
75     if (id == ID_NULL) {
76         ERR << "Lock : " << _item << " not found" << endl;
77         return false;
78     }
79     MIL << "Lock " << _item << " with the SAT-Pool ID: " << id << endl;
80     if (_item.status().isInstalled()) {
81         if (_soft) {
82             queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE | SOLVER_WEAK );
83         } else {
84             queue_push( &(q), SOLVER_INSTALL | SOLVER_SOLVABLE );
85         }
86     } else {
87         if (_soft) {
88             queue_push( &(q), SOLVER_ERASE | SOLVER_SOLVABLE | SOLVER_WEAK );
89         } else {
90             queue_push( &(q), SOLVER_ERASE | SOLVER_SOLVABLE );
91         }
92     }
93     queue_push( &(q), id );
94     return true;
95 }
96
97 SolverQueueItem_Ptr
98 SolverQueueItemLock::copy (void) const
99 {
100     SolverQueueItemLock_Ptr new_lock = new SolverQueueItemLock (pool(), _item);
101     new_lock->SolverQueueItem::copy(this);
102
103     new_lock->_soft = _soft;
104     return new_lock;
105 }
106
107 int
108 SolverQueueItemLock::cmp (SolverQueueItem_constPtr item) const
109 {
110     int cmp = this->compare (item);
111     if (cmp != 0)
112         return cmp;
113     SolverQueueItemLock_constPtr lock = dynamic_pointer_cast<const SolverQueueItemLock>(item);
114     return compareByNVRA (_item, lock->_item);
115 }
116
117
118 //---------------------------------------------------------------------------
119
120
121 ///////////////////////////////////////////////////////////////////
122     };// namespace detail
123     /////////////////////////////////////////////////////////////////////
124     /////////////////////////////////////////////////////////////////////
125   };// namespace solver
126   ///////////////////////////////////////////////////////////////////////
127   ///////////////////////////////////////////////////////////////////////
128 };// namespace zypp
129 /////////////////////////////////////////////////////////////////////////