added lock request; bugfix in wead dependency
[platform/upstream/libzypp.git] / zypp / solver / detail / SolverQueueItemInstall.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
21 #include "zypp/base/Logger.h"
22 #include "zypp/solver/detail/SolverQueueItemInstall.h"
23
24 /////////////////////////////////////////////////////////////////////////
25 namespace zypp 
26 { ///////////////////////////////////////////////////////////////////////
27   ///////////////////////////////////////////////////////////////////////
28   namespace solver
29   { /////////////////////////////////////////////////////////////////////
30     /////////////////////////////////////////////////////////////////////
31     namespace detail
32     { ///////////////////////////////////////////////////////////////////
33
34 using namespace std;
35
36 IMPL_PTR_TYPE(SolverQueueItemInstall);
37
38 //---------------------------------------------------------------------------
39
40 std::ostream &
41 SolverQueueItemInstall::dumpOn( std::ostream & os ) const
42 {
43     os << "[" << (_soft?"Soft":"") << "Install: "
44     << _name
45     << "]";
46     
47     return os;
48 }
49
50 //---------------------------------------------------------------------------
51
52 SolverQueueItemInstall::SolverQueueItemInstall (const ResPool & pool, std::string name, bool soft)
53     : SolverQueueItem (QUEUE_ITEM_TYPE_INSTALL, pool)
54     , _name (name)
55     , _soft (soft)
56 {
57 }
58
59
60 SolverQueueItemInstall::~SolverQueueItemInstall()
61 {
62 }
63
64 //---------------------------------------------------------------------------
65
66 bool SolverQueueItemInstall::addRule (Queue & q, Pool *SATPool)
67 {
68     Id id = str2id( SATPool, _name.c_str(), 0 );
69     if (_soft) {    
70         queue_push( &(q), SOLVER_INSTALL_SOLVABLE_NAME | SOLVER_WEAK  );
71     } else {
72         queue_push( &(q), SOLVER_INSTALL_SOLVABLE_NAME );
73     }
74     queue_push( &(q), id);
75
76     MIL << "Install " << _name << (_soft ? "(soft)" : "")
77         << " with SAT-Pooly: " << id << endl;        
78     return true;
79 }
80
81 SolverQueueItem_Ptr
82 SolverQueueItemInstall::copy (void) const
83 {
84     SolverQueueItemInstall_Ptr new_install = new SolverQueueItemInstall (pool(), _name);
85     new_install->SolverQueueItem::copy(this);
86
87     new_install->_soft = _soft;
88     return new_install;
89 }
90
91 int
92 SolverQueueItemInstall::cmp (SolverQueueItem_constPtr item) const
93 {
94     int cmp = this->compare (item);
95     if (cmp != 0)
96         return cmp;
97     SolverQueueItemInstall_constPtr ins = dynamic_pointer_cast<const SolverQueueItemInstall>(item);
98     if (_name != ins->_name) {
99         return _name.compare(ins->_name);
100     } else {
101         if (_soft == ins->_soft) {
102             return 0;
103         } else {
104             if (_soft)
105                 return 1;
106             else
107                 return -1;
108         }
109     }
110 }
111
112
113 //---------------------------------------------------------------------------
114
115
116 ///////////////////////////////////////////////////////////////////
117     };// namespace detail
118     /////////////////////////////////////////////////////////////////////
119     /////////////////////////////////////////////////////////////////////
120   };// namespace solver
121   ///////////////////////////////////////////////////////////////////////
122   ///////////////////////////////////////////////////////////////////////
123 };// namespace zypp
124 /////////////////////////////////////////////////////////////////////////