libzypp  11.13.5
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 
26 #include "zypp/Capabilities.h"
27 #include "zypp/base/Logger.h"
28 
30 namespace zypp
31 {
32 
33  namespace solver
34  {
35 
36  namespace detail
37  {
38 
39 using namespace std;
40 
41 IMPL_PTR_TYPE(SolutionAction);
42 IMPL_PTR_TYPE(TransactionSolutionAction);
43 IMPL_PTR_TYPE(InjectSolutionAction);
44 
45 //---------------------------------------------------------------------------
46 
48 {
49 }
50 
51 
53 {
54 }
55 
56 
57 //---------------------------------------------------------------------------
58 
59 ostream &
61 {
62  os << "TransactionSolutionAction: ";
63  switch (_action) {
64  case KEEP: os << "Keep " << _item; break;
65  case INSTALL: os << "Install " << _item; break;
66  case REMOVE: os << "Remove " << _item; break;
67  case UNLOCK: os << "Unlock " << _item; break;
68  case LOCK: os << "Lock " << _item; break;
69  case REMOVE_EXTRA_REQUIRE: os << "Remove require " << _capability; break;
70  case REMOVE_EXTRA_CONFLICT: os << "Remove conflict " << _capability; break;
71  case ADD_SOLVE_QUEUE_ITEM: os << "Add SolveQueueItem " << _solverQueueItem; break;
72  case REMOVE_SOLVE_QUEUE_ITEM: os << "Remove SolveQueueItem " << _solverQueueItem; break;
73  }
74 
75  os << endl;
76  return os;
77 }
78 
79 
80 ostream&
81 operator<<( 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 ostream&
92 operator<<( ostream& os, const CSolutionActionList & actionlist)
93 {
94  for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
95  os << *(*iter);
96  os << endl;
97  }
98  return os;
99 }
100 
101 //---------------------------------------------------------------------------
102 
103 ostream &
104 InjectSolutionAction::dumpOn( ostream& os ) const
105 {
106  os << "InjectSolutionAction: ";
107  switch (_kind) {
108  case WEAK: os << "Weak"; break;
109  default: os << "Wrong kind"; break;
110  }
111  os << " ";
112  os << _item;
113  os << endl;
114  return os;
115 }
116 
117 //---------------------------------------------------------------------------
118 
119 
120 ostream &
121 SolutionAction::dumpOn( std::ostream & os ) const
122 {
123  os << "SolutionAction<";
124  os << "not specified";
125  os << "> ";
126  return os;
127 }
128 
129 
130 bool
132 {
133  bool ret = true;
134  switch (action()) {
135  case KEEP:
136  _item.status().resetTransact (ResStatus::USER);
137  ret = _item.status().setTransact (false, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
138  break;
139  case INSTALL:
140  if (_item.status().isToBeUninstalled())
141  ret = _item.status().setTransact (false, ResStatus::USER);
142  else
143  _item.status().setToBeInstalled (ResStatus::USER);
144  break;
145  case REMOVE:
146  if (_item.status().isToBeInstalled()) {
147  _item.status().setTransact (false,ResStatus::USER);
148  _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
149  } else if (_item.status().isInstalled())
150  _item.status().setToBeUninstalled (ResStatus::USER);
151  else
152  _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
153  break;
154  case UNLOCK:
155  ret = _item.status().setLock (false, ResStatus::USER);
156  if (!ret) ERR << "Cannot unlock " << _item << endl;
157  break;
158  case LOCK:
159  _item.status().resetTransact (ResStatus::USER);
160  ret = _item.status().setLock (true, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
161  if (!ret) ERR << "Cannot lock " << _item << endl;
162  break;
164  resolver.removeExtraRequire (_capability);
165  break;
167  resolver.removeExtraConflict (_capability);
168  break;
170  resolver.addQueueItem(_solverQueueItem);
171  break;
173  resolver.removeQueueItem(_solverQueueItem);
174  break;
175  default:
176  ERR << "Wrong TransactionKind" << endl;
177  ret = false;
178  }
179  return ret;
180 }
181 
182 bool
184 {
185  switch (_kind) {
186  case WEAK:
187  // set item dependencies to weak
188  resolver.addWeak (_item);
189  break;
190  default:
191  ERR << "No valid InjectSolutionAction kind found" << endl;
192  return false;
193  }
194 
195  return true;
196 }
197 
199  };// namespace detail
202  };// namespace solver
205 };// namespace zypp