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/ActivationTransaction.h> 11 12 13 namespace BPackageKit { 14 namespace BPrivate { 15 16 17 BActivationTransaction::BActivationTransaction() 18 : 19 fLocation(B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT), 20 fChangeCount(0), 21 fTransactionDirectoryName(), 22 fPackagesToActivate(), 23 fPackagesToDeactivate() 24 { 25 } 26 27 28 BActivationTransaction::~BActivationTransaction() 29 { 30 } 31 32 33 status_t 34 BActivationTransaction::InitCheck() const 35 { 36 if (fLocation < 0 || fLocation >= B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT 37 || fTransactionDirectoryName.IsEmpty() 38 || (fPackagesToActivate.IsEmpty() && fPackagesToDeactivate.IsEmpty())) { 39 return B_BAD_VALUE; 40 } 41 return B_OK; 42 } 43 44 status_t 45 BActivationTransaction::SetTo(BPackageInstallationLocation location, 46 int64 changeCount, const BString& directoryName) 47 { 48 if (location < 0 || location >= B_PACKAGE_INSTALLATION_LOCATION_ENUM_COUNT 49 || directoryName.IsEmpty()) { 50 return B_BAD_VALUE; 51 } 52 53 fLocation = location; 54 fChangeCount = changeCount; 55 fTransactionDirectoryName = directoryName; 56 fPackagesToActivate.MakeEmpty(); 57 fPackagesToDeactivate.MakeEmpty(); 58 59 return B_OK; 60 } 61 62 63 BPackageInstallationLocation 64 BActivationTransaction::Location() const 65 { 66 return fLocation; 67 } 68 69 70 void 71 BActivationTransaction::SetLocation(BPackageInstallationLocation location) 72 { 73 fLocation = location; 74 } 75 76 77 int64 78 BActivationTransaction::ChangeCount() const 79 { 80 return fChangeCount; 81 } 82 83 84 void 85 BActivationTransaction::SetChangeCount(int64 changeCount) 86 { 87 fChangeCount = changeCount; 88 } 89 90 91 const BString& 92 BActivationTransaction::TransactionDirectoryName() const 93 { 94 return fTransactionDirectoryName; 95 } 96 97 98 void 99 BActivationTransaction::SetTransactionDirectoryName( 100 const BString& directoryName) 101 { 102 fTransactionDirectoryName = directoryName; 103 } 104 105 106 const BStringList& 107 BActivationTransaction::PackagesToActivate() const 108 { 109 return fPackagesToActivate; 110 } 111 112 113 bool 114 BActivationTransaction::SetPackagesToActivate(const BStringList& packages) 115 { 116 fPackagesToActivate = packages; 117 return fPackagesToActivate.CountStrings() == packages.CountStrings(); 118 } 119 120 121 bool 122 BActivationTransaction::AddPackageToActivate(const BString& package) 123 { 124 return fPackagesToActivate.Add(package); 125 } 126 127 128 const BStringList& 129 BActivationTransaction::PackagesToDeactivate() const 130 { 131 return fPackagesToDeactivate; 132 } 133 134 135 bool 136 BActivationTransaction::SetPackagesToDeactivate(const BStringList& packages) 137 { 138 fPackagesToDeactivate = packages; 139 return fPackagesToDeactivate.CountStrings() == packages.CountStrings(); 140 } 141 142 143 bool 144 BActivationTransaction::AddPackageToDeactivate(const BString& package) 145 { 146 return fPackagesToDeactivate.Add(package); 147 } 148 149 150 } // namespace BPrivate 151 } // namespace BPackageKit 152