Cupt
resolver.hpp
Go to the documentation of this file.
00001 /**************************************************************************
00002 *   Copyright (C) 2010 by Eugene V. Lyubimkin                             *
00003 *                                                                         *
00004 *   This program is free software; you can redistribute it and/or modify  *
00005 *   it under the terms of the GNU General Public License                  *
00006 *   (version 3 or above) as published by the Free Software Foundation.    *
00007 *                                                                         *
00008 *   This program is distributed in the hope that it will be useful,       *
00009 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00010 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00011 *   GNU General Public License for more details.                          *
00012 *                                                                         *
00013 *   You should have received a copy of the GNU GPL                        *
00014 *   along with this program; if not, write to the                         *
00015 *   Free Software Foundation, Inc.,                                       *
00016 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA               *
00017 **************************************************************************/
00018 #ifndef CUPT_COMMON_RESOLVER_SEEN
00019 #define CUPT_COMMON_RESOLVER_SEEN
00020 
00022 
00023 #include <functional>
00024 
00025 #include <cupt/common.hpp>
00026 #include <cupt/cache/binaryversion.hpp>
00027 
00028 namespace cupt {
00029 namespace system {
00030 
00031 using namespace cache;
00032 
00034 
00042 class CUPT_API Resolver
00043 {
00044     Resolver(const Resolver&);
00045     Resolver& operator=(const Resolver&);
00046  public:
00048     struct Reason
00049     {
00050      protected:
00051         CUPT_LOCAL Reason() {};
00052      public:
00053         virtual ~Reason() {}; // polymorphic
00054         virtual string toString() const = 0; 
00055     };
00057 
00061     struct UserReason: public Reason
00062     {
00063         virtual string toString() const;
00064     };
00066 
00072     struct AutoRemovalReason: public Reason
00073     {
00074         virtual string toString() const;
00075     };
00077 
00081     struct RelationExpressionReason: public Reason
00082     {
00083         shared_ptr< const BinaryVersion > version; 
00084         BinaryVersion::RelationTypes::Type dependencyType; 
00085         RelationExpression relationExpression; 
00086 
00088         RelationExpressionReason(const shared_ptr< const BinaryVersion >&,
00089                 BinaryVersion::RelationTypes::Type, const RelationExpression&);
00090         virtual string toString() const;
00091     };
00093 
00098     struct SynchronizationReason: public Reason
00099     {
00100         shared_ptr< const BinaryVersion > version; 
00101         string relatedPackageName; 
00102 
00104         SynchronizationReason(const shared_ptr< const BinaryVersion >&, const string&);
00105         virtual string toString() const;
00106     };
00107 
00109 
00112     struct SuggestedPackage
00113     {
00114         shared_ptr< const BinaryVersion > version; 
00115         // TODO/API break/: change the field to 'automaticallyInstalledFlag'
00116         bool manuallySelected; 
00117         vector< shared_ptr< const Reason > > reasons; 
00118     };
00119     typedef map< string, SuggestedPackage > SuggestedPackages; 
00120 
00121     struct Offer
00122     {
00123         SuggestedPackages suggestedPackages; 
00124         vector< shared_ptr< const Reason > > unresolvedProblems;
00125     };
00126 
00128     struct UserAnswer
00129     {
00130         enum Type
00131         {
00132             Accept, 
00133             Decline, 
00134             Abandon 
00135         };
00136     };
00137 
00139     typedef std::function< UserAnswer::Type (const Offer&) > CallbackType;
00140 
00141     Resolver() {};
00142 
00146     virtual void installVersion(const shared_ptr< const BinaryVersion >&) = 0;
00150     virtual void satisfyRelationExpression(const RelationExpression&) = 0;
00154     virtual void unsatisfyRelationExpression(const RelationExpression&) = 0;
00160     virtual void removePackage(const string& packageName) = 0;
00164     virtual void upgrade() = 0;
00165 
00167 
00173     virtual bool resolve(CallbackType) = 0;
00174 
00176     virtual ~Resolver() {};
00177 };
00178 
00179 }
00180 }
00181 
00182 #endif
00183