added solutions for ResolveQueue
[platform/upstream/libzypp.git] / zypp / solver / detail / SolutionAction.cc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* SolutionAction.cc
3  *
4  * Easy-to use interface to the ZYPP dependency resolver
5  *
6  * Copyright (C) 2000-2002 Ximian, Inc.
7  * Copyright (C) 2005 SUSE Linux Products GmbH
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License,
11  * version 2, as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307, USA.
22  */
23
24 #include "zypp/solver/detail/Resolver.h"
25 #include "zypp/solver/detail/SolutionAction.h"
26 #include "zypp/Capabilities.h"
27 #include "zypp/base/Logger.h"
28 #include "zypp/Dependencies.h"
29
30
31 /////////////////////////////////////////////////////////////////////////
32 namespace zypp
33 { ///////////////////////////////////////////////////////////////////////
34   ///////////////////////////////////////////////////////////////////////
35   namespace solver
36   { /////////////////////////////////////////////////////////////////////
37     /////////////////////////////////////////////////////////////////////
38     namespace detail
39     { ///////////////////////////////////////////////////////////////////
40
41 using namespace std;
42
43 IMPL_PTR_TYPE(SolutionAction);
44 IMPL_PTR_TYPE(TransactionSolutionAction);
45 IMPL_PTR_TYPE(InjectSolutionAction);
46
47 //---------------------------------------------------------------------------
48
49 SolutionAction::SolutionAction()
50 {
51 }
52
53
54 SolutionAction::~SolutionAction()
55 {
56 }
57
58
59 //---------------------------------------------------------------------------
60
61 ostream &
62 TransactionSolutionAction::dumpOn( ostream& os) const
63 {
64     os << "TransactionSolutionAction: ";
65     switch (_action) {
66         case KEEP:                      os << "Keep " << _item; break;
67         case INSTALL:                   os << "Install " << _item; break;
68         case REMOVE:                    os << "Remove " << _item; break;
69         case UNLOCK:                    os << "Unlock " << _item; break;
70         case REMOVE_EXTRA_REQUIRE:      os << "Remove require " << _capability; break;
71         case REMOVE_EXTRA_CONFLICT:     os << "Remove conflict " << _capability; break;
72         case ADD_SOLVE_QUEUE_ITEM:      os << "Add SolveQueueItem " <<  _solverQueueItem; break;
73         case REMOVE_SOLVE_QUEUE_ITEM:   os << "Remove SolveQueueItem " <<  _solverQueueItem; break;         
74     }
75
76     os << endl;
77     return os;
78 }
79
80
81 ostream&
82 operator<<( ostream& os, const SolutionActionList & actionlist)
83 {
84     for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
85         os << *(*iter);
86         os << endl;
87     }
88     return os;
89 }
90
91
92 ostream&
93 operator<<( ostream& os, const CSolutionActionList & actionlist)
94 {
95     for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
96         os << *(*iter);
97         os << endl;
98     }
99     return os;
100 }
101
102 //---------------------------------------------------------------------------
103
104 ostream &
105 InjectSolutionAction::dumpOn( ostream& os ) const
106 {
107     os << "InjectSolutionAction: ";
108     switch (_kind) {
109         case WEAK:      os << "Weak"; break;
110         default: os << "Wrong kind"; break;
111     }
112     os << " ";
113     os << _item;
114     os << endl;
115     return os;
116 }
117
118 //---------------------------------------------------------------------------
119
120
121 ostream &
122 SolutionAction::dumpOn( std::ostream & os ) const
123 {
124     os << "SolutionAction<";
125     os << "not specified";
126     os << "> ";
127     return os;
128 }
129
130
131 bool
132 TransactionSolutionAction::execute(Resolver & resolver) const
133 {
134     bool ret = true;
135     switch (action()) {
136         case KEEP:
137             /*FALLTHRU*/
138         case INSTALL:
139             if (_item.status().isToBeUninstalled())
140                 ret = _item.status().setTransact (false, ResStatus::USER);
141             else
142                 _item.status().setToBeInstalled (ResStatus::USER);
143             break;
144         case REMOVE:
145             if (_item.status().isToBeInstalled()) {
146                 _item.status().setTransact (false,ResStatus::USER);
147                 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
148             } else if (_item.status().isInstalled())
149                 _item.status().setToBeUninstalled (ResStatus::USER);
150             else
151                 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
152             break;
153         case UNLOCK:
154             ret = _item.status().setLock (false, ResStatus::USER);
155             if (!ret) ERR << "Cannot unlock " << _item << endl;
156             break;
157         case REMOVE_EXTRA_REQUIRE:
158             resolver.removeExtraRequire (_capability);
159             break;          
160         case REMOVE_EXTRA_CONFLICT:
161             resolver.removeExtraConflict (_capability);
162             break;
163         case ADD_SOLVE_QUEUE_ITEM:
164             resolver.addQueueItem(_solverQueueItem);
165             break;
166         case REMOVE_SOLVE_QUEUE_ITEM:
167             resolver.removeQueueItem(_solverQueueItem);
168             break;
169         default:
170             ERR << "Wrong TransactionKind" << endl;
171             ret = false;
172     }
173     return ret;
174 }
175
176 bool
177 InjectSolutionAction::execute(Resolver & resolver) const
178 {
179     switch (_kind) {
180         case WEAK:
181             // set item dependencies to weak
182             resolver.addWeak (_item);
183             break;
184         default:
185             ERR << "No valid InjectSolutionAction kind found" << endl;
186             return false;
187     }
188
189     return true;
190 }
191
192       ///////////////////////////////////////////////////////////////////
193     };// namespace detail
194     /////////////////////////////////////////////////////////////////////
195     /////////////////////////////////////////////////////////////////////
196   };// namespace solver
197   ///////////////////////////////////////////////////////////////////////
198   ///////////////////////////////////////////////////////////////////////
199 };// namespace zypp
200 /////////////////////////////////////////////////////////////////////////