Make UEFI boot-platform build again
[haiku.git] / headers / private / package / manager / PackageManager.h
blobe761151005024575fa8637187356ff2fc56ba8f0
1 /*
2 * Copyright 2013-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 * Rene Gollent <rene@gollent.com>
8 */
9 #ifndef _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
10 #define _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
13 #include <map>
14 #include <string>
16 #include <Directory.h>
17 #include <ObjectList.h>
18 #include <package/Context.h>
19 #include <package/PackageDefs.h>
20 #include <package/PackageRoster.h>
21 #include <package/RepositoryConfig.h>
22 #include <package/solver/Solver.h>
23 #include <package/solver/SolverRepository.h>
25 #include <package/ActivationTransaction.h>
26 #include <package/DaemonClient.h>
27 #include <package/Job.h>
30 namespace BPackageKit {
33 class BCommitTransactionResult;
36 namespace BManager {
38 namespace BPrivate {
41 using BPackageKit::BPrivate::BActivationTransaction;
42 using BPackageKit::BPrivate::BDaemonClient;
45 class BPackageManager : protected BSupportKit::BJobStateListener {
46 public:
47 class RemoteRepository;
48 class LocalRepository;
49 class MiscLocalRepository;
50 class InstalledRepository;
51 class Transaction;
52 class InstallationInterface;
53 class ClientInstallationInterface;
54 class UserInteractionHandler;
56 typedef BObjectList<RemoteRepository> RemoteRepositoryList;
57 typedef BObjectList<InstalledRepository> InstalledRepositoryList;
58 typedef BObjectList<BSolverPackage> PackageList;
59 typedef BObjectList<Transaction> TransactionList;
61 enum {
62 B_ADD_INSTALLED_REPOSITORIES = 0x01,
63 B_ADD_REMOTE_REPOSITORIES = 0x02,
64 B_REFRESH_REPOSITORIES = 0x04,
67 public:
68 BPackageManager(
69 BPackageInstallationLocation location,
70 InstallationInterface*
71 installationInterface,
72 UserInteractionHandler*
73 userInteractionHandler);
74 virtual ~BPackageManager();
76 void Init(uint32 flags);
78 void SetDebugLevel(int32 level);
79 // 0 - 10 (passed to libsolv)
81 BSolver* Solver() const
82 { return fSolver; }
84 const InstalledRepository* SystemRepository() const
85 { return fSystemRepository; }
86 const InstalledRepository* HomeRepository() const
87 { return fHomeRepository; }
88 const InstalledRepositoryList& InstalledRepositories() const
89 { return fInstalledRepositories; }
90 const RemoteRepositoryList& OtherRepositories() const
91 { return fOtherRepositories; }
93 void Install(const char* const* packages,
94 int packageCount);
95 void Install(const BSolverPackageSpecifierList&
96 packages);
97 void Uninstall(const char* const* packages,
98 int packageCount);
99 void Uninstall(const BSolverPackageSpecifierList&
100 packages);
101 void Update(const char* const* packages,
102 int packageCount);
103 void Update(const BSolverPackageSpecifierList&
104 packages);
105 void FullSync();
107 void VerifyInstallation();
110 virtual status_t DownloadPackage(const BString& fileURL,
111 const BEntry& targetEntry,
112 const BString& checksum);
113 virtual status_t RefreshRepository(
114 const BRepositoryConfig& repoConfig);
116 protected:
117 InstalledRepository& InstallationRepository();
119 protected:
120 // BJobStateListener
121 virtual void JobStarted(BSupportKit::BJob* job);
122 virtual void JobProgress(BSupportKit::BJob* job);
123 virtual void JobSucceeded(BSupportKit::BJob* job);
125 private:
126 void _HandleProblems();
127 void _AnalyzeResult();
128 void _ConfirmChanges(bool fromMostSpecific = false);
129 void _ApplyPackageChanges(
130 bool fromMostSpecific = false);
131 void _PreparePackageChanges(
132 InstalledRepository&
133 installationRepository);
134 void _CommitPackageChanges(Transaction& transaction);
136 void _ClonePackageFile(
137 LocalRepository* repository,
138 BSolverPackage* package,
139 const BEntry& entry);
140 int32 _FindBasePackage(const PackageList& packages,
141 const BPackageInfo& info);
143 void _AddInstalledRepository(
144 InstalledRepository* repository);
145 void _AddRemoteRepository(BPackageRoster& roster,
146 const char* name, bool refresh);
147 status_t _GetRepositoryCache(BPackageRoster& roster,
148 const BRepositoryConfig& config,
149 bool refresh, BRepositoryCache& _cache);
151 void _AddPackageSpecifiers(
152 const char* const* searchStrings,
153 int searchStringCount,
154 BSolverPackageSpecifierList& specifierList);
155 bool _IsLocalPackage(const char* fileName);
156 BSolverPackage* _AddLocalPackage(const char* fileName);
158 bool _NextSpecificInstallationLocation();
160 protected:
161 int32 fDebugLevel;
162 BPackageInstallationLocation fLocation;
163 BSolver* fSolver;
164 InstalledRepository* fSystemRepository;
165 InstalledRepository* fHomeRepository;
166 InstalledRepositoryList fInstalledRepositories;
167 RemoteRepositoryList fOtherRepositories;
168 MiscLocalRepository* fLocalRepository;
169 TransactionList fTransactions;
171 // must be set by the derived class
172 InstallationInterface* fInstallationInterface;
173 UserInteractionHandler* fUserInteractionHandler;
177 class BPackageManager::RemoteRepository : public BSolverRepository {
178 public:
179 RemoteRepository(
180 const BRepositoryConfig& config);
182 const BRepositoryConfig& Config() const;
184 private:
185 BRepositoryConfig fConfig;
189 class BPackageManager::LocalRepository : public BSolverRepository {
190 public:
191 LocalRepository();
192 LocalRepository(const BString& name);
194 virtual void GetPackagePath(BSolverPackage* package,
195 BPath& _path) = 0;
199 class BPackageManager::MiscLocalRepository : public LocalRepository {
200 public:
201 MiscLocalRepository();
203 BSolverPackage* AddLocalPackage(const char* fileName);
205 virtual void GetPackagePath(BSolverPackage* package,
206 BPath& _path);
208 private:
209 typedef std::map<BSolverPackage*, std::string> PackagePathMap;
210 private:
211 PackagePathMap fPackagePaths;
215 class BPackageManager::InstalledRepository : public LocalRepository {
216 public:
217 typedef BObjectList<BSolverPackage> PackageList;
219 public:
220 InstalledRepository(const char* name,
221 BPackageInstallationLocation location,
222 int32 priority);
224 BPackageInstallationLocation Location() const
225 { return fLocation; }
226 const char* InitialName() const
227 { return fInitialName; }
228 int32 InitialPriority() const
229 { return fInitialPriority; }
231 virtual void GetPackagePath(BSolverPackage* package,
232 BPath& _path);
234 void DisablePackage(BSolverPackage* package);
235 // throws, if already disabled
236 bool EnablePackage(BSolverPackage* package);
237 // returns whether it was disabled
239 PackageList& PackagesToActivate()
240 { return fPackagesToActivate; }
241 PackageList& PackagesToDeactivate()
242 { return fPackagesToDeactivate; }
244 bool HasChanges() const;
245 void ApplyChanges();
247 private:
248 PackageList fDisabledPackages;
249 PackageList fPackagesToActivate;
250 PackageList fPackagesToDeactivate;
251 const char* fInitialName;
252 BPackageInstallationLocation fLocation;
253 int32 fInitialPriority;
257 class BPackageManager::Transaction {
258 public:
259 Transaction(InstalledRepository& repository);
260 ~Transaction();
262 InstalledRepository& Repository()
263 { return fRepository; }
264 BActivationTransaction& ActivationTransaction()
265 { return fTransaction; }
266 BDirectory& TransactionDirectory()
267 { return fTransactionDirectory; }
269 private:
270 InstalledRepository& fRepository;
271 BActivationTransaction fTransaction;
272 BDirectory fTransactionDirectory;
276 class BPackageManager::InstallationInterface {
277 public:
278 virtual ~InstallationInterface();
280 virtual void InitInstalledRepository(
281 InstalledRepository& repository) = 0;
282 virtual void ResultComputed(InstalledRepository& repository);
284 virtual status_t PrepareTransaction(Transaction& transaction)
285 = 0;
286 virtual status_t CommitTransaction(Transaction& transaction,
287 BCommitTransactionResult& _result) = 0;
291 class BPackageManager::ClientInstallationInterface
292 : public InstallationInterface {
293 public:
294 ClientInstallationInterface();
295 virtual ~ClientInstallationInterface();
297 virtual void InitInstalledRepository(
298 InstalledRepository& repository);
300 virtual status_t PrepareTransaction(Transaction& transaction);
301 virtual status_t CommitTransaction(Transaction& transaction,
302 BCommitTransactionResult& _result);
304 private:
305 BDaemonClient fDaemonClient;
309 class BPackageManager::UserInteractionHandler {
310 public:
311 virtual ~UserInteractionHandler();
313 virtual void HandleProblems();
314 virtual void ConfirmChanges(bool fromMostSpecific);
316 virtual void Warn(status_t error, const char* format, ...);
318 virtual void ProgressPackageDownloadStarted(
319 const char* packageName);
320 virtual void ProgressPackageDownloadActive(
321 const char* packageName,
322 float completionPercentage,
323 off_t bytes, off_t totalBytes);
324 virtual void ProgressPackageDownloadComplete(
325 const char* packageName);
326 virtual void ProgressPackageChecksumStarted(
327 const char* title);
328 virtual void ProgressPackageChecksumComplete(
329 const char* title);
331 virtual void ProgressStartApplyingChanges(
332 InstalledRepository& repository);
333 virtual void ProgressTransactionCommitted(
334 InstalledRepository& repository,
335 const BCommitTransactionResult& result);
336 virtual void ProgressApplyingChangesDone(
337 InstalledRepository& repository);
341 } // namespace BPrivate
343 } // namespace BManager
345 } // namespace BPackageKit
348 #endif // _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_