libzypp 17.31.0
SolutionAction.cc
Go to the documentation of this file.
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#define ZYPP_USE_RESOLVER_INTERNALS
25
26#include <zypp/solver/detail/Resolver.h>
29#include <zypp/Capabilities.h>
30#include <zypp/base/Logger.h>
31
32using std::endl;
33
35namespace zypp
36{
38 namespace solver
39 {
41 namespace detail
42 {
43
44
45IMPL_PTR_TYPE(SolutionAction);
46
47//---------------------------------------------------------------------------
48
49SolutionAction::SolutionAction()
50{
51}
52
53
54SolutionAction::~SolutionAction()
55{
56}
57
58
59//---------------------------------------------------------------------------
60
61std::ostream &
62TransactionSolutionAction::dumpOn( std::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 LOCK: os << "Lock " << _item; break;
71 case REMOVE_EXTRA_REQUIRE: os << "Remove require " << _capability; break;
72 case REMOVE_EXTRA_CONFLICT: os << "Remove conflict " << _capability; break;
73 case ADD_SOLVE_QUEUE_ITEM: os << "Add SolveQueueItem " << _solverQueueItem; break;
74 case REMOVE_SOLVE_QUEUE_ITEM: os << "Remove SolveQueueItem " << _solverQueueItem; break;
75 }
76 return os;
77}
78
79
80std::ostream&
81operator<<( std::ostream& os, const SolutionActionList & actionlist)
82{
83 for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
84 os << *(*iter);
85 os << endl;
86 }
87 return os;
88}
89
90//---------------------------------------------------------------------------
91
92std::ostream &
93InjectSolutionAction::dumpOn( std::ostream& os ) const
94{
95 os << "InjectSolutionAction: ";
96 switch (_kind) {
97 case WEAK: os << "Weak"; break;
98 default: os << "Wrong kind"; break;
99 }
100 os << " ";
101 os << _item;
102 return os;
103}
104
105//---------------------------------------------------------------------------
106
107
108std::ostream &
109SolutionAction::dumpOn( std::ostream & os ) const
110{
111 os << "SolutionAction<";
112 os << "not specified";
113 os << "> ";
114 return os;
115}
116
117
118bool
119TransactionSolutionAction::execute(ResolverInternal & resolver) const
120{
121 bool ret = true;
122 switch (action()) {
123 case KEEP:
124 _item.status().resetTransact (ResStatus::USER);
125 ret = _item.status().setTransact (false, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
126 break;
127 case INSTALL:
128 if (_item.status().isToBeUninstalled())
129 ret = _item.status().setTransact (false, ResStatus::USER);
130 else
131 _item.status().setToBeInstalled (ResStatus::USER);
132 break;
133 case REMOVE:
134 if (_item.status().isToBeInstalled()) {
135 _item.status().setTransact (false,ResStatus::USER);
136 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
137 } else if (_item.status().isInstalled())
138 _item.status().setToBeUninstalled (ResStatus::USER);
139 else
140 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
141 break;
142 case UNLOCK:
143 ret = _item.status().setLock (false, ResStatus::USER);
144 if (!ret) ERR << "Cannot unlock " << _item << endl;
145 break;
146 case LOCK:
147 _item.status().resetTransact (ResStatus::USER);
148 ret = _item.status().setLock (true, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
149 if (!ret) ERR << "Cannot lock " << _item << endl;
150 break;
151 case REMOVE_EXTRA_REQUIRE:
152 resolver.removeExtraRequire (_capability);
153 break;
154 case REMOVE_EXTRA_CONFLICT:
155 resolver.removeExtraConflict (_capability);
156 break;
157 case ADD_SOLVE_QUEUE_ITEM:
158 resolver.addQueueItem(_solverQueueItem);
159 break;
160 case REMOVE_SOLVE_QUEUE_ITEM:
161 resolver.removeQueueItem(_solverQueueItem);
162 break;
163 default:
164 ERR << "Wrong TransactionKind" << endl;
165 ret = false;
166 }
167 return ret;
168}
169
170bool
171InjectSolutionAction::execute(ResolverInternal & resolver) const
172{
173 switch (_kind) {
174 case WEAK:
175 // set item dependencies to weak
176 resolver.addWeak (_item);
177 break;
178 default:
179 ERR << "No valid InjectSolutionAction kind found" << endl;
180 return false;
181 }
182
183 return true;
184}
185
187 };// namespace detail
190 };// namespace solver
193};// namespace zypp
Resolver ResolverInternal
Preferred name in API.
Definition: Types.h:38
std::list< SolutionAction_Ptr > SolutionActionList
Definition: Types.h:48
IMPL_PTR_TYPE(SATResolver)
std::ostream & operator<<(std::ostream &os, const SolutionActionList &actionlist)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:567
#define ERR
Definition: Logger.h:98