1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 9 10 #include <package/solver/SolverProblem.h> 11 12 #include <stdio.h> 13 14 #include <package/solver/SolverPackage.h> 15 16 17 static const char* const kToStringTexts[] = { 18 "unspecified problem", 19 "%source% does not belong to a distupgrade repository", 20 "%source% has inferior architecture", 21 "problem with installed package %source%", 22 "conflicting requests", 23 "nothing provides requested %dependency%", 24 "%dependency% is provided by the system", 25 "dependency problem", 26 "package %source% is not installable", 27 "nothing provides %dependency% needed by %source%", 28 "cannot install both %source% and %target%", 29 "package %source% conflicts with %dependency% provided by %target%", 30 "package %source% obsoletes %dependency% provided by %target%", 31 "installed package %source% obsoletes %dependency% provided by %target%", 32 "package %source% implicitly obsoletes %dependency% provided by %target%", 33 "package %source% requires %dependency%, but none of the providers can be " 34 "installed", 35 "package %source% conflicts with %dependency% provided by itself" 36 }; 37 38 39 namespace BPackageKit { 40 41 42 BSolverProblem::BSolverProblem(BType type, BSolverPackage* sourcePackage, 43 BSolverPackage* targetPackage) 44 : 45 fType(type), 46 fSourcePackage(sourcePackage), 47 fTargetPackage(targetPackage), 48 fDependency() 49 { 50 } 51 52 53 BSolverProblem::BSolverProblem(BType type, BSolverPackage* sourcePackage, 54 BSolverPackage* targetPackage, 55 const BPackageResolvableExpression& dependency) 56 : 57 fType(type), 58 fSourcePackage(sourcePackage), 59 fTargetPackage(targetPackage), 60 fDependency(dependency) 61 { 62 } 63 64 65 BSolverProblem::~BSolverProblem() 66 { 67 } 68 69 70 BSolverProblem::BType 71 BSolverProblem::Type() const 72 { 73 return fType; 74 } 75 76 77 BSolverPackage* 78 BSolverProblem::SourcePackage() const 79 { 80 return fSourcePackage; 81 } 82 83 84 BSolverPackage* 85 BSolverProblem::TargetPackage() const 86 { 87 return fTargetPackage; 88 } 89 90 91 const BPackageResolvableExpression& 92 BSolverProblem::Dependency() const 93 { 94 return fDependency; 95 } 96 97 98 BString 99 BSolverProblem::ToString() const 100 { 101 size_t index = fType; 102 if (index >= sizeof(kToStringTexts) / sizeof(kToStringTexts[0])) 103 index = 0; 104 105 return BString(kToStringTexts[index]) 106 .ReplaceAll("%source%", 107 fSourcePackage != NULL 108 ? fSourcePackage->VersionedName().String() : "?") 109 .ReplaceAll("%target%", 110 fTargetPackage != NULL 111 ? fTargetPackage->VersionedName().String() : "?") 112 .ReplaceAll("%dependency%", 113 fDependency.InitCheck() == B_OK 114 ? fDependency.ToString().String() : "?"); 115 } 116 117 118 } // namespace BPackageKit 119