solutionAction implemented
[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/CapSet.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 operator<<( ostream& os, const TransactionSolutionAction & action)
63 {
64     os << "TransactionSolutionAction: ";
65     switch (action._action) {
66         case KEEP:      os << "Keep"; break;
67         case INSTALL:   os << "Install"; break;
68         case UPDATE:    os << "Update"; break;
69         case REMOVE:    os << "Remove"; break;
70         case UNLOCK:    os << "Unlock"; break;      
71     }
72     os << " ";
73     os << action._item;
74     os << endl;
75     return os;
76 }
77
78
79 ostream&
80 operator<<( ostream& os, const SolutionActionList & actionlist)
81 {
82     for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
83         os << (*iter);
84         os << endl;
85     }
86     return os;
87 }
88
89
90 ostream&
91 operator<<( ostream& os, const CSolutionActionList & actionlist)
92 {
93     for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
94         os << (*iter);
95         os << endl;
96     }
97     return os;
98 }
99
100 //---------------------------------------------------------------------------
101
102 ostream&
103 operator<<( ostream& os, const InjectSolutionAction & action)
104 {
105     os << "InjectSolutionAction: ";
106     os << action._capability;
107     os << ", ";
108     os << action._kind;
109     os << endl;
110     return os;
111 }
112
113 //---------------------------------------------------------------------------
114
115
116 bool 
117 TransactionSolutionAction::execute(Resolver & resolver) const
118 {
119     bool ret = true;
120     switch (action()) {
121         case KEEP:
122         case INSTALL:
123         case UPDATE:
124             resolver.addPoolItemToInstall (_item);
125             break;
126         case REMOVE:
127             resolver.addPoolItemToRemove (_item);           
128             break;
129         case UNLOCK:
130             ERR << "Not implemented yet" << endl;
131             ret = false;
132 #warning Unlocking items not implemented
133             break;
134         default:
135             ERR << "Wrong TransactionKind" << endl;
136             ret = false;
137     }
138     return ret;
139 }
140
141 bool
142 InjectSolutionAction::execute(Resolver & resolver) const
143 {
144     ResObject::constPtr resolvable = _item.resolvable();
145     CapSet dep;
146     
147     dep.insert(_capability);
148     Dependencies dependencies;
149
150     if (_kind == Dep::CONFLICTS) {
151         // removing provide, it the other resolvable has the conflict
152         dependencies[Dep::PROVIDES] = dep;
153         // removing conflict
154         dependencies[Dep::CONFLICTS] = dep;             
155     } else if (_kind  == Dep::PROVIDES) {
156         // removing the requires dependency from the item
157         dependencies[Dep::REQUIRES] = dep;
158     } else {
159         ERR << "No valid InjectSolutionAction kind found" << endl;
160         return false;
161     }
162 #warning Disabling capabilities currently not possible;
163 //    resolvable->deprecatedSetDeps(dependencies);
164     return true;
165 }
166
167       ///////////////////////////////////////////////////////////////////
168     };// namespace detail
169     /////////////////////////////////////////////////////////////////////
170     /////////////////////////////////////////////////////////////////////
171   };// namespace solver
172   ///////////////////////////////////////////////////////////////////////
173   ///////////////////////////////////////////////////////////////////////
174 };// namespace zypp
175 /////////////////////////////////////////////////////////////////////////